Choose online backups if you back up your database frequently and cannot afford to
deactivate it for each backup. Online backups allow you to maintain all connections to the database,
but they require more disk space to store the history of transaction logs.
About this task
During an online backup, the entire database is copied to a file, but it might not contain
transactions that were being performed on the database while the backup was being created.
Therefore, the backup file must always be complemented with transaction logs to restore the database
to the consistent state. Transaction logs are backed up automatically after enabling archive
logging, and must always be stored in a safe location together with the backup file. After you
restore the database from the backup file, you add the archive logs, and the database is complete.
Enabling the archive logging for the first time requires that you deactivate the database.
Procedure
-
Set up archive logging.
Note: TEMADB
is the default database name. If you are unsure
whether it applies to your database, see:
Checking the database
name.
-
Check the status of archive logging in your database. If the first archive method contains a
value other than OFF, you can omit the following steps and make an online backup.
db2 get db cfg for TEMADB | grep LOGARCHMETH
First log archive method(LOGARCHMETH1) = OFF
Second log archive method(LOGARCHMETH2) = OFF
-
Create a backup directory that will be used to store archive logs and online backups, and give
it proper permissions.
mkdir /var/online_backup
chown db2inst1:db2iadm1 /var/online_backup
-
Update the database configuration to enable archive logging and point to the new
directory.
db2 update database configuration for TEMADB using LOGARCHMETH1 'disk:/var/online_backup'
DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.
The
status of archive logging settings also changed to a specific
path:
First log archive method (LOGARCHMETH1) = DISK:/var/online_backup/
-
Terminate the connections and deactivate the database.
db2 force application all
db2 deactivate db TEMADB
-
Make a full offline backup.
db2 backup database TEMADB to <location>
Creating an offline backup
is a requirement after enabling the archive logging. Although you will not need to create offline
backups later, it is a good practice to create them before major changes to the database. The
archive logs can be applied in the same way both to offline and online backups to restore them to
the most recent state. You can store this offline backup in a safe location as an extra
precaution.
-
Activate the database.
- Restart the License Metric Tool server to restore its connection to the database.
For more information, see: Administering the server
-
If DB2 is shared with the BigFix server,
restart the BigFix server to restore its
connection to the database.
-
Make an online backup.
db2 backup database TEMADB online to /var/online_backup/ compress include logs
Backup successful. The timestamp for this backup image is : xxxxxxxxxxxx
Whenever
you create an online backup, all archive logs created up to this point are no longer needed. To
restore a complete database, you need a backup file and subsequent archive logs.
-
Verify that the backup file was correctly created.
db2ckbkp <online backup file>
Image Verification Complete - successful.