您的位置:软件测试 > 软件项目管理 > 项目管理软件 > 禅道项目管理软件
禅道及其数据库自动备份及短信、邮件通知脚本
作者:网络转载 发布时间:[ 2015/7/8 16:11:37 ] 推荐标签:项目管理工具

  三、数据库自动备份脚本
  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=13910892224@139.com
user2=15048088251@139.com
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 > /dev/null 2>&1
  四、更新脚本版本:
  数据库备份脚本v1.2
#!/bin/bash
#Auto backup for mariadb
#Date: first write on 2014.7.22
#Vertion: v1.2
date=`date +%Y-%m-%d`
user1=13910892224@139.com
user2=15048088251@139.com
main(){
tar -jcf /opt/backup/datadir-$date.tar.bz2 /data;
if [ $? -eq 0 ];then
/usr/local/mysql/bin/mysqldump --all-databases > /opt/backup/alldb-$date.sql;
if [ $? -eq 0 ];then
sleep 2
/usr/local/mysql/bin/mysqldump --databases zentao > /opt/backup/zentao-$date.sql;
if [ $? -eq 0 ];then
cd /opt/backup/
tar -jcf ALLDB-$date.tar.bz2 alldb-$date.sql zentao-$date.sql --remove-files
&& echo "Backup is ok!" | mail -s "Auto backup for db" $user2;
else
echo "Zentao db backup failure" | mail -s "Auto backup for db" $user2;
fi
else
echo "All databases backup failure" | mail -s "Auto backup for db" $user2;
fi
else
echo "Datadir backup failure,it's first step" | mail -s "Auto backup for db" $user2;
fi
find /opt/backup/ -type f -mtime +30 -name "*.bz2" -exec rm -rf {} ;
}
if [ ! -d "/opt/backup/" ]; then
mkdir -p /opt/backup/;
main;
else
main;
fi

上一页12下一页
软件测试工具 | 联系我们 | 投诉建议 | 诚聘英才 | 申请使用列表 | 网站地图
沪ICP备07036474 2003-2017 版权所有 上海泽众软件科技有限公司 Shanghai ZeZhong Software Co.,Ltd