轉(zhuǎn)帖來(lái)自網(wǎng)上Hu YunQiang的一個(gè)db2move 備份數(shù)據(jù)庫(kù)的腳本。
# Shell programmer : Hu YunQiang. ########################################################################################## # 程序名稱: db2back.sh # 入口參數(shù): 無(wú) # # 返回結(jié)果: 數(shù)據(jù)庫(kù)的備份 # # 功能描述: ① 備份數(shù)據(jù)庫(kù)DBname # # # 程序編碼: Hu YunQiang # 發(fā)布日期: 20040915 # # 更新記錄: UserName Date(YYYYMMDD) Note # # ########################################################################################## echo "---------------------------------------------------------------------------------------" echo "程序名稱: $0 編碼 : Hu YunQinag" echo "入口參數(shù): 無(wú)" echo "格式 sh $0 " echo "Hu YunQinag 版權(quán)所有" echo "---------------------------------------------------------------------------------------" ####################### # export environment # ####################### export DB2INSTANCE=db2inst1 export HOSTNAME=p630 export LD_LIBRARY_PATH=/home/db2inst1/sqllib/lib export LIBPATH=/home/db2inst1/sqllib/lib export PATH=/bin:/usr/bin:/usr/local/bin:/usr/bin/X11:/usr/X11R6/bin:/home/db2inst1/sqllib/bin:/home/db2inst1/sqllib/adm:/home/db2inst1/sqllib/misc:/home/db2inst1/bin export CLASSPATH=/home/db2inst1/sqllib/java/db2java.zip:/home/db2inst1/sqllib/java/db2jcc.jar:/home/db2inst1/sqllib/function ####################### # backupdb main # ####################### backupdb(){ cd $sourcedir mkdir $backupfolder if [ ! -d $backupfolder ] then echo "`date +%Y%m%d`:創(chuàng)建備份目錄失敗"> $bkerrlog exit fi cd $backupfolder db2move $1 export -u $2 -p $3 cd .. tar cvf $backupfolder.tar $backupfolder gzip -9 $backupfolder.tar } ####################### # ftp main # ####################### myftp(){ ftp -n <<EOF open $desthost user $user $passwd binary prompt off lcd $sourcedir cd $destdir put $filename $filenae del $rmoldfile ! touch $sigfile EOF } ####################### # rmbkfile main # ####################### rmbkfile() { cd $sourcedir rm -Rf $backupfolder } ####################### #program main # ####################### #程序公用變量 sourcedir=/db2back shellpath=/home/db2inst1/backup sigfile=finish.`date +%Y%m%d` mainlog=errlog.`date +%Y%m%d` #backup程序變量 backupfolder=`date +%Y%m%d`.dbname.db2.bak dbname=dbname dbuser=dbuser dbpwd=dbpwd bkerrlog=bkerr.log.`date +%Y%m%d` #ftp程序變量 desthost=192.168.0.111 user=db2backup passwd=db2backup destdir=/ filename=$backupfolder.tar.gz ftperrlog=ftperr.log.`date +%Y%m%d` oldday0=`date +%Y%m%d` backupdb $dbname $dbuser $dbpwd if [ $? != 0 ] then echo "`date +%Y%m%d`:備份失敗" > $mainlog exit fi cd $shellpath oldday1=`./mydate.sh $oldday0` rmoldfile=`./mydate.sh $oldday1`.dbname.db2.bak.tar.gz myftp if [ $? != 0 ] then echo "`date +%Y%m%d`:ftp文件失敗" > $mainlog exit fi rmbkfile if [ $? != 0 ] then echo "`date +%Y%m%d`:刪除失敗" > $mainlog exit fi cd $sourcedir rm $rmoldfile 說(shuō)起來(lái)比較不好意思,當(dāng)時(shí)不熟悉find -atime -mtime -ctime 的用法,還折騰一個(gè)判斷日起的shell。后面刪除過(guò)期備份文件的方法,只要兩句話就好了,定義一個(gè)變量 n=5 #保留這些天之內(nèi)的 cd $sourcedir find . -atime +$n -exec rm -fr {} ; 之后只要把這個(gè)腳本加入到對(duì)應(yīng)用戶的crontab就好了 |
|
來(lái)自: 星月晨光 > 《數(shù)據(jù)庫(kù)》