Db2 automatic backup script
#! /Bin/bash # db2 automatic backup script # create at 2013-07-24 # ------------------------- # parameter dblist1 = BOYA # Database dblist2 to be backed up = BOYACZbkrootpath = ~ /Backup # backup path bkdate = 'date + % Y % m % d' # backup time bkpath =$ {bkrootpath}/$ {bkdate} log =$ {bkdate }. log # log date = 'date + % Y % m % d % k % M % s' backfile1 =1 {dblist1 }. 0. db2inst1. node).catn0000. $ {date} backfile2 =$ {dblist2 }. 0. db2inst1. node).catn0000. $ {date} # initialize the db2 environment if [-f $ {HOME}/sqllib/db2profile]; then. $ {HOME}/sqllib/db2profilefi # create a backup path if [-d $ {bkrootpath}]; then echo "" else mkdir $ {bkrootpath} fiif [-d $ {bkpath}]; then cd $ {bkpath} echo "backed up today" >>$ {log} else mkdir $ {bkpath} cd $ {bkpath} fidb2stop force # Stop db2 database db2start # restart db2 database, to ensure normal backup, echo "--------------------" >$ {log} echo "$ {bkdate}" >$ {log} echo ">>$ {log} echo" to back up database List ">>$ {log} echo" ${dblist1 }, $ {dblist2} ">$ {log} # connect to the backup database 1db2set db2codepage = 1386db2 connect to $ {dblist1} echo" Start backup $ {dblist1} ">$ {log} echo "backing up ...... ">$ {log} db2 backup db $ {dblist1} to" $ {bkpath} "if [-d" $ {backfile1} "]; then echo "successfully backed up the database $ {dblist1}" >$ {log} else echo "failed to back up the database $ {dblist1}" >$ {log} fidb2stop forcedb2start # connect to the backup database 2db2set db2codepage = 1386 db2 connect to $ {dblist2} echo "Start backup $ {dblist2}" >$ {log} echo "backing up ...... ">$ {log} db2 backup db $ {dblist2} to" $ {bkpath} "if [-d" $ {backfile2} "]; then echo "successfully backed up database $ {dblist2}" >$ {log} else echo "failed to back up database $ {dblist2}" >>> {log} fi