This section lists examples of the following BART operations.
Restoring a database cluster with tablespaces.
Restoring an incremental backup.
Managing backups.
Managing incremental backups.
Restoring a Database Cluster with Tablespaces
The following code sample illustrates taking a backup and restoring a database cluster on a remote host containing tablespaces. For detailed information regarding using tablespaces, see the EDB Backup and Recovery User Guide available at the EDB website.
On an Advanced Server database running on a remote host, the following tablespaces are created for use by two tables:
The following code sample shows the OIDs assigned to the tablespaces and the symbolic links to the tablespace directories:
The BART configuration file contains the following settings. Note that the tablespace_path parameter does not have to be set at this point.
After the necessary configuration steps are performed to ensure BART manages the remote database server, a full backup is taken as shown in the following code sample:
Note that in the output from the preceding example, checksums are generated for the tablespaces as well as the full backup.
Within the backup subdirectory 1447709811516 of the BART backup catalog, the tablespace data is stored with file names 16587.tar.gz and 16588.tar.gz as shown below:
When you are ready to restore the backup, in addition to creating the directory to which the main database cluster is to be restored, you must prepare the directories to which the tablespaces are to be restored.
On the remote host, directories /opt/restore_tblspc_1 and /opt/restore_tblspc_2 are created and assigned the proper ownership and permissions as shown by the following example. The main database cluster is to be restored to /opt/restore.
Set the tablespace_path parameter in the BART configuration file to specify the tablespace directories. The remote host user and IP address are specified by the remote_host configuration parameter.
The following code sample demonstrates invoking the RESTORE subcommand:
The following code sample shows the restored full backup (including the restored tablespaces):
The symbolic links in the pg_tblspc subdirectory point to the restored directory location:
psql queries also show the restored tablespaces:
Restoring an Incremental Backup
Restoring an incremental backup may require additional setup steps depending upon the host on which the incremental backup is to be restored. For more information, see the EDB Backup and Recovery User Guide available at the EDB website.
This section provides an example of creating backup chains and then restoring an incremental backup.
Creating a Backup Chain
A backup chain is the set of backups consisting of a full backup and all of its successive incremental backups. Tracing back on the parent backups of all incremental backups in the chain eventually leads back to that single, full backup.
In the following example, the allow_incremental_backups parameter is set to enabled in the BART configuration file to permit incremental backups on the listed database server:
After the database server has been started with WAL archiving enabled to the BART backup catalog, the WAL scanner is started:
First, a full backup is taken.
A series of incremental backups are taken. The first incremental backup specifies the full backup as the parent. Each successive incremental backup then uses the preceding incremental backup as its parent.
The following output of the SHOW-BACKUPS subcommand lists the backup chain, which are backups full_1, incr_1-a, incr_1-b, and incr_1-c.
For the full backup full_1, the BACKUP PARENT field contains none. For each incremental backup, the BACKUP PARENT field contains the backup identifier or name of its parent backup.
A second backup chain is created in the same manner with the BACKUP subcommand. The following example shows the addition of the resulting, second backup chain consisting of full backup full_2 and incremental backups incr_2-a and incr_2-b.
The following additional incremental backups starting with incr_1-b-1, which designates incr_1-b as the parent, results in the forking from that backup into a second line of backups in the chain consisting of full_1, incr_1-a, incr_1-b, incr_1-b-1, incr_1-b-2, and incr_1-b-3 as shown in the following list:
Restoring an Incremental Backup
Restoring an incremental backup is done with the RESTORE subcommand in the same manner as for restoring a full backup. Specify the backup identifier or backup name of the incremental backup to be restored as shown in the following example.
Restoring incremental backup incr_1-b as shown by the preceding example results in the restoration of full backup full_1, then incremental backups incr_1-a and finally, incr_1-b.
Managing Backups
This section illustrates evaluating, marking, and deleting backups using the MANAGE subcommand using a redundancy retention policy and a recovery window retention policy. For detailed information about the MANAGE subcommand, see the EDB Backup and Recovery User Guide available at the EDB website.
Using a Redundancy Retention Policy
The following code sample uses a redundancy retention policy to evaluate, mark, and delete backups as shown by the following server configuration:
The following list is the set of backups. Note that the last backup in the list has been marked as keep.
Invoke the MANAGE subcommand with the -n option to perform a dry run to observe which active backups would be changed to obsolete according to the retention policy as shown in the following code sample:
The dry run shows that backups 1428502049836 and 1428422324880 would be marked as obsolete.
Note
A dry run does not change the backup status. The two backups that would be considered obsolete are still marked as active:
Invoke the MANAGE subcommand omitting the -n option to change and mark the status of the backups as obsolete:
The obsolete backups can be observed in a number of ways. Use the MANAGE subcommand with the -l option to list the obsolete backups:
The STATUS field of the SHOW-BACKUPS subcommand displays the current status:
The details of an individual backup can be displayed using the SHOW-BACKUPS subcommand with the -t option. Note the status in the BACKUP STATUS field.
Use the MANAGE subcommand with the -d option to physically delete the obsolete backups including the unneeded WAL files.
The SHOW-BACKUPS subcommand now displays the remaining backups marked as active or keep:
Using a Recovery Window Retention Policy
This section illustrates the evaluation, marking, and deletion of backup using a recovery window retention policy. To use the recovery window retention policy, set the retention_policy parameter to the desired length of time for the recovery window.
This section provides examples of the following:
How to view the calculated recovery window.
How to evaluate, mark, and delete backup using a recovery window retention policy.
Viewing the Recovery Window
You can view the actual, calculated recovery window by invoking any of the following subcommands:
MANAGE subcommand in debug mode (along with the -n option).
SHOW-SERVERS subcommand.
Viewing the Recovery Window Using the Manage Subcommand
When invoking BART in debug mode with the MANAGE subcommand and the -n option, the length of the recovery window is calculated based on the retention_policy setting and the current date/time.
For example, using the following retention_policy settings:
If the MANAGE subcommand is invoked in debug mode along with the -n option on 2015-04-17, the following results are displayed:
For server acctg, 72 hours translates to a recovery window of 3 days.
For server dev, 504 hours translates to a recovery window of 21 days (3 weeks).
For server hr, 2160 hours translates to a recovery window of 90 days (3 months).
For a setting of <max_number> MONTHS, the calculated total number of days for the recovery window is dependent upon the actual number of days in the preceding months from the current date/time. Thus, <max_number> MONTHS is not always exactly equivalent to <max_number> x 30 DAYS. For example, if the current date/time is in the month of March, a 1-month recovery window would be equivalent to only 28 days because the preceding month is February. Thus, for a current date of March 31, a 1-month recovery window would start on March 3. However, the typical result is that the day of the month of the starting recovery window boundary will be the same day of the month of when the MANAGE subcommand is invoked.
Viewing the Recovery Window Using the Show-Servers Subcommand
This section provides an example of viewing the recovery window using the SHOW-SERVERS subcommand; the RETENTION POLICY field displays the start of the recovery window.
In the following code sample, the recovery window retention policy setting considers the backups taken within a 3-day recovery window as the active backups.
The start of the 3-day recovery window displayed in the RETENTION POLICY field is 2015-04-07 14:57:36 EDT when the SHOW-SERVERS subcommand is invoked on 2015-04-10.
At this current point in time, backups taken on or after 2015-04-07 14:57:36 EDT would be considered active. Backups taken prior to 2015-04-07 14:57:36 EDT would be considered obsolete except for backups marked as keep.
In the following code sample, the recovery window retention policy setting considers the backups taken within a 3-week recovery window as the active backups.
The start of the 3-week recovery window displayed in the RETENTION POLICY field is 2015-03-20 14:59:42 EDT when the SHOW-SERVERS subcommand is invoked on 2015-04-10.
At this current point in time, backups taken on or after 2015-03-20 14:59:42 EDT would be considered active. Backups taken prior to 2015-03-20 14:59:42 EDT would be considered obsolete except for backups marked as keep.
In the following code sample, the recovery window retention policy setting considers the backups taken within a 3-month recovery window as the active backups.
The start of the 3-month recovery window displayed in the RETENTION POLICY field is 2015-01-10 14:04:23 EST when the SHOW-SERVERS subcommand is invoked on 2015-04-10.
At this current point in time, backups taken on or after 2015-01-10 14:04:23 EST would be considered active. Backups taken prior to 2015-01-10 14:04:23 EST would be considered obsolete, except for backups marked as keep.
Evaluating, Marking, and Deleting Backup Using a Recovery Window Retention Policy
The following code sample uses a recovery window retention policy to evaluate, mark, and delete backups as shown by the following server configuration:
The following is the current set of backups. Note that the last backup in the list has been marked as keep.
The current date and time is 2015-04-13 16:46:35 EDT as shown below:
Thus, a 3-day recovery window would evaluate backups prior to 2015-04-10 16:46:35 EDT as obsolete except for those marked as keep.
Invoke the MANAGE subcommand with the -n option to perform a dry run to observe which active backups would be changed to obsolete according to the retention policy.
The dry run shows that backups 1428684544008 and 1428590536488 would be marked as obsolete.
Also note that a dry run does not change the backup status. The two backups that would be considered obsolete are still marked as active:
Invoke the MANAGE subcommand omitting the -n option to change and mark the status of the backups as obsolete:
The obsolete backups can be observed in a number of ways. Use the MANAGE subcommand with the -l option to list the obsolete backups:
The STATUS field of the SHOW-BACKUPS subcommand displays the current status:
The details of an individual backup can be displayed using the SHOW-BACKUPS subcommand with the -t option. Note the status in the BACKUP STATUS field.
Use the MANAGE subcommand with the -d option to physically delete the obsolete backups including the unneeded WAL files.
The SHOW-BACKUPS subcommand now displays the remaining backups marked as active or keep:
Managing Incremental Backups
This section illustrates evaluating, marking, and deleting incremental backups using the MANAGE and DELETE subcommands utilizing redundancy retention policy and recovery window retention policy. For detailed information about the MANAGE and DELETE subcommands, as well as the redundancy retention and recovery window retention policy, see the EDB Backup and Recovery User Guide available at the EDB website.
Using a Redundancy Retention Policy provides an example of using the MANAGE and DELETE subcommands when a 3 backup redundancy retention policy is in effect.
Using a Recovery Window Retention Policy provides an example of using the MANAGE and DELETE subcommands when a 1-day recovery window retention policy is in effect.
Using a Redundancy Retention Policy
The following code sample uses the MANAGE and DELETE subcommands to evaluate, mark, and delete incremental backups when a 3 backup redundancy retention policy is in effect. The example uses the following server configuration:
The example uses the following set of backups. In these code samples, some columns have been omitted from the SHOW-BACKUPS output to display the relevant information in a more observable manner.
There is one backup chain. The first backup is the initial full backup.
The MANAGE subcommand is invoked as shown by the following:
The following code sample shows the resulting status of the backups:
The status remains active for all backups. Even though the total number of backups exceeds the 3 backup redundancy retention policy, it is only the total number of full backups that is used to determine if the redundancy retention policy has been exceeded. Additional full backups are added including a second backup chain. The following example shows the resulting list of backups:
Second backup chain: 1481749997807 => 1481750098924
The MANAGE subcommand is invoked, but now with a total of four active full backups.
The oldest full backup and its chain of incremental backups are now marked as obsolete.
Invoking the MANAGE subcommand with the -d option deletes the entire obsolete backup chain.
The following code sample shows the remaining full backups and the second backup chain.
Using a Recovery Window Retention Policy
The following example demonstrates using the MANAGE and DELETE subcommands to evaluate, mark, and delete incremental backups when a 1-day recovery window retention policy is in effect. The example uses the following server configuration:
The example uses the following set of backups. In the samples, some columns have been omitted from the SHOW-BACKUPS output to display the relevant information in a more observable manner.
There are two backup chains. In each of the following chains, the first backup is the initial full backup.
Second backup chain: 1481553651165 => 1481554203288 => 1481559303348
The MANAGE subcommand is invoked when the first full backup 1481552078404 falls out of the recovery window. When the MANAGE subcommand is invoked, it is 2016-12-13 09:20:03 EST, thus making the start of the 1-day recovery window at 2016-12-12 09:20:03 EST exactly one day earlier. This backup was taken at 2016-12-12 09:14:39 EST, which is about 5 ½ minutes before the start of the recovery window, thus making the backup obsolete.
The incremental backup date and time are within the recovery window since they were taken after the start of the recovery window of 2016-12-12 09:20:03 EST, but all backups in the chain are marked as obsolete.
The following code sample shows how the entire backup chain is changed back to active status by invoking the MANAGE subcommand with the -c nokeep option on the full backup of the chain.
The backup chain has now been reset to active status.
The following code sample shows usage of the DELETE subcommand on an incremental backup. The specified incremental backup 1481554802918 in the first backup chain as well as its successive incremental backup 1481559014359 are deleted.
The results show that the backups 1481554802918 and 1481559014359 are no longer listed by the SHOW-BACKUPS subcommand.
The MANAGE subcommand is invoked again. This time both backup chains are marked obsolete since the full backups of both chains fall out of the start of the recovery window, which is now 2016-12-12 09:55:03 EST.
The following code sample shows both backup chains marked as obsolete.
The following code sample demonstrates using the MANAGE subcommand with the -c keep option to keep a backup chain indefinitely. The MANAGE subcommand with the -c keep option must specify the backup identifier or backup name of the full backup of the chain, and not any incremental backup.
The full backup 1481553651165 and its successive incremental backups 1481554203288 and 1481559303348 have been changed to keep status:
Finally, the MANAGE subcommand with the -d option is used to delete the obsolete backup chain:
Only the backup chain with the keep status remains as shown below: