is written entirely in Perl. Some additional modules will need to be installed depending on the OS.* Install required Perl modules:
apt-get install libdbd-pg-perl
* Install Perl and required modules:
yum install perl perl-Time-HiRes perl-IO-String perl-parent perl-JSON perl-Digest-SHA perl-DBD-Pg
* Install Perl and required modules:
yum install perl perl-IO-String perl-Thread-Queue perl-JSON-PP perl-Digest-SHA perl-DBD-Pg
can be installed by downloading the most recent release:
https://github.com/pgmasters/backrest/releases
can be installed anywhere but it's best (though not required) to install it in the same location on all systems.* Create the backrest user
The backrest user must be created on the same system and in the same group as the user you will use for testing (which can be any user you prefer). For example:
adduser -g <test-user-group> backrest
* Setup password-less SSH login between the test user and the backrest user
The test user should be able to `ssh backrest@127.0.0.1` and the backrest user should be able to `ssh <testuser>@127.0.0.1` without requiring any passwords. This article (http://archive.oreilly.com/pub/h/66) has details on how to accomplish this. Do the logons both ways at the command line before running regression tests.
* Give group read and execute permissions to ~/backrest/test:
Usually this can be accomplished by running the following as the test user:
chmod 750 ~
* Running regression:
Running the full regression suite is generally not necessary. Run the following first:
./test.pl --module=backup --test=full --db-version=all --thread-max=<# threads>
This will run full backup/restore regression with a variety of options on all installed versions of . If you are only interested in one version then modify the db-version setting to X.X (e.g. 9.4). --thread-max can be omitted if you are running single-threaded.
If there are errors in this test then run full regression to help isolate problems:
./test.pl --db-version=all --thread-max=<# threads>
Report regression test failures at https://github.com/pgmasters/backrest/issues. can be used entirely with command-line parameters but a configuration file is more practical for installations that are complex or set a lot of options. The default location for the configuration file is /etc/pg_backrest.conf.
Each system where is installed should have a repository owned by the user that will be running on that system. Normally this will be the postgres user on a database server and the backrest user on a backup server. See [repo-path](USERGUIDE.md#repo-path-key) for more information on how repositories are used.Modify the following settings in postgresql.conf:
wal_level = archive
archive_mode = on
archive_command = '/path/to/backrest/bin/ --stanza=db archive-push %p'
Replace the path with the actual location where was installed. The stanza parameter should be changed to the actual stanza name for your database cluster.The absolute minimum required to run (if all defaults are accepted) is the database cluster path.
/etc/pg_backrest.conf:
[main]
db-path=/data/db
The db-path option could also be provided on the command line, but it's best to use a configuration file as options tend to pile up quickly.This configuration is appropriate for a small installation where backups are being made locally or to a remote file system that is mounted locally. A number of additional options are set:
db-port - Custom port for .
compress - Disable compression (handy if the file system is already compressed).
repo-path - Path to the repository where backups and WAL archive are stored.
log-level-file - Set the file log level to debug (Lots of extra info if something is not working as expected).
hardlink - Create hardlinks between backups (but never between full backups).
thread-max - Use 2 threads for backup/restore operations.
/etc/pg_backrest.conf:
[global:general]
compress=n
repo-path=/path/to/db/repo
[global:log]
log-level-file=debug
[global:backup]
hardlink=y
thread-max=2
[main]
db-path=/data/db
db-port=5555
This configuration is appropriate for a small installation where backups are being made remotely. Make sure that postgres@db-host has trusted ssh to backrest@backup-host and vice versa. This configuration assumes that you have in the same path on both servers.
/etc/pg_backrest.conf on the db host:
[global:general]
repo-path=/path/to/db/repo
repo-remote-path=/path/to/backup/repo
[global:backup]
backup-host=backup.mydomain.com
backup-user=backrest
[global:archive]
archive-async=y
[main]
db-path=/data/db
/etc/pg_backrest.conf on the backup host:
[global:general]
repo-path=/path/to/backup/repo
[main]
db-host=db.mydomain.com
db-path=/data/db
db-user=postgres
The command section defines the location of external commands that are used by .Defines the location of pg_backrest_remote.pl.
Required only if the path to pg_backrest_remote.pl is different on the local and remote systems. If not defined, the remote path will be assumed to be the same as the local path.same as local/usr/lib/backrest/bin/pg_backrest_remote.plThe log section defines logging-related settings. The following log levels are supported:
Sets file log level.debugSets console log level.errorThe general section defines settings that are shared between multiple operations.Set the buffer size used for copy, compress, and uncompress functions. A maximum of 3 buffers will be in use at a time per thread. An additional maximum of 256K per thread may be used for zlib buffers.16384 - 838860832768Enable gzip compression. Backup files are compatible with command-line gzip tools.nSets the zlib level to be used for file compression when compress=y.0-99Sets the zlib level to be used for protocol compression when compress=n and the database cluster is not on the same host as the backup. Protocol compression is used to reduce network traffic but can be disabled by setting compress-level-network=0. When compress=y the compress-level-network setting is ignored and compress-level is used instead so that the file is only compressed once. SSH compression is always disabled.0-91Sets the umask to 0000 so modes in the repository as created in a sensible way. The default directory mode is 0750 and default file mode is 0640. The lock and log directories set the directory and file mode to 0770 and 0660 respectively.
To use the executing user's umask instead specify neutral-umask=n in the config file or --no-neutral-umask on the command line.nPath to the backrest repository where WAL segments, backups, logs, etc are stored.
The repository serves as both storage and working area for pgBackRest. In a simple installation where the backups are stored locally to the database server there will be only one repository which will contain everything: backups, archives, logs, locks, etc.
If the backups are being done remotely then the backup server's repository will contain backups, archives, locks and logs while the database server's repository will contain only locks and logs. However, if asynchronous archiving is enabled then the database server's repository will also contain a spool directory for archive logs that have not yet been pushed to the remote repository.
Each system where is installed should have a repository directory configured. Storage requirements vary based on usage. The main backup repository will need the most space as it contains both backups and WAL segments for whatever retention you have specified. The database repository only needs significant space if asynchronous archiving is enabled and then it will act as an overflow for WAL segments and might need to be large depending on your database activity.
If you are new to backup then it will be difficult to estimate in advance how much space you'll need. The best thing to do it take some backups then record the size of different types of backups (full/incr/diff) and measure the amount of WAL generated per day. This will give you a general idea of how much space you'll need, though of course requirements will change over time as your database evolves.
/data/db/backrestPath to the remote backrest repository where WAL segments, backups, logs, etc are stored.
The remote repository is relative to the current installation of . On a database server the backup server will be remote and visa versa for the backup server where the database server will be remote. This option is only required if the remote repository is in a different location than the local repository./backup/backrestThe backup section defines settings related to backup.Sets the backup host when backup up remotely via SSH. Make sure that trusted SSH authentication is configured between the db host and the backup host.
When backing up to a locally mounted network filesystem this setting is not required.backup.domain.comSets user account on the backup host.backrestSets the timeout for operations against the database during the backup. This includes the pg_start_backup() and pg_stop_backup() functions which can each take a substantial amount of time. Because of this the timeout should be kept high unless you know that these functions will return quickly (i.e. if you have set startfast=y and you know that the database cluster will not generate many WAL segments during the backup).600Automatically stops a prior failed backup when a new backup is run. This will only be done if an exclusive advisory lock can be acquired to demonstrate that the prior failed backup process has really stopped.
This feature relies on pg_is_in_backup() so only works on >= 9.3.
The setting is disabled by default because it assumes that is the only process doing exclusive online backups. It depends on an advisory lock that only sets so it may abort other processes that do exclusive online backups. Note that base_backup and pg_dump are safe to use with this setting because they do not call pg_start_backup() so are not exclusive.
yForces a checkpoint (by passing true to the fast parameter of pg_start_backup()) so the backup begins immediately. Otherwise the backup will start after the next regular checkpoint.
This feature only works in <= 8.3.yEnable hard-linking of files in differential and incremental backups to their full backups. This gives the appearance that each backup is a full backup. Be careful, though, because modifying files that are hard-linked can affect all the backups in the set.yDefines how often the manifest will be saved during a backup (in bytes). Saving the manifest is important because it stores the checksums and allows the resume function to work efficiently. The actual threshold used is 1% of the backup size or manifest-save-threshold, whichever is greater.5368709120Defines whether the resume feature is enabled. Resume can greatly reduce the amount of time required to run a backup after a previous backup of the same type has failed. It adds complexity, however, so it may be desirable to disable in environments that do not require the feature.falseDefines the number of threads to use for backup or restore. Each thread will perform compression and transfer to make the backup run faster, but don't set thread-max so high that it impacts database performance during backup.4Maximum amount of time (in seconds) that a backup thread should run. This limits the amount of time that a thread might be stuck due to unforeseen issues during the backup. Has no affect when thread-max=1.3600Checks that all WAL segments required to make the backup consistent are present in the WAL archive. It's a good idea to leave this as the default unless you are using another method for archiving.nStore WAL segments required to make the backup consistent in the backup's pg_xlog path. This slightly paranoid option protects against corruption or premature expiration in the WAL segment archive. PITR won't be possible without the WAL segment archive and this option also consumes more space.
Even though WAL segments will be restored with the backup, will ignore them if a recovery.conf file exists and instead use archive_command to fetch WAL segments. Specifying type=none when restoring will not create recovery.conf and force to use the WAL segments in pg_xlog. This will get the database cluster to a consistent state.yThe archive section defines parameters when doing async archiving. This means that the archive files will be stored locally, then a background process will pick them and move them to the backup.Archive WAL segments asynchronously. WAL segments will be copied to the local repo, then a process will be forked to compress the segment and transfer it to the remote repo if configured. Control will be returned to as soon as the WAL segment is copied locally.yLimits the amount of archive log that will be written locally when archive-async=y. After the limit is reached, the following will happen:
will notify Postgres that the archive was successfully backed up, then DROP IT.
An error will be logged to the console and also to the Postgres log.
A stop file will be written in the lock directory and no more archive files will be backed up until it is removed.
If this occurs then the archive log stream will be interrupted and PITR will not be possible past that point. A new backup will be required to regain full restore capability.
The purpose of this feature is to prevent the log volume from filling up at which point Postgres will stop completely. Better to lose the backup than have go down.
To start normal archiving again you'll need to remove the stop file which will be located at ${repo-path}/lock/${stanza}-archive.stop where ${repo-path} is the path set in the general section, and ${stanza} is the backup stanza.1024The restore section defines settings used for restoring backups.Defines whether tablespaces will be be restored into their original (or remapped) locations or stored directly under the pg_tblspc path. Disabling this setting produces compact restores that are convenient for development, staging, etc. Currently these restores cannot be backed up as expects only links in the pg_tblspc path. If no tablespaces are present this this setting has no effect.nThe expire section defines how long backups will be retained. Expiration only occurs when the number of complete backups exceeds the allowed retention. In other words, if full-retention is set to 2, then there must be 3 complete backups before the oldest will be expired. Make sure you always have enough space for retention + 1 backups.Number of full backups to keep. When a full backup expires, all differential and incremental backups associated with the full backup will also expire. When not defined then all full backups will be kept.2Number of differential backups to keep. When a differential backup expires, all incremental backups associated with the differential backup will also expire. When not defined all differential backups will be kept.3Type of backup to use for archive retention (full or differential). If set to full, then will keep archive logs for the number of full backups defined by retention-archive. If set to differential, then will keep archive logs for the number of differential backups defined by retention-archive.
If not defined then archive logs will be kept indefinitely. In general it is not useful to keep archive logs that are older than the oldest backup, but there may be reasons for doing so.diffNumber of backups worth of archive log to keep. If this is set less than your backup retention then be sure you set archive-copy=y or you won't be able to restore some older backups.
For example, if retention-archive=2 and retention-full=4, then any backups older than the most recent two full backups will not have WAL segments in the archive to make them consistent. To solve this, set archive-copy=y and use type=none when restoring. This issue will be addressed in a future release but for now be careful with this setting.2A stanza defines the backup configuration for a specific database cluster. The stanza section must define the database cluster path and host/user if the database cluster is remote. Also, any global configuration sections can be overridden to define stanza-specific settings.Define the database cluster host. Used for backups where the database cluster host is different from the backup host.db.domain.comDefines the logon user when db-host is defined. This user will also own the remote process and will initiate connections to . For this to work correctly the user should be the database cluster owner which is generally postgres, the default.test_userPath to the db data directory (data_directory setting in postgresql.conf)./data/dbPort that is running on. This usually does not need to be specified as most database clusters run on the default port.6543The unix socket directory that was specified when was started. will automatically look in the standard location for your OS so there usually no need to specify this setting unless the socket directory was explicitly modified with the unix_socket_directory setting in postgressql.conf./var/run/postgresqlThese options are either global or used by all commands.Perform a database cluster backup. does not have a built-in scheduler so it's best to run it from cron or some other scheduling mechanism.
/path/to/ --stanza=db --type=full backup
Run a full backup on the db stanza. --type can also be set to incr or diff for incremental or differential backups. However, if no full backup exists then a full backup will be forced even if incr or diff is requested.Archive a WAL segment to the repository.
/path/to/ --stanza=db archive-push %p
Accepts a WAL segment from and archives it in the repository defined by repo-path. %p is how specifies the location of the WAL segment to be archived.Get a WAL segment from the repository.
/path/to/ --stanza=db archive-get %f %p
Retrieves a WAL segment from the repository. This command is used in recovery.conf to restore a backup, perform PITR, or as an alternative to streaming for keeping a replica up to date. %f is how specifies the WAL segment it needs and %p is the location where it should be copied. does backup rotation, but is not concerned with when the backups were created. So if two full backups are configured for retention, will keep two full backups no matter whether they occur, two hours apart or two weeks apart.
/path/to/ --stanza=db expire
Expire (rotate) any backups that exceed the defined retention. Expiration is run automatically after every successful backup, so there is no need to run this command separately unless you have reduced retention, usually to free up some space.Perform a database cluster restore. This command is generally run manually, but there are instances where it might be automated.
/path/to/ --stanza=db --type=name --target=release restore
Restores the latest database cluster backup and then recovers to the release restore point.Retrieve information about backups for a single stanza or for all stanzas. Text output is the default and gives a human-readable summary of backups for the stanza(s) requested. This format is subject to change with any release.
For machine-readable output use --output=json. The JSON output contains far more information than the text output, however this feature is currently experimental so the format may change between versions.
/path/to/ --stanza=db --output=json info
Get information about backups in the db stanza.
/path/to/ --output=json info
Get information about backups for all stanzas in the repository.