#!/bin/bash# The initial database file is placed in the/soft directory, the backup database file is placed in the/tzxdb/backup/directory sif-stopecho "Stopping application, please wait 1 minutes" sleep 60dbname=$ (su - db2inst1 -c "db2 list db directory" |sed -n "10p" |awk ' {print $5} ' |awk -f '/' ' {print $3} ') #获取数据库名read -p "Whether you want to back up an existing database (yes/no):" backupb=yesif [ "$backup" = "$b" ]thenaa=backupbb=$ (ls /tzxdb |grep backup) if [ "$aa" = "$BB" ]thenecho "Backing up Database to/tzxdb/backup/" elseecho "Backing up Database to/tzxdb/backup/" mkdir /tzxdb/backupchmod 777 /tzxdb/backupfi# determine if the backup Data directory exists, Create a new one and attach permissions if it does not exist. su - db2inst1 -c "Db2 force application all" su - db2inst1 -c "Db2 force application all" su - db2inst1 -c "Db2stop" su - db2inst1 -c "Db2start" #重启数据库su - db2inst1 -c "db2 backup db $ Dbname to&nbsP;/tzxdb/backup "echo " Backup complete,/tzxdb/backup/"ls /tzxdb/backup/read -p " make sure to restore the database to the initial state (yes/no) : " aaabbb=yesif [ $aaa" = "$BBB" ]thensu - db2inst1 -c "DB2 force application all "sleep 2su - db2inst1 -c " db2 force Application all "su - db2inst1 -c " db2stop "echo " Database Stop "Su - db2inst1 -c "Db2start" echo "database Start" su - db2inst1 -c "db2 drop db $ dbname "echo " database Delete "cd /tmpecho " in database Restore ... "nohup su - db2inst1 -c "/ Soft/dbinstall " & #在后台执行数据库还原脚本 (see script below) elseecho " exited database Restore "fielseread -p " make sure you want to restore the database to its initial state ( yes/no): " aaabbb=yesif [ $aaa" = "$BBB" ]thensu - db2inst1 -c "Db2 force application all" sleep 2su - db2inst1 -c "db2 Force application&nbSp;all "su - db2inst1 -c " db2stop "echo " Database Stop "su - db2inst1 -c " Db2start "echo " database Start "su - db2inst1 -c " db2 drop db $dbname "echo " Database Delete "cd /tmpecho " in Database recovery ... "nohup su - db2inst1 -c "/soft/dbinstall " & #在后台执行数据库还原脚本 (see script below) elseecho "exited database Restore" fifi# database restore Script #!/bin/bashnamedb1=testdbdbname=$ ( ls /soft |grep db2inst1|awk -F "." ' {print $1} ' dbtime=$ ( ls /soft |grep db2inst1|awk -F ".") ' {print $6} ' ) db2 restore db $dbname from /soft taken at $dbtime on /tzxdb/$namedb 1 dbpath on /tzxdb/$namedb 1 into $namedb 1
This article is from the "Galaxy Marina" blog, be sure to keep this source http://liy607.blog.51cto.com/2892862/1633505
Database restore backup fool show script