您的位置:軟件測試 > 軟件項目管理 > 項目管理軟件 > 禪道項目管理軟件
禪道及其數(shù)據(jù)庫自動備份及短信、郵件通知腳本
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時間:[ 2015/7/8 16:11:37 ] 推薦標簽:項目管理工具

  三、數(shù)據(jù)庫自動備份腳本
  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、賦予腳本執(zhí)行權(quán)限
  chmod +x db_backup.sh
  3、任務(wù)計劃自動執(zhí)行
  #crontab -e
  0 0 * * * /bin/sh /opt/scripts/db_backup.sh > /dev/null 2>&1
  四、更新腳本版本:
  數(shù)據(jù)庫備份腳本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下一頁
軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd