异地备份同步校验脚本
2016-07-21 16:04
423 查看
实现功能:
将客户端服务器A的每天的数据(/www,/log)本地打包,并且配置定时脚本每天同步到服务端服务器上,在服务器上对备份的数据进行校验,将结果发送到管理员邮箱。客户端:
#!/bin/bash
remote_host=172.16.1.111
remote_path=/backup
local_backup_path=/backup
local_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
[/code]加入定时任务
crontab -e
0 4 * * * /bin/bash /root/shell/www_backup.sh &> /dev/null
[/code]
服务端:
#!/bin/bash
local_backup_path=/backup
md5_file=flag_$(date +%F)
cd $local_backup_path
if [ $? -eq 0 ];then
if [ -e $md5_file ];then
md5sum -c ${md5_file} >> mail.txt
if [ $? -eq 0 ];then
mail -s "Success ! The backup task is ok !" 731431337@qq.com < mail.txt
else
mail -s "Failed ! The backup task is failed !" 731431337@qq.com < mail.txt
fi
else
ls > mail.txt
mail -s "Failed ! The md5_file is not exists!" 731431337@qq.com < mail.txt
fi
[/code]加入定时任务
crontab -e
0 5 * * * /bin/bash /root/shell/flag_check.sh &> /dev/null
[/code]
来自为知笔记(Wiz)
相关文章推荐
- 第一次使用ajax
- hbase相关配置说明
- Linux下通过crontab及expect实现自动化处理 --亲测可用
- Axure RP 7.0使用心得
- protocol buffers 序列化实例
- Ceph 从H版升级到J版经验总结
- 【杭电oj】2082 - 找单词(母函数)
- intellj idea manven
- MySql视图原理讲解与使用大全
- 2_3画橡皮矩形
- mysql 主从配置原理
- 轮询和推送
- js动态添加table,select等
- 关于iOS通知(APNS)的理解
- 处理:APP home后,手机管家清理,导致回到app时,数据丢失
- maven工程建立和SSM(springMVC+spring+mybatis)整合
- 红黑树详解
- Android指纹识别
- db2 之 入门实验
- JavaScript中match方法与exec方法的异同