db2自動備份腳本
#!/bin/bash #db2自動備份腳本 # create at 2013-07-24 #--------------------------- #參數 dblist1=BOYA #要備份的數據庫 dblist2=BOYACZ bkrootpath=~/backup #備份路徑 bkdate=`date +%Y%m%d` #備份時間 bkpath=${bkrootpath}/${bkdate} log=${bkdate}.log #日志 date=`date +%Y%m%d%k%M%S` backfile1=${dblist1}.0.db2inst1.NODE0000.CATN0000.${date} backfile2=${dblist2}.0.db2inst1.NODE0000.CATN0000.${date} #初始化db2環境 if [ -f ${HOME}/sqllib/db2profile ]; then . ${HOME}/sqllib/db2profile fi #創建備份路徑 if [ -d ${bkrootpath} ];then echo "" else mkdir ${bkrootpath} fi if [ -d ${bkpath} ];then cd ${bkpath} echo "今天已備份">>${log} else mkdir ${bkpath} cd ${bkpath} fi db2stop force #停止db2數據庫 db2start #重啟db2數據庫,以保證備份正常進行 echo "----------------------">${log} echo "${bkdate}">>${log} echo "">>${log} echo "所要備份數據庫列表">>${log} echo "${dblist1},${dblist2}">>${log} #連接備份數據庫1 db2set db2codepage=1386 db2 connect to ${dblist1} echo "開始備份${dblist1}">>${log} echo "正在備份......">>${log} db2 backup db ${dblist1} to "${bkpath}" if [ -d "${backfile1}" ];then echo "成功備份數據庫${dblist1}">>${log} else echo "備份數據庫${dblist1}失敗">>${log} fi db2stop force db2start #連接備份數據庫2 db2set db2codepage=1386 db2 connect to ${dblist2} echo "開始備份${dblist2}">>${log} echo "正在備份......">>${log} db2 backup db ${dblist2} to "${bkpath}" if [ -d "${backfile2}" ];then echo "成功備份數據庫${dblist2}">>${log} else echo "備份數據庫${dblist2}失敗">>${log} fi