How to install PgBackRest

Hello today i will tell you how to install PgBackRest

Before reading this article, make sure you have set your ssh settings.
This post was written for PostgreSQL 11 and PgBackRest 2.15

Setup
Master settings
First, let's install pgbackrest with the following command

sudo apt-get install pgbackrest -y
 /etc/pgbackrest.conf let's open it, delete the contents and watch the following


[global]
repo1-host=xxx xxx xx xx
repo1-host-user=postgres
process-max=2
log-level-console=info
log-level-file=debug

[main_stanzamiz]
pg1-path=/var/lib/postgresql/11/main
pg1-port=5432

repo1-host:IP of the backup server

repo1-host-user:The user of your backup server

note: you could also create another user instead of postgres. In our installation, I used postgres because the postgres user came ready and we made the SSH settings accordingly.

pg1-path:postgres cluster permission data folder

You can give any name you want as main_stanzamiz

stanza: configuration that includes the settings of a cluster such as backup, archiving

repo: where the backup will be taken. can be a local or a remote machine

Now, let's tell PostgreSQL to send WAL files to pgbackrest
/etc/postgresql/11/main/postgresql.conf 

archive_mode = on
archive_command = 'pgbackrest --stanza=main_stanzamiz archive-push %p'

systemctl reload [email protected]


sudo apt-get install pgbackrest -y


 /etc/pgbackrest.conf let's open it, delete the contents and watch the following

[global]
repo1-path=/var/lib/pgbackrest
repo1-retention-full=2
repo1-retention-diff=2
process-max=2
log-level-console=info

[main_stanzamiz]
pg1-path=/var/lib/postgresql/11/main/
pg1-host=xxx.xxx.xx.xx
pg1-host-user=postgres
repo1-path: where to save backups on our backup server
repo1-retention-full: limit of full backups, after this number the previous ones are deleted
repo1-retention-diff: diff of the above
pg1-path: data folder of your postgres cluster
pg1-host: postgres cluster IP
pg1-host-user: postgres

Note: pg1-host-user must have read and write permissions to the cluster folder

Now let's create the stanza.
as a postgres user

pgbackrest --stanza=main_stanzamiz check
control with. You should get an output like INFO: check command end: completed successfully (2502ms) on the last line.
Do the same check on the master server

Now let's take our first backup.

Backup is taken from backup/repo server
Restore is done from master server
Since we will take a backup, switch to the backup/repo server.

pgbackrest --stanza=main_stanzamiz backup
pgbackrest will take incremental backup by default. But since we do not have a full backup, it has to create a full backup at the first time.
You can force a full backup with --type=full. You can also choose incr and diff.

 2,199 views last month,  3 views today

About tayfun inam

Computer Engineer -PostgreSql-Oracle Database Administrator I am about Oracle & SQL Server database, Goldengate, Exadata Machine, Oracle Database Appliance administrator with 8+years experience.I have OCA,PostgreSql senior Certificates I have worked 50+ Banking, Insurance, Finance, Telco and etc. clients as a Consultant, Insource or Outsource.I have done 200+ Operations in this clients such as Exadata Installation & PoC & Migration & Upgrade, Oracle & SQL Server Database Upgrade, Oracle RAC Installation, SQL Server AlwaysOn Installation, Database Migration, Disaster Recovery, Backup Restore, Performance Tuning, Periodic Healthchecks.I have done 2000+ Table replication with Goldengate or SQL Server Replication tool for DWH Databases in many clients.

Leave a Reply