DB2: Backup and Recovery Cheat Sheet


  • Offline backup

List the active applications/databases

db2 list application  

Terminate Database Connection

db2 terminate 

Deactivate Database

db2 deactivate database one   

Take the backup file

db2 backup database <db_name> to <location>   
  • Online backup

Check if the database is using circular or archive logging

db2 get db cfg for one | grep LOGARCH   

Updating logarchmeth1 with required archive directory

Make directories

mkdir backup 
mkdir backup/ArchiveDest   

Provide user permissions for folder

chown db2inst1:db2iadm1 backup/ArchiveDest 

Update configuration LOGARCHMETH1

db2 update database configuration for one using LOGARCHMETH1 

Take online backup

db2 backup database one online to 
/home/db2inst1/onlinebackup/ compress include logs  

Verify Backup

db2ckbkp <location/backup file>   

Listing the history of backup files

db2 list history backup all for one    

Restoring the database from backup

Restore the database from backup file

db2 restore database <db_name> from <location> 
taken at <timestamp>    

Roll forward all the logs located in the log directory, including the latest changes just before the disk drives failure.

db2 rollforward db <db_name> to end of logs and stop 

Leave a Reply

Your email address will not be published. Required fields are marked *