Teach DB2 to Roll Data Forward
What if you perform a change to the database after you backed it up? Are the inserts or changes you made to rows lost? No, thanks to the
rollforward command. It lets you recover changes to your databases from transaction logs that DB2 maintains behind the scenes.
Before you can perform a roll forward, however, you have to make sure that your database is configured for the appropriate type of logging. By default, DB2 databases use circular logging, which doesn't retain the transaction history you need to recover a database. The type of logging you need is known as archive logging.
As previously discussed, you can enable archive logging with the following command:
db2 => update database configuration for backdem using logretain on
You can also right click on the appropriate database name in the Control Center's context menu and choose the "Configure Database Logging" option to start the Configure Database Logging Wizard (see Figure 5). The wizard will guide you through the process of selecting a logging type and specifying logging options and parameters.
To test out how rolling forward works, add a new row to the database table:
db2 => insert into secretidentities values (Robin,Dick Grayson)
If you restored your database from the image you created earlier, you would not be able to see the row insert above.
You can perform a rollforward using the following syntax:
db2=> rollforward database backdem user db2admin using db2admin
to end of logs and stop
You can perform rollforwards to a certain point in time (not necessarily to the end of the logs, as done above). The following command specifies that you want to roll forward only to a certain point in time:
db2=> rollforward database backdem user db2admin using db2admin
to 2001-02-22-14.65.21.245343 and stop
The DB2 Control Center includes a Rollforward Wizard that allows you to graphically specify the options for a rollforward operation (see Figure 6).
If Something Can Go Wrong...
If your data is precious to you and your organization, use DB2's built-in features to recover from a data-loss nightmare. You could automate the backup process on a periodic basis to external mediums (e.g., tape drives). The Backup Wizard of the Control Center can guide you through the process of choosing the frequency of your database backup process.
Backup measures may sound pessimistic, as they assume something might go wrong, but they are realistic. Many times things do go wrong. It helps to know that with DB2, you can recover when they do (pun intended).