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. 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. The absolute minimum required to run (if all defaults are accepted) is the database 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.pl The log section defines logging-related settings. The following log levels are supported:
  • off - No logging at all (not recommended)
  • error - Log only errors
  • warn - Log warnings and errors
  • info - Log info, warnings, and errors
  • debug - Log debug, info, warnings, and errors
  • trace - Log trace (very verbose debugging), debug, info, warnings, and errors
Sets file log level. debug Sets console log level. error
The 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 - 8388608 32768 Enable gzip compression. Backup files are compatible with command-line gzip tools. n Sets the zlib level to be used for file compression when compress=y. 0-9 9 Sets the zlib level to be used for protocol compression when compress=n and the database 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-9 1 Sets 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. n Path to the backrest repository where WAL segments, backups, logs, etc are stored. /data/db/backrest Path to the remote backrest repository where WAL segments, backups, logs, etc are stored. /backup/backrest The 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.com Sets user account on the backup host. backrest Forces 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. y Enable 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. y Defines 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. 5368709120 Defines 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. false Defines 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. 4 Maximum 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. 3600 Checks 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. n Store 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 to a consistent state. y The 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. y Limits the amount of archive log that will be written locally when archive-async=y. After the limit is reached, the following will happen:
  1. will notify Postgres that the archive was successfully backed up, then DROP IT.
  2. An error will be logged to the console and also to the Postgres log.
  3. 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 the database 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.
1024
The 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. n The 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. 2 Number 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. 3 Type 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. diff Number 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. 2 A stanza defines a backup for a specific database. The stanza section must define the base database path and host/user if the database is remote. Also, any global configuration sections can be overridden to define stanza-specific settings. Define the database host. Used for backups where the database host is different from the backup host. db.domain.com Defines 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 cluster owner which is generally postgres, the default. test_user Path to the db data directory (data_directory setting in postgresql.conf). /data/db Port that is running on. This usually does not need to be specified as most clusters run on the default port. 6543 The 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 explicily modified with the unix_socket_directory setting in postgressql.conf. /var/run/postgresql
These options are either global or used by all commands. Perform a database 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 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 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.