Backups and Restore in DB2


There are mainly 2 types of logging in db2.

1.Circular logging

It is a method where the old transaction logs are overwritten when there is a need to allocate a new transaction log file, thus erasing the sequences of log files and reusing them. You are permitted to take only full back-up in offline mode. i.e., the database must be offline to take the full backup.

 2.Archive logging

This mode supports for Online Backup and database recovery using log files called roll forward recovery.

 Backup process :

Offline:

 1.Stop the applications using force command.

 Db2 list applications – List of active applications

 Db2 force application(appid) --  To stop the application

 2.Deactivate the Database using the below command

Db2 deactivate db dbname

 

3.backup db dbname to <location>

 Online:

To start, you need to change the mode from Circular logging to Archive Logging.

Syntax: [To check if the database is using circular or archive logging]

 Db2 get db cfg for dbname | grep -i LOGARCH

If you need to work with ‘ARCHIVE LOGGING’ mode, you need to change or add path in the variables logarchmeth1 present in the configuration file.

Updating logarchmeth1 with required archive directory

mkdir backup

mkdir backup/Archive

 Syntax: [To provide user permissions for folder]

chown db2inst1:db2iadm1 backup/Archive

 Syntax: [To update configuration LOGARCHMETH1]

db2 update database configuration for one using LOGARCHMETH1

'DISK:/home/db2inst1/backup/Archive'

 Syntax: [To take online backup]

db2 backup database dbname online to

/home/db2inst1/onlinebackup/

 Verify Backup file using following command:

Syntax:

db2ckbkp <location/backup file> 

Listing the history of backup files

Syntax:

db2 list history backup all for one   

 Restoring the database from backup

To restore the database from backup file, you need to follow the given syntax:

Syntax:

db2 restore database <db_name> from <location>

taken at <timestamp>

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

Syntax:

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


Comments

Popular posts from this blog

Db2 export command example using file format (del , ixf)

How to fix DB2 Tablespace OFFLINE state issue?

How to determine fenced User-ID of a DB2 instance