异地备份同步校验脚本
实现功能:
将客户端服务器A的每天的数据(/www,/log)本地打包,并且配置定时脚本每天同步到服务端服务器上,在服务器上对备份的数据进行校验,将结果发送到管理员邮箱。
客户端:
#!/bin/bashremote_host=172.16.1.111remote_path=/backuplocal_backup_path=/backuplocal_file_path=/data[ -d $local_backup_path ] || mkdir -p $local_backup_path#打包cd ${local_file_path} && \tar zcf $local_backup_path/www-$(date +%F).tar.gz /data/www && \tar zcf $local_backup_path/log-$(date +%F).tar.gz /data/log && \find /backup -type f -name "*.tar.gz" | xargs md5sum > $local_backup_path/flag_$(date +%F)#同步rsync -avz $local_backup_path/* $remote_host:$remote_path --passwod(省略)#删除本地七天前find $local_backup_path -type f -name "*.tar.gz" -mtime +7 | xargs rm -f
加入定时任务
crontab -e0 4 * * * /bin/bash /root/shell/www_backup.sh &> /dev/null
服务端:
#!/bin/bashlocal_backup_path=/backupmd5_file=flag_$(date +%F)cd $local_backup_pathif [ $? -eq 0 ];thenif [ -e $md5_file ];thenmd5sum -c ${md5_file} >> mail.txtif [ $? -eq 0 ];thenmail -s "Success ! The backup task is ok !" 731431337@qq.com < mail.txtelsemail -s "Failed ! The backup task is failed !" 731431337@qq.com < mail.txtfielsels > mail.txtmail -s "Failed ! The md5_file is not exists!" 731431337@qq.com < mail.txtfi
加入定时任务
crontab -e0 5 * * * /bin/bash /root/shell/flag_check.sh &> /dev/null
浙公网安备 33010602011771号