3.5. Creating a Backup #
To create a backup, run the following command:
pg_probackup3 backup -Bbackup_dir--instance=instance_name-bbackup_mode[-sbackup_source] [-ibackup_id]
backup_mode can take one of the following values: FULL, DELTA, and PTRACK.
The -s/--backup-source option can be set to pro (PRO mode), direct (DIRECT mode), or base (BASE mode). If this option is omitted, pg_probackup3 defaults to PRO mode and falls back to BASE mode if PRO is unavailable (pgpro_bindump is not configured).
Note
The BASE server access mode supports only FULL and DELTA backup modes.
Note
You can create multiple backups of the same database cluster in parallel, provided each backup is stored in a separate subdirectory of the backup catalog. These backups are independent and do not affect each other.
A single FULL backup can have multiple independent branches of incremental backup chains, which together constitute a tree-like structure (see Section 5.1.1). By default, when a new incremental backup is created, pg_probackup3 uses the most recent valid backup in the chain as its parent. To branch from a specific backup, specify its ID using the --parent-backup-id option when creating a new backup. For example:
pg_probackup3 backup -B /path/to/backup_dir --instance=dev -b DELTA --parent-backup-id=second-delta-1
Note
A parent backup can only be specified for incremental backups. Full backups have no parent.
In pg_probackup3, a chain of incremental backups can be merged without affecting the full backup. For more details, refer to Section 5.1.3.2.
Some options can be skipped depending on the user goals:
If
backup_modeis not specified,FULLmode is used by default.prois the default value forbackup_source.If the backup ID is not specified explicitly in the body of a request,
backup_idwill take the value of the date and time it was created.If the backup ID is specified and includes a path to a directory,
backup_dirandinstance_namecan be skipped without specification. Example:-i /mnt/ramdisk/backups/2.backup.If a path to the data directory is not specified either via
backup_diror via--backup-id, the current directory is used as the default one.If you omit the parent backup ID (
--parent-backup-id) when performing incremental backups, pg_probackup3 uses the latest valid backup from the backup chain. If pg_probackup3 somehow fails to find it, the backup process terminates with an error.If the
--from-fulloption is specified, an incremental backup is created from the last full backup.
For the full list of the backup options, refer to the command's description.
3.5.1. ARCHIVE WAL Delivery Mode #
ARCHIVE is the default WAL delivery mode.
To make a full backup in ARCHIVE mode, run:
pg_probackup3 backup -Bbackup_dir--instance=instance_name-b FULL
ARCHIVE backups rely on continuous archiving to get WAL segments required to restore the cluster to a consistent state at the time the backup was taken.
3.5.2. STREAM WAL Delivery Mode #
To make a full backup in the STREAM mode, add the --stream flag to the command from the previous example:
pg_probackup3 backup -Bbackup_dir--instance=instance_name-b FULL --stream
Unlike backups in ARCHIVE mode, STREAM backups include all the WAL segments required to restore the cluster to a consistent state at the time the backup was taken.
During backup pg_probackup3 streams WAL files containing WAL records between Start LSN and Stop LSN to the backup file.
Even if you are using continuous archiving, STREAM backups can still be useful in the following cases:
STREAMbackups can be restored on the server that has no file access to WAL archive.STREAMbackups enable you to restore the cluster state at the point in time for which WAL files in archive are no longer available.
3.5.3. External Directories #
To back up a directory located outside of the data directory, use the optional -E/--external-dirs option that specifies the path to this directory. If you would like to add more than one external directory, you can provide several paths separated with a colon on Linux systems and semicolon on Windows.
For example, to include /etc/dir1 and /etc/dir2 directories into the full backup of your instance_name instance that will be stored under the backup_dir directory on Linux, run:
pg_probackup3 backup -Bbackup_dir--instance=instance_name-b FULL --external-dirs=/etc/dir1:/etc/dir2
Similarly, to include C:\dir1 and C:\dir2 directories into the full backup on Windows, run:
pg_probackup3 backup -Bbackup_dir--instance=instance_name-b FULL --external-dirs=C:\dir1;C:\dir2
pg_probackup3 recursively copies the contents of each external directory into a separate subdirectory in the backup catalog. Since external directories included into different backups do not have to be the same, when you are restoring the cluster from an incremental backup, only those directories that belong to this particular backup will be restored. Any external directories stored in the previous backups will be ignored.
To include the same directories into each backup of your instance, you can specify them in the pg_probackup3.conf configuration file using the set-config command with the -E/--external-dirs option.
Note
External directories are not supported in BASE server access mode. When using BASE mode, external directories specified via --external-dirs are silently ignored. To include external directories, use DIRECT mode (-s direct).
3.5.4. Partial Backup #
You can backup particular databases using the --db-include-oid and --db-exclude-oid options.
Important
Note the following operation specifics:
Partial backup is currently supported only in DIRECT mode.
The excluded databases must be dropped manually using the
DROP DATABASEcommand.After a partial backup, you can perform a non-partial restore, which will result in an instance with only the included databases.
To back up the specified databases only, run the backup command with the following options:
pg_probackup3 backup -Bbackup_dir--instance=instance_name--db-include-oid=dboid
To exclude databases from backup, use the --db-exclude-oid option:
pg_probackup3 backup -Bbackup_dir--instance=instance_name--db-exclude-oid=dboid
The --db-include-oid and --db-exclude-oid options can be specified multiple times, but cannot be used together. For example, to back up the db1 database with the dboid1 OID and db2 with dboid2, run the following command:
pg_probackup3 backup -Bbackup_dir--instance=instance_name--db-include-oid=dboid1 --db-include-oid=dboid2
To exclude the same databases as in the previous example, run:
pg_probackup3 backup -Bbackup_dir--instance=instance_name--db-exclude-oid=dboid1 --db-exclude-oid=dboid2