Basic examples for both offline and online backup of the database are described in the following sections. The examples shown are for the AIX® operating system, and may need to be modified for other operating systems. These examples also incorporate name of the days in a week abbreviation in the naming of the backup locations.
Backing up the directory database:
cp /home/ldapdb2/idsslapd-ldapdb2/etc/* /safeplace/etc
ibmslapd -I ldapdb2 -k
db2 force applications all db2 backup db ldapdb2 to /safeplace/sun-full-ldapdb2
Restoring the directory database on a different machine:
cp /safeplace/etc/* /home/ldapdb2/idsslapd-ldapdb2/etc
db2 restore db ldapdb2 from /safeplace/sun-full-ldapdb2 replace existing
cp /home/ldapdb2/idsslapd-ldapdb2/etc/* /safeplace/etc
ibmslapd -I ldapdb2 -k
db2 update db config for ldapdb2 using newlogpath /safeplace/db2logs-ldapdb2
db2 update db config for ldapdb2 using logarchmeth1 logretain db2 force applications all db2stop db2start
db2 backup db ldapdb2 to /safeplace/sun-full-ldapdb2
ibmslapd -I ldapdb2
db2 backup db ldapdb2 online to /safeplace/mon-ldapdb2
db2 get db config for ldapdb2 | grep -i “Path to log files"
Path to log files = /safeplace/db2logs-ldapdb2/NODE0000/
If a different machine is being used to restore the database, the /safeplace directory on the backed up machine must be set up on the new machine to a local /safeplace directory. This must include all backup directories being used, as well as the log files in the /safeplace/db2log-ldapdb2/NODE0000 directory.
cp /safeplace/etc/* /home/ldapdb2/idsslapd-ldapdb2/etc
db2 restore db ldapdb2 from /safeplace/tues-ldapdb2 taken
at <timestamp_of_backup>
If you are restoring on a new machine, the following warning message is displayed:
SQL2523W Warning! Restoring to an existing database that is different from the database on the backup image, but have matching names. The target database will be overwritten by the backup version. The Roll-forward recovery logs associated with the target database will be deleted. Do you want to continue ? (y/n) y DB20000I The RESTORE DATABASE command completed successfully.
db2 update db config for ldapdb2 using
newlogpath /safeplace/db2logs-ldapdb2db2 rollforward db ldapdb2 to end of logs and stop

cp /home/ldapdb2/idsslapd-ldapdb2/etc/* /safeplace/etc
ibmslapd -I ldapdb2 -k
db2 update db cfg for ldapdb2 using logarchmeth1 logretain trackmod on db2 update db config for ldapclog using logarchmeth1 logretain trackmod on db2 force applications all db2stop db2start
db2 backup db ldapdb2 to /safeplace/sun-full-ldapdb2 db2 backup db ldapclog to /safeplace/sun-full-ldapclog
ibmslapd -I ldapdb2
db2 backup db ldapdb2 online incremental to /safeplace/mon-ldapdb2
db2 get db config for ldapdb2 | grep -i “Path to log files"
An example of the output displayed:
Path to log files = /home/ldapdb2/ldapdb2/NODE0000/SQL00001/SQLOGDIR/
cp /home/ldapdb2/ldapdb2/NODE0000/SQL00001/SQLOGDIR/*
/safeplace/db2logs-ldapdb2
db2 backup db ldapclog online incremental to /safeplace/mon-ldapclogdb2 get db config for ldapclog | grep “Path to log files"
An example of the output displayed:
Path to log files = /home/ldapdb2/ldapdb2/NODE0000/SQL00002/SQLOGDIR/
cp /home/ldapdb2/ldapdb2/NODE0000/SQL00002/SQLOGDIR/*
/safeplace/db2logs-ldapclogSuppose a disk drive failed on Wednesday morning on the machine being used, since the /safeplace directory used to backup the files was not affected, it can be used for restore.
If a different system is being used to restore the database, the /safeplace directories on the backed up system must be set up on the new system to the local /safeplace directory. This must include all backup directories being used, as well as the log files in the /safeplace/db2log-ldapdb2/NODE0000 and the /safeplace/db2log-ldapclog/NODE0000 directories.
cp /safeplace/etc/* /home/ldapdb2/idsslapd-ldapdb2/etc
ibmslapd -I ldapdb2 -k
db2 restore db ldapdb2 incremental from /safeplace/tues-ldapdb2 db2 restore db ldapdb2 incremental from /safeplace/sun-full-ldapdb2 db2 restore db ldapdb2 incremental from /safeplace/tues-ldapdb2
cp /safeplace/db2logs-ldapdb2/*
/home/ldapdb2/ldapdb2/NODE0000/SQL00001/SQLOGDIR
db2 rollforward db ldapdb2 to end of logs and stopdb2 restore db ldapclog incremental from /safeplace/tues-ldapclog db2 restore db ldapclog incremental from /safeplace/sun-full-ldapclog db2 restore db ldapclog incremental from /safeplace/tues-ldapclog
cp /safeplace/db2logs-ldapclog/*
/home/ldapdb2/ldapdb2/NODE0000/SQL00002/SQLOGDIR
db2 rollforward db ldapclog to end of logs and stopIn the examples using incremental backup, the incremental backup increases in size until the next full backup. This is because the backup contains accumulated changes over time, so there are many more changes saved for Saturday than there were for Monday. DB2 also allows “delta" backups, which save only changes made since the last backup of any kind. These delta backups are much smaller and can be done in lesser time. When restoring, you must have all deltas since the last full or incremental backup.
The commands to perform online delta backups for the ldapdb2 database on a daily basis are listed:
db2 backup db ldapdb2 online incremental delta to /safeplace/mon-delta-ldapdb2 db2 backup db ldapdb2 online incremental delta to /safeplace/tues-delta-ldapdb2 db2 backup db ldapdb2 online incremental delta to /safeplace/wed-delta-ldapdb2 db2 backup db ldapdb2 online incremental delta to /safeplace/thurs-delta-ldapdb2 db2 backup db ldapdb2 online incremental delta to /safeplace/fri-delta-ldapdb2 db2 backup db ldapdb2 online incremental delta to /safeplace/sat-delta-ldapdb2
When using delta backups, the log files for the database must be kept in a secure location. If you are using the default log paths, you must copy them to the /safeplace/db2logs-ldapdb2 directory or modify the database configuration to save them directly in the /safeplace/db2logs-ldapdb2 directory.
In the examples, the log files for the database from the backup machine must be available on the machine being used for restoring the delta backups. If you are using the default log paths, you must copy them from the /safeplace/db2logs-ldapdb2/NODE0000 directory on the backup machine to the default log path on the machine being restored, or modify the database configuration newlogpath on the new machine and copy them directly to the /safeplace/db2logs-ldapdb2/NODE000 directory. When restoring from delta backups, you must have ALL deltas since the last full or incremental backup.
The commands to restore online delta backups for the ldapdb2 database are as listed:
db2 restore db ldapdb2 incremental from /safeplace/sat-delta-ldapdb2 db2 restore db ldapdb2 incremental from /safeplace/sun-full-ldapdb2 db2 restore db ldapdb2 incremental from /safeplace/mon-delta-ldapdb2 db2 restore db ldapdb2 incremental from /safeplace/tues-delta-ldapdb2 db2 restore db ldapdb2 incremental from /safeplace/wed-delta-ldapdb2 db2 restore db ldapdb2 incremental from /safeplace/thurs-delta-ldapdb2 db2 restore db ldapdb2 incremental from /safeplace/fri-delta-ldapdb2 db2 restore db ldapdb2 incremental from /safeplace/sat-delta-ldapdb2
Copy the logs and do rollforward:
cp /safeplace/db2logs-ldapdb2/*
/home/ldapdb2/ldapdb2/NODE0000/SQL0001/SQLOGDIR/
db2 rollforward db ldapdb2 to end of logs and stop
If a database is used for high write activity, an online full backup may be more efficient. Although minimal, the tracking of updates to the database can have an impact on the runtime performance of transactions that update or insert data.
Incremental backup can be used as a way to protect a database that is mostly read-only and has some write activity, which makes it important to be recoverable. An incremental backup image is a copy of all database data that has changed since the most recent, successful, and full backup operation. This is also known as a cumulative backup image. The predecessor of an incremental backup image is always the most recent successful full backup of the same object. With this approach, you must save the last full backup and the last cumulative incremental backup because both will be used for restoring the database.
An incremental delta backup image is a copy of all database data that has changed since the last successful backup, such as full, incremental, or incremental delta. This is also known as a differential or noncumulative backup image. While delta backups are smaller, all deltas since the last full or cumulative incremental backup are required to restore the database.
When using online backup, you need to keep archived logs for as long as they might be required for restoring a database, which depends on your backup methodology and goals. This applies even if you have configured one of the log archival options that “automates" log archiving, you still must have a plan to delete old log files as they become expendable so that your archive space does not get full. One key decision that you must make is whether you want to recover your data up to the most recent backup, or you want to recover data right up to the time of the system failure. In case is a disk fails and you have to restore a database from a backup, you must have the log files that were taken during the backup. After the restore activity, the log files are rolled forward to bring the database to a consistent state that existed after the last backup. If you have saved all the log files generated since the last backup, you can replay the logs right to a time just before the crash. This helps reduce loss of updates to the directory considerably. The next main factor is your backup methodology and schedule. Consider the following examples:
In cases where you want to restore a database to a specific point in time and not roll forward any changes made after than point in time, the “without rolling forward" option will prevent DB2 from changing the restored database in rollforward pending state.
db2 restore db ldapdb2 from /safeplace taken at 20040405154705 without rolling forward
To restore a database without prompting for a path that has only one backup database image stored, use the following command:
db2 restore db ldapclog from /safeplace/full-backup-ldapclog without
rolling forward without promptingThe command for offline rollforward database to a point in time:
db2 rollforward database ldapdb2 to 2004-04-22-14.54.21.253422 and stop
This command rolls forward all logs located in the log folder specified in the database configuration file up to and including the point-in-time as stated in the example. The “and stop" key phrase completes the rollforward recovery process by rolling back incomplete transactions and tuning off the rollforward pending state of the database.
In the scenarios listed below, the database name ldapdb2 is used. For change log, the change log database ldapclog can be used.
db2 update db cfg for ldapdb2 using logarchmeth1 logretain trackmod on DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully. SQL1363W One or more of the parameters submitted for immediate modification were not changed dynamically. For these configuration parameters, all applications must disconnect from this database before the changes become effective.
If you receive the displayed message, you must stop and restart ibmslapd for the changes to take effect. Use the following commands:
ibmslapd -I ldapdb2 -k ibmslapd -I ldapdb2
db2 backup database ldapdb2 online to /safeplace SQL2413N Online backup is not allowed because either logretain or userexit for roll-forward is not activated, or a backup pending condition is in effect for the database.
To set the archival logging parameters to enable rollforward recovery for the database ldapdb2 the following DB2 command must be run:
db2 update db config for ldapdb2 using logarchmeth1 logretain
After archival logging is configured, the user must make a full backup of the database. This state is indicated by the backup_pending flag parameter. If a full backup has not been made, the following message will be displayed when the user connects to the database:
db2 connect to ldapdb2 SQL1116N A connection to or activation of database <ldapdb2> cannot be made because of a BACKUP PENDING.
The database will be in backup pending state until an offline backup is performed. This could cause a server to fail when it connects to the database and will start in configuration mode only.
db2 backup database ldapdb2 to /safeplace
If the backup is successful, the following message is displayed:
Backup successful. The timestamp for this backup image is : 20040308170601
db2 restore db ldapdb2 from /safeplace SQL1035N The database is currently in use.
db2 connect to ldapdb2 SQL1117N A connection to or activation of database “LDAPDB2" cannot be made because of ROLL-FORWARD PENDING. SQLSTATE=57019The database will be in rollforward pending state until a rollforward command is issued. This could cause a server to fail when it connects to the database and will start in configuration mode only.
[ Top of Page | Previous Page | Next Page ]