Overview of pgBackRest
pgbackrest delivers an innovative, high performance backup and restore solution, which is simple to configure and automate the process of backing up critical PostgreSQL databases.
If you want to learn and implement pgbackrest, you are at the right place.
Few of the main features of using pgbackrest are listed here,
- Parallelism: pgbackrest can be configured to utilize CPU cores for faster backups
- Ease of scheduling: Works with native cron scheduler
- Automatic retention: Configure the number of backups you have and do not worry about scheduling another cron to delete older backups
- Centralized Backup: Have all the backups configured from a single backup server, providing more control for backup and restore process.
- Advanced Options: Use pgbackrest for recovery, as it stores wals files along with the backup file
- Replication: Use pgbackrest to rebuild a replication from the backup destination
- Compression: By default is set to compression level of 3, can be disabled for faster backup without compression if needed
- Types of backups: Full backup, differential backup as well as incremental backup
In this article we would demonstrate a local pgbackrest configuration, where the backup is taken on the same server as the database.
Step 1: Install pgbackrest on a Redhat 7 server
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo yum install pgbackrest
Step 2: Create the backup directory where you want to store the backups
mkdir -p /backup/pgbackrest/local
Step 3: pgbackrest Configuration
vi /etc/pgbackrest.conf
[global]
repo1-path=/backup/pgbackrest/local
repo1-retention-full=2
repo1-retention-diff=2
start-fast=y
delta=y
process-max=2
log-level-console=info
log-level-file=debug
[primary]
pg1-path=/var/lib/pgsql/14/data
Step 4: Archive mode and archive command changes and restart the postgresql service
alter system set archive_mode=on;
alter syste set archive_command='pgbackrest --stanza=primary archive-push %p'
Step 5: pgbackrest commands to create, check
pgbackrest --stanza=primary stanza-create
pgbackrest --stanza=primary check
Step 6: Take a full backup
pgbackrest --stanza=primary --type=full backup
Step 6a: Take a differential backup
pgbackrest --stanza=primary --type=diff backup
Step 6b
pgbackrest info
Step 7: Test the restore
pgbackrest --stanza=primary restore
Step 8: Schedule the backups on cron based on your backup strategy
To book a free consultation Click Here