In my book, “DB2 9.7 Advanced Administration Cookbook“, I discussed redirected restores. However, this was from an offline backup. If you only use online backups, you may still achieve the same goal using the commands I used below.
It took a while for me to grasp the online redirected restore, and figure out the error messages. So let me share this with you, and avoid wasting your time on an otherwise simple task. Don’t forget to use the same window throughout this procedure.
Having an online redirected restores means you have to deal with logs and rolling forward the database. We’ll have to assume here that the backup has been made with the “include logs” option. These logs will be extracted into a logtarget directory, which we will create first, and specify in the restore command below:
mkdir -p /db2/backup/20120425_prod_support/logtarget
db2 "restore database bcgapps from '/db2/backup/20120425_prod_support'
taken at 20120425134406
into bcgapps1
logtarget '/db2/backup/20120425_prod_support/logtarget'
newlogpath '/db2/db2inst1/bcgapps1/archlogs'
with 2 buffers buffer 1024
redirect parallelism 1
without prompting"
DB2 will print a message indicating restore is completed.
SQL1277W A redirected restore operation is being performed. Table space
configuration can now be viewed and table spaces that do not use automatic
storage can have their containers reconfigured.
DB20000I The RESTORE DATABASE command completed successfully.
You have to set the path for the tablespaces, which we will do here:
db2 "set tablespace containers for 0
using ( path '/db2/db2inst1/bcgapps1/system' )"
db2 "set tablespace containers for 1
using ( path '/db2/db2inst1/bcgapps1/tables' )"
db2 "set tablespace containers for 2
using ( path '/db2/db2inst1/bcgapps1/user' )"
db2 "set tablespace containers for 3
using ( path '/db2/db2inst1/bcgapps1/log' )"
db2 "set tablespace containers for 4
using ( path '/db2/db2inst1/bcgapps1/dup' )"
db2 "set tablespace containers for 5
using ( path '/db2/db2inst1/bcgapps1/profile' )"
db2 "set tablespace containers for 6
using ( path '/db2/db2inst1/bcgapps1/temp' )"
db2 "set tablespace containers for 7
using ( path '/db2/db2inst1/bcgapps1/user_temp' )"
db2 "set tablespace containers for 8
using ( path '/db2/db2inst1/bcgapps1/systoolspace' )"
db2 "set tablespace containers for 9
using ( path '/db2/db2inst1/bcgapps1/systoolstmpspace' )"
Once all tablespaces have been set, here is the actual restore:
db2 "restore database bcgapps continue"
If you open another window and look at the logtarget directory, you will see the logs extracted from the backup,
db2inst1@nodedb21:/db2/dbbackup/BACKUP/20120425_prod_support/logtarget> ls -al
total 408
drwxrwxr-x 2 db2inst1 db2iadm1 256 Apr 26 08:57 .
drwxrwxr-x 4 db2inst1 db2iadm1 4096 Apr 26 08:50 ..
-rw------- 1 db2inst1 db2iadm1 106496 Apr 26 08:57 S0001712.LOG
-rw------- 1 db2inst1 db2iadm1 98304 Apr 26 08:57 S0001713.LOG
These logs will be used in the next step. So going back to the restore window:
db2 "rollforward database bcgapps1 to end of logs and complete
overflow log path ( '/db2/backup/20120425_prod_support/logtarget') "
You should see this result:
Rollforward Status
Input database alias = bcgapps1
Number of nodes have returned status = 1
Node number = 0
Rollforward status = not pending
Next log file to be read =
Log files processed = S0001712.LOG - S0001713.LOG
Last committed transaction = 2012-04-25-18.45.15.000000 UTC
DB20000I The ROLLFORWARD command completed successfully.
If you did not specify the logtarget option, you will see see messages like this one:
SQL4970N Roll-forward recovery on database "BCGAPPS1" cannot reach the
specified stop point (end-of-log or point-in-time) because of missing or
corrupted log file(s) on database partition(s) "0". Roll-forward recovery
processing has halted on log file "S0001712.LOG".
Have fun !