[[email protected] data]# yum list pgbackrest*

Loaded plugins: langpacks, ulninfo

Available Packages

pgbackrest.x86_64                                                            2.40-1.rhel7                                                  pgdg-common

pgbackrest-debuginfo.x86_64                                                  2.40-1.rhel7                                                  pgdg-common

[[email protected] data]# yum install pgbackrest.x86_64

 

[[email protected] data]# vi /etc/pgbackrest.conf

     [global]

repo1-path=/var/lib/pgbackrest

 

[pearl]

pg1-path=/var/lib/pgsql/13/data

 

CHECK IF POSTGRES IS RUNNING

 

[[email protected] data]# vi /etc/pgbackrest.conf

[[email protected] data]# ps -ef|grep post

root      1499     1  0 17:00 ?        00:00:00 /usr/libexec/postfix/master -w

postfix   1500  1499  0 17:00 ?        00:00:00 pickup -l -t unix -u

postfix   1501  1499  0 17:00 ?        00:00:00 qmgr -l -t unix -u

postgres  4540     1  0 17:16 ?        00:00:00 /usr/pgsql-13/bin/postmaster -D /var/lib/pgsql/13/data/

 

[[email protected] data]# cd /var/lib/pgsql/13/data

[[email protected] data]# vi postgresql.conf

      wal_level = logical

archive_mode = on

archive_command = ‘pgbackrest –stanza=pearl archive-push %p’

max_wal_sender=6

 

-bash-4.2$ /usr/pgsql-13/bin/pg_ctl -D /var/lib/pgsql/13/data/ restart

 

-bash-4.2$ pgbackrest –stanza=pearl –log-level-console=info stanza-create

2022-09-15 17:32:01.366 P00   INFO: stanza-create command begin 2.40: –exec-id=5650-7a82ffab –log-level-console=info –pg1-path=/var/lib/pgsql/13/data –repo1-path=/var/lib/pgbackrest –stanza=pearl

2022-09-15 17:32:01.976 P00   INFO: stanza-create for stanza ‘pearl’ on repo1

2022-09-15 17:32:02.070 P00   INFO: stanza-create command end: completed successfully (705ms)

 

-bash-4.2$ pgbackrest –stanza=pearl –log-level-console=info check

2022-09-15 17:33:38.647 P00   INFO: check command begin 2.40: –exec-id=5749-7129dc7a –log-level-console=info –pg1-path=/var/lib/pgsql/13/data –repo1-path=/var/lib/pgbackrest –stanza=pearl

2022-09-15 17:33:39.256 P00   INFO: check repo1 configuration (primary)

2022-09-15 17:33:39.468 P00   INFO: check repo1 archive for WAL (primary)

2022-09-15 17:33:39.881 P00   INFO: WAL segment 000000010000000000000001 successfully archived to ‘/var/lib/pgbackrest/archive/pearl/13-1/0000000100000000/000000010000000000000001-90c3cfb00f3cdb504985c93f1010b10c72e12e61.gz’ on repo1

2022-09-15 17:33:39.881 P00   INFO: check command end: completed successfully (1235ms)

 

-bash-4.2$ pgbackrest –stanza=pearl –type=full –log-level-stderr=info backup

INFO: backup command begin 2.40: –exec-id=5876-5b294bf5 –log-level-stderr=info –pg1-path=/var/lib/pgsql/13/data –repo1-path=/var/lib/pgbackrest –stanza=pearl –type=full

WARN: option ‘repo1-retention-full’ is not set for ‘repo1-retention-full-type=count’, the repository may run out of space

      HINT: to retain full backups indefinitely (without warning), set option ‘repo1-retention-full’ to the maximum.

INFO: execute non-exclusive pg_start_backup(): backup begins after the next regular checkpoint completes

INFO: backup start archive = 000000010000000000000003, lsn = 0/3000060

INFO: check archive for prior segment 000000010000000000000002

INFO: execute non-exclusive pg_stop_backup() and wait for all WAL segments to archive

INFO: backup stop archive = 000000010000000000000003, lsn = 0/3000138

INFO: check archive for segment(s) 000000010000000000000003:000000010000000000000003

INFO: new backup label = 20220915-173551F

INFO: full backup size = 23.9MB, file total = 936

INFO: backup command end: completed successfully (7565ms)

INFO: expire command begin 2.40: –exec-id=5876-5b294bf5 –log-level-stderr=info –repo1-path=/var/lib/pgbackrest –stanza=pearl

INFO: option ‘repo1-retention-archive’ is not set – archive logs will not be expired

INFO: expire command end: completed successfully (21ms)

 

[[email protected] ~]# vi /etc/pgbackrest.conf

   [global]

repo1-path=/var/lib/pgbackrest

 

[pearl]

pg1-path=/var/lib/pgsql/13/restore

 

Before restoring check if the “restore” directory is available in the path “pg1-path=/var/lib/pgsql/13/restore”.

If not available we need to create 

[[email protected] ~]# mkdir /var/lib/pgsql/13/restore

[[email protected] ~]# chmod 700 /var/lib/pgsql/13/restore

[[email protected] ~]# chown -R postgres. /var/lib/pgsql/13/restore

 

-bash-4.2$ pgbackrest –stanza=pearl –log-level-stderr=info restore

Now we can change the port number in the restored cluster and run it as a new cluster

-bash-4.2$ vi postgresql.conf

           Port=5434

-bash-4.2$ /usr/pgsql-13/bin/pg_ctl -D /var/lib/pgsql/13/restore/ start

waiting for server to start….2022-09-15 17:48:53.243 IST [6735] LOG:  redirecting log output to logging collector process

2022-09-15 17:48:53.243 IST [6735] HINT:  Future log output will appear in directory “log”.

 done

server started

-bash-4.2$ psql -p 5434

psql (13.8)

Type “help” for help.

postgres=# show port;

 port 

——

 5434

(1 row)