Rsync全网数据同步备份及检查
1. 客户端备份数据并推送
#!/bin/bash
#Date: 2018/7/16
#Author: Testder
#Mail: 10000@testder.cn
# Definition variable
IP=$(cat /etc/sysconfig/network-scripts/ifcfg-eno16777728 | awk -F= '/IPADDR/{print $2}')
Path="/backup/$IP"
[ ! -d $Path ] && mkdir -p $Path
# Packaging backup data
tar czf $Path/www_$(date +%F).tar.gz /usr/local/nginx/html/ && \
tar czf $Path/logs_$(date +%F).tar.gz /usr/local/nginx/logs/ && \
tar czf $Path/conf_$(date +%F).tar.gz /var/spool/cron/root /etc/rc.local /etc/sysconfig/iptables-config
# Generate MD5
find /backup/ -type f -name "*$(date +%F).tar.gz" | xargs md5sum >> $Path/flag_$(date +%F).txt
# Push to the rysnc server
rsync -avz /backup/* rsync_backup@172.16.100.20::bak --password-file=/etc/rsync.passwd
# Delete backups from seven days ago
find /backup -type f -name "*.tar.gz" -mtime +7 | xargs rm -f
2. 服务端验证备份完整性
md5sum -c /backup/172.16.100.10/flag_2018-07-01.txt
/backup/172.16.100.10/www_2018-07-01.tar.gz: OK
/backup/172.16.100.10/logs_2018-07-01.tar.gz: OK
/backup/172.16.100.10/conf_2018-07-01.tar.gz: OK
find /backup/ -type f -name "flag_$(date +%F).txt" | xargs md5sum -c | grep FAILED