Database restore backup fool show script

Source: Internet
Author: User

#!/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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.