The {@link LogVerificationInputStream example here} shows how to implementthe {@code myCopyFiles} method using {@link LogVerificationInputStream}. A filter input stream is used to verify the file efficiently as it is being read. If you choose to use a script for copying files, the {@link DbVerifyLog} command line tool can be usedinstead.
Assuming that the full backup copied files into an empty directory, to restore you can simply copy these files back into another empty directory.
Always start with an empty directory as the destination for a full backup or a restore, to ensure that no unused files are present. Unused files -- perhaps the residual of an earlier environment or an earlier backup -- will take up space, and they will never be deleted by the JE log cleaner. Also note that such files will not be used by JE for calculating utilization and will not appear in the {@link DbSpace} output.
Performing incremental backups
Incremental backups are used to reduce the number of files copied during each backup. Compared to a full backup, there are two additional pieces of information needed for an incremental backup: the number of the last file in the previous backup, and a list of the files in the environment directory at the time of the current backup. Their purpose is explained below.
The number of the last file in the previous backup is used to avoid copying files that are already present in the backup set. This file number must be obtained before beginning the backup, either by checking the backup archive, or getting this value from a stored location. For example, the last file number could be written to a special file in the backup set at the time of a backup, and then read from the special file before starting the next backup.
The list of current files in the environment, which should be obtained after calling {@link #startBackup}, is used to avoid unused files after a restore, and may also be used to reduce the size of the backup set. How to use this list is described below.
Some applications need the ability to restore to the point in time of any of the incremental backups that were made in the past, and other applications only need to restore to the point in time of the most recent backup. Accordingly, the list of current files (that is made at the time of the backup), should be used in one of two ways.
The following two examples shows how to perform an incremental backup. In the first example, the list of current files is used to delete files from the backup set that are no longer needed.
void myBackup(Environment env, File destDir) { DbBackup backupHelper = new DbBackup(env); // Get the file number of the last file in the previous backup. long lastFileInPrevBackup = ... // Optional: Do a checkpoint to reduce recovery time after a restore. env.checkpoint(new CheckpointConfig().setForce(true)); // Start backup, find out what needs to be copied. backupHelper.startBackup(); try { // Copy the necessary files to archival storage. String[] filesForBackup = backupHelper.getLogFilesInBackupSet(lastFileInPrevBackup); myCopyFiles(env, filesForBackup, destDir); // Delete files that are no longer needed. // WARNING: This should only be done after copying all new files. String[] filesAtBackupTime = myGetCurrentFiles(env); myDeleteUnusedFiles(destDir, filesAtBackupTime); // Optional: Update knowledge of last file saved in the backup set. lastFileInPrevBackup = backupHelper.getLastFileInBackupSet(); // Save lastFileInPrevBackup persistently here ... } finally { // Remember to exit backup mode, or the JE cleaner cannot delete // log files and disk usage will grow without bounds. backupHelper.endBackup(); } } String[] myGetCurrentFiles(Environment env) { // If multiple data directories are used, this will need to be changed // to return all files for all data directories. return env.getHome().list(); } void myDeleteUnusedFiles(File destDir, String[] filesAtBackupTime) { // For each file in destDir that is NOT in filesAtBackupTime, it should // be deleted from destDir to save disk space in the backup set, and to // ensure that unused files will not be restored. } void myCopyFiles(Environment env, String[] filesForBackup, File destDir) { // See {@link LogVerificationInputStream}}
When performing backups as shown in the first example above, to restore you can simply copy all files from the backup set into an empty directory.
In the second example below, the list of current files is saved with the backup set so it can be used during a restore. The backup set will effectively hold multiple backups that can be used to restore to different points in time.
void myBackup(Environment env, File destDir) { DbBackup backupHelper = new DbBackup(env); // Get the file number of the last file in the previous backup. long lastFileInPrevBackup = ... // Optional: Do a checkpoint to reduce recovery time after a restore. env.checkpoint(new CheckpointConfig().setForce(true)); // Start backup, find out what needs to be copied. backupHelper.startBackup(); try { // Copy the necessary files to archival storage. String[] filesForBackup = backupHelper.getLogFilesInBackupSet(lastFileInPrevBackup); myCopyFiles(env, filesForBackup, destDir); // Save current list of files with backup data set. String[] filesAtBackupTime = myGetCurrentFiles(env); // Save filesAtBackupTime persistently here ... // Optional: Update knowledge of last file saved in the backup set. lastFileInPrevBackup = backupHelper.getLastFileInBackupSet(); // Save lastFileInPrevBackup persistently here ... } finally { // Remember to exit backup mode, or the JE cleaner cannot delete // log files and disk usage will grow without bounds. backupHelper.endBackup(); } } String[] myGetCurrentFiles(Environment env) { // If multiple data directories are used, this will need to be changed // to return all files for all data directories. return env.getHome().list(); } void myCopyFiles(Environment env, String[] filesForBackup, File destDir) { // See {@link LogVerificationInputStream}}
When performing backups as shown in the example above, to restore you must choose one of the file lists that was saved. You may choose the list written by the most recent backup, or a list written by an earlier backup. To restore, the files in the list should be copied into an empty destination directory.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|