标签:
#!/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
crontab -e 04*** /bin/bash /root/shell/www_backup.sh &>/dev/null
#!/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
crontab -e 05*** /bin/bash /root/shell/flag_check.sh &>/dev/null
标签:
原文地址:http://www.cnblogs.com/yangliheng/p/5692148.html