2012年6月22日 星期五

DB2 simple backup and restore test

Test Platform OS - RHEL5.3


First, backup the production data
force all the application
command - db2 force application all

try to stop and restart db2
command - db2stop
command - db2start

backup the database, using online backup -
command :db2 BACKUP DATABASE dbName USER db2inst1 USING dbPWD ONLINE TO /home/db2inst1/backup

OPTIONAL - DROP BACKUP DB
command - db2 drop database dbName

restore the database use db2 restore
command - db2 RESTORE DATABASE ${BACKUP_DB} FROM ${BACKUP_LOCAL_DIR} TAKEN AT ${TIMESTAMP} INTO ${RESTORE_DB} REPLACE EXISTING

For changing the database name
command -
vi xxx.cfg

Insert the following to xxx.cfg

DB_NAME=test3,test1
DB_PATH=/home/db2inst1
INSTANCE=db2inst1


After that run the relocate db name command - db2relocatedb -f xxx.cfg
*The new DB name have to be same as the backup_DB name*
roll data to end of log
command - db2 rollforward db DBName to end of logs

rollforward stop
command - db2 rollforward db DBName stop