流程思路
1.指定完成项目需求信息
2.按照需求完成每个任务
3.编写任务脚本文件信息
客户端:
[root@nfs01 scripts]# cat backup_nfs01.sh #!/bin/bash day=$(date +%F_%A -d "-1 day") IP=$(hostname -i) Path="/backup" #01.创建备份目录 mkdir -p $Path/$IP #创建防火墙的配置文件 echo "123" >/etc/sysconfig/iptables #02.将相关的目录文件 打包备份带制定的目录 tar zcPhf $Path/$IP/sys-$day.tar.gz /etc/rc.local /server/scripts /var/spool/cron/root /etc/sysconfig/iptables #wed01服务端创建站点目录 #mkdir -p /var/html/www #mkdir -p /app/logs/ #tar -zcPhf $Path/$IP/www-${date}.tar.gz /var/html/www #tar -zcPhf $Path/$IP/logs-${date}.tar.gz /app/logs #03.生成指纹文件 find $Path/$IP -type f -mmin -20 -name "*.tar.gz"|xargs md5sum > $Path/$IP/finger.txt #05.删除备份目录中时间超过7天的数据 find $Path/ -type f -mtime +7 -delete #04.将打包的文件推送(增量传送) rsync -avz $Path/ rsync_backup@172.16.1.41::backup/ --password-file=/etc/rsync.password
添加定时任务:
[root@nfs01 scripts]# crontab -e 00 00 * * * /bin/bash /server/scripts/backup_nfs01.sh &>/dev/null
服务端:
[root@backup ~]# cat /server/scripts/backup_rsync.sh #验证备份文件的完整性 find /backup -type f -name "finger.txt"|xargs md5sum -c >/tmp/check_finger.txt #将指纹文件验证结果发送给运维人员 mail -s "$(date +%F) data check" ***********@qq.com </tmp/check_finger.txt #删除历史备份数据(180之前的) find /backup -type f -mtime +180 ! -name "*星期一.tar.gz" -delete
服务端 邮件服务配置文件
[root@backup ~]# tail -f /etc/mail.rc # For Linux and BSD, this should be set. set bsdcompat set from=**********@qq.com set smtp=smtp.qq.com set smtp-auth-user=**********@qq.com set smtp-auth-password=wyzsfsmebjjsbejd set smtp-auth=login
启动邮件服务!
[root@backup ~]# systemctl status postfix.service ● postfix.service - Postfix Mail Transport Agent Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled) Active: active (running) since 四 2019-10-24 08:31:31 CST; 1 day 12h ago Main PID: 6819 (master) CGroup: /system.slice/postfix.service ├─ 6819 /usr/libexec/postfix/master -w ├─ 6821 qmgr -l -t unix -u └─11302 pickup -l -t unix -u 10月 24 08:31:28 backup systemd[1]: Starting Postfix Mail Transport Agent... 10月 24 08:31:31 backup postfix/postfix-script[6817]: starting the Postfix mail system 10月 24 08:31:31 backup postfix/master[6819]: daemon started -- version 2.10.1, configuration /etc/postfix 10月 24 08:31:31 backup systemd[1]: Started Postfix Mail Transport Agent.
添加定时任务:
[root@backup ~]# crontab -e 00 07 * * * /bin/bash /server/scripts/backup_rsync.sh &>/dev/null