客户端脚本:
[root@nfs01 ~]# vim /server/scripts/backup.sh
#/bin/bash
Backup_dir="/backup"
IP_info=$(hostname -i)
#创建备份目录
mkdir -p $Backup_dir/$IP_info
#压缩备份数据
tar zchf $Backup_dir/$IP_info/system_backup_$(date +%F_week%w).tar.gz /var/spool/cron/root /etc/rc.local /server/scripts /et
c/sysconfig/iptables
#删除7天以前的数据
find $Backup_dir -type f -mtime +7|xargs rm 2>/dev/null
#创建指纹文件
find $Backup_dir/ -type f -mtime -1 ! -name "finger.txt"|xargs md5sum > $Backup_dir/$IP_info/finger.txt
#备份推送数据信息
rsync -az $Backup_dir/ rsync_backup@172.16.1.41::backup --password-file=/etc/rsync.password
服务端脚本:
[root@backup ~]# vim /server/scripts/backup.sh
#/bin/bash
#删除180天以前的数据
find /backup/ -type f -mtime +180 ! -name "*week1.tar.gz" |xargs rm 2>/dev/null
#检查备份数据
find /backup/ -type f -name "finger.txt" |xargs md5sum -c > /tmp/checklist.txt
#发送email
cat /tmp/checklist.txt |mail -s "邮件测试$(date +%F)" 1017198665@qq.com
定时任务编写:
客户端:
crontab -e
#time sync by lidao at 2017-03-08
#*/5 * * * * /usr/sbin/ntpdate ntp1.aliyun.com >/dev/null 2>&1
0 0 * * * /bin/sh /server/scripts/backup.sh &>/dev/null
服务端:
[root@backup ~]# crontab -e
#time sync by lidao at 2017-03-08
#*/5 * * * * /usr/sbin/ntpdate ntp1.aliyun.com >/dev/null 2>&1
0 6 * * * /bin/sh /server/scripts/backup.sh &>/dev/null