Chapter 5. Backing up and Restoring Berkeley DB, Java Edition Applications

Table of Contents

Normal Recovery
Checkpoints
Performing Backups
Performing a Hot Backup
Performing an Offline Backup
Using the DbBackup Helper Class
Performing Catastrophic Recovery
Hot Failover

Fundamentally, you backup your databases by copying JE log files off to a safe storage location. To restore your database from a backup, you copy those files to an appropriate directory on disk and restart your JE application.

Note that if you are using subdirectories to store your JE log files, then your backup and restore process must maintain the relationship between each log file and the subdirectory in which JE intially placed it. That is, if JE placed log file number 17 in the subdirectory named data003, then when you perform a recovery log file number 17 must be placed inside subdirectory data003.

Beyond these simple activities, there are some differing backup strategies that you may want to consider. These topics are described in this chapter.

Before continuing, before you review the information on log files and background threads in the Getting Started with Berkeley DB, Java Edition guide. Those topics contain important information that is basic to the following discussion on backups and restores.

Normal Recovery

Remember that internally JE databases are organized in a BTree, and that in order to operate JE requires the complete BTree be available to it.

When database records are created, modified, or deleted, the modifications are represented in the BTree's leaf nodes. Beyond leaf node changes, database record modifications can also cause changes to other BTree nodes and structures.

Now, if your writes are transaction-protected, then every time a transaction is committed the leaf nodes (and only the leaf nodes) modified by that transaction are written to the JE log files on disk. Also, remember that the durability of the write (whether a flush or fsync is performed) depends on the type of commit that is requested. See Non-Durable Transactions for more information.

Normal recovery, then, is the process of recreating the entire BTree from the information available in the leaf nodes. You do not have to do anything special to cause normal recovery to be run; this occurs every time a JE environment is opened.

You can know if normal recovery must be run by catching EnvironmentFailureException. This exception indicates that a failure has occurred that impacts the Environment as a whole. Upon seeing this exception, you should run Environment.isValid(). If it returns true, then you can continue operating without any further action. However, if it returns false, then you must close and reopen all Environment handles so that normal recovery can be run.