企业中难免会有使用svn 的怎么给svn做好备份呢
下面是用两个脚本进行同步和监控
同步脚本:
#!/bin/bash i=1 while true do if [ $(expr $i % 12) == 0 ];then i=1 mail -s "svn备份消息推送" lize@example.com </root/backsvn47.log else echo `date +"%F %T"` "IP开始异地备份目标公司192.168.30.197,服务所在地公司">/root/backsvn47.log /usr/bin/rsync -avzu --progress --delete --password-file=/etc/rsync.passwd rsync@ipaddress::svnbakdir /hwdata/backsvn47/ >>/root/backsvn47.log if [ $? -eq 0 ];then echo `date +"%F %T"` "备份成功">>/root/backsvn47.log else echo `date +"%F %T"` "备份失败">>/root/backsvn47.log mail -s "svn备份消息推送" lize@example.com </root/backsvn47.log fi sleep 300 let i++ fi done
监控小脚本
#!/bin/bash times=$(ps -ef | grep /root/backsvn.sh |grep -v grep |wc -l) if [ $times -eq 1 ];then echo `date +"%F %T"` "正常" else echo `date +"%F %T"` $(ps -ef | grep /root/backsvn.sh |grep -v grep)>/root/svn_check_life.log echo `date +"%F %T"` "尝试启动同步脚本">>/root/svn_check_life.log kill -9 $(ps -ef | grep /root/backsvn.sh |grep -v grep|awk '{print $2}') sleep 1 /bin/bash /root/backsvn.sh echo "尝试启动同步脚本" if [ $? -eq 0 ];then echo `date +"%F %T"` "脚本启动完毕" >>/root/svn_check_life.log else echo `date +"%F %T"` "脚本启动失败" >>/root/svn_check_life.log mail -s "svn监控脚本消息推送" lize@example </root/svn_check_life.log fi fi
*/10 * * * * /bin/bash /root/60backsvn.sh
十分钟监控一次如果脚本被关闭,重启如果重启失败,则发送邮件