项目需求: 1、备份web服务器的网站目录、脚本、配置文件、定时任务等 2、web服务器上保留7天备份,并添加指纹 3、备份服务器上保留7天备份,并保留180内每周一的备份文件,并做指纹认证 [root@web /server/scripts]# cat bak.sh #!/bin/bash export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin" export RSYNC_PASSWORD=shnne IP=$(hostname -i) mkdir -p /backup/$IP #1.tar tar zchf /backup/$IP/bak_${IP}_$(date +%F_%w).tar.gz /var/spool/cron/root /etc/rc.local /server/scripts /var/html/www /app/logs &>/dev/null &&\ #2.采集指纹 touch /backup/$IP/bak_${IP}_$(date +%F_%w).flag &&\ find /backup/ -type f -name "bak_${IP}_$(date +%F_%w).tar.gz" | xargs md5sum > /backup/$IP/bak_${IP}_$(date +%F_%w).flag &&\ #3.del find /backup/ -type f -name "*.tar.gz" -mtime +7|xargs rm -f &&\ #4.push rsync -az /backup/ rsync_backup@172.16.1.200::backup &>/dev/null [root@backup /server/scripts]#cat /server/scripts/del.sh #!/bin/bash export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin" #1.del find /backup/ -type f -name "*.tar.gz" -mtime +180|xargs rm -f &&\ find /backup/ -type f ! -name "*_1.tar.gz" -mtime +7|xargs rm -f #2.校验 find /backup -type f -name "*$(date +%F_%w).flag |xargs md5sum -c > /tmp/fail.log mail -s "$(date +%F_%T) backup data error" postmaster@shnne.com < /tmp/fail.log vi /etc/mailrc set from=xxx@126.com smtp=smtp.126.com smtp-auth-user=xxx smtp-auth-password=PASSWORD smtp-auth=login
rsync配置参考:https://www.shnne.com/post/390.html
mail配置参考:https://www.shnne.com/post/395.html