禅道及其数据库自动备份及短信、邮件通知脚本
一、添加SMTP服务器
在需要发送自动报警的服务器上修改如下文件,增加如下两行
# vim /etc/mail.rc set from=[email protected] smtp=smtp.126.com set smtp-auth-user=doteyplay smtp-auth-password=*** smtp-auth=login
当然,这里的SMTP服务器也可以使用别的,比如QQ的,但是QQ只能发几卦,在测试的时候,总报错:smtp-server: 454 Error: authentication failed, system busy,万恶的TX啊!所以,后来就改126的SMTP服务器了,用起来还是相当不错的。对于邮箱嘛,就用139邮箱吧,因为有短信提醒,同样,在测试的时候,QQ邮箱那个慢呀……
二、禅道自动备份脚本
1、自动备份脚本
#vim chandao_backup.sh #!/bin/bash #Auto backup for chandao #Date: first write on 2014.7.22 #Vertion: v1.1 date=`date +%Y-%m-%d` tarball="tar -jcf /opt/backup/chandao-$date.tar.bz2 chandao/" user1=[email protected] user2=[email protected] if [ ! -d "/opt/backup/" ]; then mkdir -p /opt/backup/ fi cd /var/www/html/ && $tarball judge=`echo $?` if [ $judge == 0 ];then echo "backup is ok" | mail -s "Auto backup for chandao" $user1 $user2; else echo "backup is failure" | mail -s "Auto backup for chandao" $user1 $user2; fi find /opt/backup/ -type f -mtime +30 -name "*.bz2" -exec rm -rf {} \;
2、赋予脚本执行权限
chmod +x chandao_backup.sh
2、任务计划自动执行
#crontab -e 0 0 * * * /bin/sh /opt/scripts/chandao_backup.sh 2>&1 /dev/null
三、数据库自动备份脚本
1、自动备份脚本
#vim db_backup.sh #!/bin/bash #Auto backup for mariadb #Date: first write on 2014.7.22 #Vertion: v1.1 date=`date +%Y-%m-%d` datadir="tar -jcf /opt/backup/datadir-$date.tar.bz2 /data" #alldb="mysqldump --all-databases > /opt/backup/alldb-$date.sql" #zentaodb="mysqldump --databases zentao > /opt/backup/zentao-$date.sql" user1=[email protected] user2=[email protected] if [ ! -d "/opt/backup/" ]; then mkdir -p /opt/backup/ fi mysqldump --all-databases > /opt/backup/alldb-$date.sql && mysqldump --databases zentao > /opt/backup/zentao-$date.sql judge=`echo $?` if [ $judge == 0 ];then cd /opt/backup/ && tar -jcf ALLDB-$date.tar.bz2 alldb-$date.sql zentao-$date.sql --remove-files $datadir; judge1=`echo $?` if [ $judge1 == 0 ];then echo "Backup is ok!" | mail -s "Auto backup for db" $user1 $user2; else echo "Db is ok but datadir is failure!" | mail -s "Auto backup for db" $user1 $user2; fi else echo "Backup is failure,because of db backup is faild!" | mail -s "Auto backup for db" $user1 $user2; fi find /opt/backup/ -type f -mtime +30 -name "*.bz2" -exec rm -rf {} \;
2、赋予脚本执行权限
chmod +x db_backup.sh
3、任务计划自动执行
#crontab -e 0 0 * * * /bin/sh /opt/scripts/db_backup.sh 2>&1 /dev/null
本文出自 “nmshuishui的博客” 博客,请务必保留此出处http://nmshuishui.blog.51cto.com/1850554/1529829
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。