异地备份同步校验脚本

实现功能:

将客户端服务器A的每天的数据(/www,/log)本地打包,并且配置定时脚本每天同步到服务端服务器上,在服务器上对备份的数据进行校验,将结果发送到管理员邮箱。

客户端:


   
  1. #!/bin/bash
  2. remote_host=172.16.1.111    
  3. remote_path=/backup          
  4. local_backup_path=/backup
  5. local_file_path=/data
  6. [ -d $local_backup_path ] || mkdir -p $local_backup_path 
  7. #打包 
  8. cd ${local_file_path} && \
  9. tar zcf $local_backup_path/www-$(date +%F).tar.gz /data/www && \
  10. tar zcf $local_backup_path/log-$(date +%F).tar.gz /data/log && \
  11. find /backup -type f -name "*.tar.gz" | xargs md5sum > $local_backup_path/flag_$(date +%F) 
  12. #同步
  13. rsync -avz  $local_backup_path/*  $remote_host:$remote_path --passwod(省略)
  14. #删除本地七天前
  15. find $local_backup_path -type f -name "*.tar.gz" -mtime +7 | xargs rm -f
加入定时任务

   
  1. crontab -e
  2. 0 4 * * *  /bin/bash /root/shell/www_backup.sh &> /dev/null

服务端:


   
  1. #!/bin/bash
  2. local_backup_path=/backup
  3. md5_file=flag_$(date +%F)
  4. cd $local_backup_path 
  5. if [ $? -eq 0 ];then
  6.     if [ -e $md5_file ];then
  7.         md5sum -c ${md5_file} >> mail.txt
  8.         if [ $? -eq 0 ];then
  9.             mail -s "Success ! The backup task is ok !" 731431337@qq.com < mail.txt
  10.         else 
  11.             mail -s "Failed ! The backup task is failed !" 731431337@qq.com < mail.txt        
  12.         fi  
  13.     else 
  14.         ls > mail.txt
  15.         mail -s "Failed ! The md5_file is not exists!" 731431337@qq.com < mail.txt 
  16. fi
加入定时任务

   
  1. crontab -e
  2. 0 5 * * *  /bin/bash /root/shell/flag_check.sh &> /dev/null





转载于:https://www.cnblogs.com/yangliheng/p/5692148.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值