sudo -u postgres perl -V | grep USE_64_BIT_INT
USE_64_BIT_ALL USE_64_BIT_INT USE_ITHREADS
sudo rm -f /usr/bin/pgbackrest
sudo rm -f /usr/bin/pg_backrest
sudo rm -rf /usr/lib/perl5/BackRest
sudo rm -rf /usr/share/perl5/BackRest
sudo rm -rf /usr/lib/perl5/pgBackRest
sudo rm -rf /usr/share/perl5/pgBackRest
sudo apt-get install libdbd-pg-perl libio-socket-ssl-perl libxml-libxml-perl
sudo wget -q -O - \ https://github.com/pgbackrest/pgbackrest/archive/release/1.29.tar.gz | \ sudo tar zx -C /root
sudo cp -r /root/pgbackrest-release-1.29/lib/pgBackRest \ /usr/share/perl5
sudo find /usr/share/perl5/pgBackRest -type f -exec chmod 644 {} +
sudo find /usr/share/perl5/pgBackRest -type d -exec chmod 755 {} +
sudo cp /root/pgbackrest-release-1.29/bin/pgbackrest /usr/bin/pgbackrest
sudo chmod 755 /usr/bin/pgbackrest
sudo mkdir -m 770 /var/log/pgbackrest
sudo chown postgres:postgres /var/log/pgbackrest
sudo touch /etc/pgbackrest.conf
sudo chmod 640 /etc/pgbackrest.conf
sudo chown postgres:postgres /etc/pgbackrest.conf
sudo sh -c 'cd /root/pgbackrest-release-1.29/libc && \ perl Makefile.PL INSTALLMAN1DIR=none INSTALLMAN3DIR=none'
sudo make -C /root/pgbackrest-release-1.29/libc test
sudo make -C /root/pgbackrest-release-1.29/libc install
sudo -u postgres pgbackrest
pgBackRest 1.29 - General help Usage: pgbackrest [options] [command] Commands: archive-get Get a WAL segment from the archive. archive-push Push a WAL segment to the archive. backup Backup a database cluster. check Check the configuration. expire Expire backups that exceed retention. help Get help. info Retrieve information about backups. restore Restore a database cluster. stanza-create Create the required stanza data. stanza-delete Delete a stanza. stanza-upgrade Upgrade a stanza. start Allow pgBackRest processes to run. stop Stop pgBackRest processes from running. version Get version. Use 'pgbackrest help [command]' for more information.
sudo -u postgres /usr/lib/postgresql/9.4/bin/initdb \ -D /var/lib/postgresql/9.4/demo -k -A peer
sudo pg_createcluster 9.4 demo
Configuring already existing cluster (configuration: /etc/postgresql/9.4/demo, data: /var/lib/postgresql/9.4/demo, owner: 5000:5000) Ver Cluster Port Status Owner Data directory Log file 9.4 demo 5432 down postgres /var/lib/postgresql/9.4/demo /var/log/postgresql/postgresql-9.4-demo.log
sudo mkdir /var/lib/pgbackrest
sudo chmod 750 /var/lib/pgbackrest
sudo chown postgres:postgres /var/lib/pgbackrest
sudo pg_ctlcluster 9.4 demo restart
sudo -u postgres pgbackrest --stanza=demo --log-level-console=info stanza-create
P00 INFO: stanza-create command begin 1.29: --db1-path=/var/lib/postgresql/9.4/demo --log-level-console=info --log-level-stderr=off --no-log-timestamp --repo-cipher-pass=--repo-cipher-type=aes-256-cbc --repo-path=/var/lib/pgbackrest --stanza=demo
P00 INFO: stanza-create command end: completed successfully
sudo -u postgres pgbackrest --stanza=demo --log-level-console=info check
P00 INFO: check command begin 1.29: --db1-path=/var/lib/postgresql/9.4/demo --log-level-console=info --log-level-stderr=off --no-log-timestamp --repo-cipher-pass=--repo-cipher-type=aes-256-cbc --repo-path=/var/lib/pgbackrest --stanza=demo
P00 INFO: WAL segment 000000010000000000000001 successfully stored in the archive at '/var/lib/pgbackrest/archive/demo/9.4-1/0000000100000000/000000010000000000000001-a2cb0209004f0a7872bdf06c8515baf435beb1ab.gz'
P00 INFO: check command end: completed successfully
sudo -u postgres pgbackrest --stanza=demo \ --log-level-console=info backup
P00 INFO: backup command begin 1.29: --db1-path=/var/lib/postgresql/9.4/demo --log-level-console=info --log-level-stderr=off --no-log-timestamp --repo-cipher-pass=--repo-cipher-type=aes-256-cbc --repo-path=/var/lib/pgbackrest --retention-full=2 --stanza=demo
P00 WARN: no prior backup exists, incr backup has been changed to full
P00 INFO: execute exclusive pg_start_backup() with label "pgBackRest backup started at 2018-07-05 22:15:23": backup begins after the next regular checkpoint completes P00 INFO: backup start archive = 000000010000000000000002, lsn = 0/2000028 [filtered 754 lines of output] P01 INFO: backup file /var/lib/postgresql/9.4/demo/base/1/11895 (0B, 100%) P01 INFO: backup file /var/lib/postgresql/9.4/demo/base/1/11885 (0B, 100%)
P00 INFO: full backup size = 19.2MB
P00 INFO: execute exclusive pg_stop_backup() and wait for all WAL segments to archive P00 INFO: backup stop archive = 000000010000000000000002, lsn = 0/2000128 [filtered 4 lines of output]
sudo -u postgres pgbackrest --stanza=demo --type=diff \ --log-level-console=info backup
[filtered 4 lines of output] P01 INFO: backup file /var/lib/postgresql/9.4/demo/global/pg_control (8KB, 97%) checksum a2b990954b573ece4f51abf6fc7078d7c115cd47 P01 INFO: backup file /var/lib/postgresql/9.4/demo/backup_label (236B, 100%) checksum b619ed4bdc754eef7642fae8ecae479b6581a060
P00 INFO: diff backup size = 8.2KB
P00 INFO: execute exclusive pg_stop_backup() and wait for all WAL segments to archive P00 INFO: backup stop archive = 000000010000000000000003, lsn = 0/30000F0 [filtered 4 lines of output]
#m h dom mon dow command 30 06 * * 0 pgbackrest --type=full --stanza=demo backup 30 06 * * 1-6 pgbackrest --type=diff --stanza=demo backup
sudo -u postgres pgbackrest info
stanza: demo status: ok db (current) wal archive min/max (9.4-1): 000000010000000000000002 / 000000010000000000000003
full backup: 20180705-221523F
timestamp start/stop: 2018-07-05 22:15:23 / 2018-07-05 22:15:34 wal start/stop: 000000010000000000000002 / 000000010000000000000002 database size: 19.2MB, backup size: 19.2MB repository size: 2.2MB, repository backup size: 2.2MB
diff backup: 20180705-221523F_20180705-221534D
timestamp start/stop: 2018-07-05 22:15:34 / 2018-07-05 22:15:37 wal start/stop: 000000010000000000000003 / 000000010000000000000003 database size: 19.2MB, backup size: 8.2KB repository size: 2.2MB, repository backup size: 400B backup reference list: 20180705-221523F
sudo pg_ctlcluster 9.4 demo stop
sudo -u postgres rm /var/lib/postgresql/9.4/demo/global/pg_control
sudo pg_ctlcluster 9.4 demo start
The PostgreSQL server failed to start. Please check the log output:
postgres: could not find the database system
Expected to find it in the directory "/var/lib/postgresql/9.4/demo", but could not open file "/var/lib/postgresql/9.4/demo/global/pg_control": No such file or directory
sudo -u postgres find /var/lib/postgresql/9.4/demo -mindepth 1 -delete
sudo -u postgres pgbackrest --stanza=demo restore
sudo pg_ctlcluster 9.4 demo start
sudo -u postgres pgbackrest --stanza=demo --type=incr \ --log-level-console=info backup
P00 INFO: backup command begin 1.29: --db1-path=/var/lib/postgresql/9.4/demo --log-level-console=info --log-level-stderr=off --no-log-timestamp --repo-cipher-pass=--repo-cipher-type=aes-256-cbc --repo-path=/var/lib/pgbackrest --retention-full=2 --stanza=demo --type=incr P00 INFO: last backup label = 20180705-221523F_20180705-221534D, version = 1.29
P00 INFO: execute exclusive pg_start_backup() with label "pgBackRest backup started at 2018-07-05 22:15:56": backup begins after the next regular checkpoint completes
P00 INFO: backup start archive = 000000020000000000000005, lsn = 0/5000028 P01 INFO: backup file /var/lib/postgresql/9.4/demo/pg_multixact/offsets/0000 (8KB, 33%) checksum 0631457264ff7f8d5fb1edc2c0211992a67c73e6 [filtered 10 lines of output]
sudo -u postgres pgbackrest --stanza=demo --type=incr \ --log-level-console=info backup
P00 INFO: backup command begin 1.29: --db1-path=/var/lib/postgresql/9.4/demo --log-level-console=info --log-level-stderr=off --no-log-timestamp --repo-cipher-pass=--repo-cipher-type=aes-256-cbc --repo-path=/var/lib/pgbackrest --retention-full=2 --stanza=demo --start-fast --type=incr P00 INFO: last backup label = 20180705-221523F_20180705-221556I, version = 1.29
P00 INFO: execute exclusive pg_start_backup() with label "pgBackRest backup started at 2018-07-05 22:16:00": backup begins after the requested immediate checkpoint completes
P00 INFO: backup start archive = 000000020000000000000006, lsn = 0/6000028 P01 INFO: backup file /var/lib/postgresql/9.4/demo/global/pg_control (8KB, 97%) checksum 7df60ef9b13f809b2b0548c6508da704b7d4dcb7 [filtered 8 lines of output]
sudo chmod 550 /var/lib/pgbackrest/backup/demo/
sudo -u postgres pgbackrest --stanza=demo --type=incr \ --log-level-console=info backup
[filtered 2 lines of output] P00 INFO: execute exclusive pg_start_backup() with label "pgBackRest backup started at 2018-07-05 22:16:04": backup begins after the requested immediate checkpoint completes P00 INFO: backup start archive = 000000020000000000000007, lsn = 0/7000028
P00 ERROR: [047]: unable to create path '/var/lib/pgbackrest/backup/demo/20180705-221523F_20180705-221604I': Permission denied
P00 INFO: backup command end: aborted with exception [047]
sudo chmod 750 /var/lib/pgbackrest/backup/demo/
sudo -u postgres pgbackrest --stanza=demo --type=incr \ --log-level-console=info backup
P00 INFO: backup command begin 1.29: --db1-path=/var/lib/postgresql/9.4/demo --log-level-console=info --log-level-stderr=off --no-log-timestamp --repo-cipher-pass=--repo-cipher-type=aes-256-cbc --repo-path=/var/lib/pgbackrest --retention-full=2 --stanza=demo --start-fast --type=incr P00 INFO: last backup label = 20180705-221523F_20180705-221600I, version = 1.29 P00 INFO: execute exclusive pg_start_backup() with label "pgBackRest backup started at 2018-07-05 22:16:06": backup begins after the requested immediate checkpoint completes
P00 ERROR: [057]: ERROR: a backup is already in progress
HINT: Run pg_stop_backup() and try again.: select to_char(current_timestamp, 'YYYY-MM-DD HH24:MI:SS.US TZ'), pg_xlogfile_name(lsn), lsn::text from pg_start_backup('pgBackRest backup started at 2018-07-05 22:16:06', true) as lsn
sudo -u postgres pgbackrest --stanza=demo --type=incr \ --log-level-console=info backup
P00 INFO: backup command begin 1.29: --db1-path=/var/lib/postgresql/9.4/demo --log-level-console=info --log-level-stderr=off --no-log-timestamp --repo-cipher-pass=--repo-cipher-type=aes-256-cbc --repo-path=/var/lib/pgbackrest --retention-full=2 --stanza=demo --start-fast --stop-auto --type=incr P00 INFO: last backup label = 20180705-221523F_20180705-221600I, version = 1.29
P00 WARN: the cluster is already in backup mode but no pgBackRest backup process is running. pg_stop_backup() will be called so a new backup can be started.
P00 INFO: execute exclusive pg_stop_backup() and wait for all WAL segments to archive
P00 INFO: execute exclusive pg_start_backup() with label "pgBackRest backup started at 2018-07-05 22:16:08": backup begins after the requested immediate checkpoint completes
P00 INFO: backup start archive = 000000020000000000000008, lsn = 0/8000028 P01 INFO: backup file /var/lib/postgresql/9.4/demo/global/pg_control (8KB, 97%) checksum 390ede54c87382c2138b9af6bdaa0d1a00aa009a [filtered 8 lines of output]
sudo -u postgres pgbackrest --stanza=demo --type=full \ --log-level-console=detail backup
[filtered 763 lines of output] P00 INFO: backup command end: completed successfully P00 INFO: expire command begin 1.29: --log-level-console=detail --log-level-stderr=off --no-log-timestamp --repo-cipher-pass=--repo-cipher-type=aes-256-cbc --repo-path=/var/lib/pgbackrest --retention-archive=2 --retention-full=2 --stanza=demo
P00 DETAIL: archive retention on backup 20180705-221523F, archiveId = 9.4-1, start = 000000010000000000000002
P00 DETAIL: no archive to remove, archiveId = 9.4-1 P00 INFO: expire command end: completed successfully
sudo -u postgres pgbackrest --stanza=demo --type=full \ --log-level-console=info backup
[filtered 763 lines of output] P00 INFO: backup command end: completed successfully P00 INFO: expire command begin 1.29: --log-level-console=info --log-level-stderr=off --no-log-timestamp --repo-cipher-pass=--repo-cipher-type=aes-256-cbc --repo-path=/var/lib/pgbackrest --retention-archive=2 --retention-full=2 --stanza=demo
P00 INFO: expire full backup set: 20180705-221523F, 20180705-221523F_20180705-221534D, 20180705-221523F_20180705-221556I, 20180705-221523F_20180705-221600I, 20180705-221523F_20180705-221608I
P00 INFO: remove expired backup 20180705-221523F_20180705-221608I P00 INFO: remove expired backup 20180705-221523F_20180705-221600I [filtered 3 lines of output]
rollingset of differentials for the last day or more. This allows quick restores to recent points-in-time but reduces overall space consumption.
sudo -u postgres pgbackrest --stanza=demo --type=diff backup
sudo -u postgres pgbackrest --stanza=demo --type=incr backup
sudo -u postgres pgbackrest --stanza=demo --type=diff \ --log-level-console=info backup
[filtered 10 lines of output] P00 INFO: backup command end: completed successfully P00 INFO: expire command begin 1.29: --log-level-console=info --log-level-stderr=off --no-log-timestamp --repo-cipher-pass=--repo-cipher-type=aes-256-cbc --repo-path=/var/lib/pgbackrest --retention-archive=2 --retention-diff=1 --retention-full=2 --stanza=demo
P00 INFO: expire diff backup set: 20180705-221626F_20180705-221638D, 20180705-221626F_20180705-221643I
P00 INFO: remove expired backup 20180705-221626F_20180705-221643I P00 INFO: remove expired backup 20180705-221626F_20180705-221638D
sudo -u postgres pgbackrest --stanza=demo --type=diff \ --log-level-console=info backup
[filtered 7 lines of output] P00 INFO: execute exclusive pg_stop_backup() and wait for all WAL segments to archive P00 INFO: backup stop archive = 000000020000000000000011, lsn = 0/110000F0
P00 INFO: new backup label = 20180705-221626F_20180705-221652D
P00 INFO: backup command end: completed successfully P00 INFO: expire command begin 1.29: --log-level-console=info --log-level-stderr=off --no-log-timestamp --repo-cipher-pass=--repo-cipher-type=aes-256-cbc --repo-path=/var/lib/pgbackrest --retention-archive=2 --retention-diff=2 --retention-full=2 --stanza=demo
sudo -u postgres pgbackrest --stanza=demo --log-level-console=detail \ --retention-archive-type=diff --retention-archive=1 expire
P00 INFO: expire command begin 1.29: --log-level-console=detail --log-level-stderr=off --no-log-timestamp --repo-cipher-pass=--repo-cipher-type=aes-256-cbc --repo-path=/var/lib/pgbackrest --retention-archive=1 --retention-archive-type=diff --retention-diff=2 --retention-full=2 --stanza=demo P00 DETAIL: archive retention on backup 20180705-221614F, archiveId = 9.4-1, start = 000000020000000000000009, stop = 000000020000000000000009 P00 DETAIL: archive retention on backup 20180705-221626F, archiveId = 9.4-1, start = 00000002000000000000000A, stop = 00000002000000000000000A
P00 DETAIL: archive retention on backup 20180705-221626F_20180705-221646D, archiveId = 9.4-1, start = 00000002000000000000000D, stop = 00000002000000000000000D
P00 DETAIL: archive retention on backup 20180705-221626F_20180705-221652D, archiveId = 9.4-1, start = 000000020000000000000011
P00 DETAIL: remove archive: archiveId = 9.4-1, start = 00000002000000000000000B, stop = 00000002000000000000000C P00 DETAIL: remove archive: archiveId = 9.4-1, start = 00000002000000000000000E, stop = 000000020000000000000010
P00 INFO: expire command end: completed successfully
sudo pg_ctlcluster 9.4 demo stop
sudo -u postgres pgbackrest --stanza=demo --delta \ --log-level-console=detail restore
[filtered 692 lines of output] P01 DETAIL: restore file /var/lib/postgresql/9.4/demo/base/12134/PG_VERSION - exists and matches backup (4B, 99%) checksum 8dbabb96e032b8d9f1993c0e4b9141e71ade01a1 P01 DETAIL: restore file /var/lib/postgresql/9.4/demo/base/1/PG_VERSION - exists and matches backup (4B, 99%) checksum 8dbabb96e032b8d9f1993c0e4b9141e71ade01a1
P01 DETAIL: restore file /var/lib/postgresql/9.4/demo/PG_VERSION - exists and matches backup (4B, 100%) checksum 8dbabb96e032b8d9f1993c0e4b9141e71ade01a1
P01 DETAIL: restore file /var/lib/postgresql/9.4/demo/global/12086 - exists and is zero size (0B, 100%) P01 DETAIL: restore file /var/lib/postgresql/9.4/demo/global/12038 - exists and is zero size (0B, 100%) [filtered 83 lines of output] P01 DETAIL: restore file /var/lib/postgresql/9.4/demo/base/1/11885 - exists and is zero size (0B, 100%) P00 INFO: write /var/lib/postgresql/9.4/demo/recovery.conf
P00 INFO: restore global/pg_control (performed last to ensure aborted restores cannot be started)
P00 INFO: restore command end: completed successfully
sudo pg_ctlcluster 9.4 demo start
sudo -u postgres psql -c "create database test1;"
CREATE DATABASE
sudo -u postgres psql -c "create database test2;"
CREATE DATABASE
sudo -u postgres pgbackrest --stanza=demo --type=incr backup
sudo -u postgres psql -c "create table test1_table (id int); \ insert into test1_table (id) values (1);" test1
INSERT 0 1
sudo -u postgres psql -c "create table test2_table (id int); \ insert into test2_table (id) values (2);" test2
INSERT 0 1
sudo -u postgres du -sh /var/lib/postgresql/9.4/demo/base/16384
6.4M /var/lib/postgresql/9.4/demo/base/16384
sudo pg_ctlcluster 9.4 demo stop
sudo -u postgres pgbackrest --stanza=demo --delta \ --db-include=test2 restore
sudo pg_ctlcluster 9.4 demo start
sudo -u postgres psql -c "select * from test2_table;" test2
id ---- 2 (1 row)
sudo -u postgres psql -c "select * from test1_table;" test1
psql: FATAL: relation mapping file "base/16384/pg_filenode.map" contains invalid data
sudo -u postgres du -sh /var/lib/postgresql/9.4/demo/base/16384
152K /var/lib/postgresql/9.4/demo/base/16384
sudo -u postgres psql -c "drop database test1;"
DROP DATABASE
sudo -u postgres psql -c "select oid, datname from pg_database order by oid;"
oid | datname -------+----------- 1 | template1 12134 | template0 12139 | postgres
16385 | test2
(4 rows)
sudo -u postgres pgbackrest --stanza=demo --type=diff backup
sudo -u postgres psql -c "begin; \ create table important_table (message text); \ insert into important_table values ('Important Data'); \ commit; \ select * from important_table;"
message ----------------
Important Data
(1 row)
sudo -u postgres psql -Atc "select current_timestamp"
2018-07-05 22:17:32.812092+00
sudo -u postgres psql -c "begin; \ drop table important_table; \ commit; \ select * from important_table;"
ERROR: relation "important_table" does not exist
LINE 1: ...le important_table; commit; select * from important_... ^
sudo pg_ctlcluster 9.4 demo stop
sudo -u postgres pgbackrest --stanza=demo --delta \ --type=time "--target=2018-07-05 22:17:32.812092+00" restore
sudo -u postgres cat /var/lib/postgresql/9.4/demo/recovery.conf
restore_command = '/usr/bin/pgbackrest --stanza=demo archive-get %f "%p"'
recovery_target_time = '2018-07-05 22:17:32.812092+00'
sudo pg_ctlcluster 9.4 demo start
sudo -u postgres psql -c "select * from important_table"
message ----------------
Important Data
(1 row)
sudo -u postgres cat /var/log/postgresql/postgresql-9.4-demo.log
LOG: database system was interrupted; last known up at 2018-07-05 22:17:26 UTC
LOG: starting point-in-time recovery to 2018-07-05 22:17:32.812092+00
LOG: restored log file "00000004.history" from archive LOG: restored log file "000000040000000000000016" from archive [filtered 2 lines of output] LOG: incomplete startup packet LOG: restored log file "000000040000000000000017" from archive
LOG: recovery stopping before commit of transaction 686, time 2018-07-05 22:17:33.066969+00
LOG: redo done at 0/170157F0
LOG: last completed transaction was at log time 2018-07-05 22:17:32.510815+00
LOG: selected new timeline ID: 5 LOG: restored log file "00000004.history" from archive [filtered 5 lines of output]
sudo -u postgres psql -c "begin; \ drop table important_table; \ commit; \ select * from important_table;"
ERROR: relation "important_table" does not exist
LINE 1: ...le important_table; commit; select * from important_... ^
sudo -u postgres pgbackrest --stanza=demo --type=incr backup
sudo pg_ctlcluster 9.4 demo stop
sudo -u postgres pgbackrest --stanza=demo --delta \ --type=time "--target=2018-07-05 22:17:32.812092+00" restore
sudo pg_ctlcluster 9.4 demo start
sudo -u postgres psql -c "select * from important_table"
ERROR: relation "important_table" does not exist
LINE 1: select * from important_table ^
recovery stopping before...and
last completed transaction...log messages. If they are not present then the recovery to the specified point-in-time was not successful.
sudo -u postgres cat /var/log/postgresql/postgresql-9.4-demo.log
LOG: database system was interrupted; last known up at 2018-07-05 22:17:45 UTC
LOG: starting point-in-time recovery to 2018-07-05 22:17:32.812092+00
LOG: restored log file "00000005.history" from archive LOG: restored log file "000000050000000000000018" from archive LOG: redo starts at 0/18000028
LOG: consistent recovery state reached at 0/180000F0
LOG: incomplete startup packet FATAL: the database system is starting up [filtered 11 lines of output]
sudo -u postgres pgbackrest info
stanza: demo status: ok db (current) wal archive min/max (9.4-1): 000000020000000000000009 / 000000050000000000000018 full backup: 20180705-221614F timestamp start/stop: 2018-07-05 22:16:14 / 2018-07-05 22:16:26 wal start/stop: 000000020000000000000009 / 000000020000000000000009 database size: 19.2MB, backup size: 19.2MB repository size: 2.2MB, repository backup size: 2.2MB full backup: 20180705-221626F timestamp start/stop: 2018-07-05 22:16:26 / 2018-07-05 22:16:37 wal start/stop: 00000002000000000000000A / 00000002000000000000000A database size: 19.2MB, backup size: 19.2MB repository size: 2.2MB, repository backup size: 2.2MB diff backup: 20180705-221626F_20180705-221652D timestamp start/stop: 2018-07-05 22:16:52 / 2018-07-05 22:16:55 wal start/stop: 000000020000000000000011 / 000000020000000000000011 database size: 19.2MB, backup size: 8.2KB repository size: 2.2MB, repository backup size: 400B backup reference list: 20180705-221626F incr backup: 20180705-221626F_20180705-221705I timestamp start/stop: 2018-07-05 22:17:05 / 2018-07-05 22:17:14 wal start/stop: 000000030000000000000013 / 000000030000000000000013 database size: 31.7MB, backup size: 12.5MB repository size: 3.7MB, repository backup size: 1.5MB backup reference list: 20180705-221626F
diff backup: 20180705-221626F_20180705-221725D
timestamp start/stop: 2018-07-05 22:17:25 / 2018-07-05 22:17:32 wal start/stop: 000000040000000000000016 / 000000040000000000000016 database size: 25.5MB, backup size: 6.3MB repository size: 3MB, repository backup size: 771.6KB backup reference list: 20180705-221626F incr backup: 20180705-221626F_20180705-221743I timestamp start/stop: 2018-07-05 22:17:43 / 2018-07-05 22:17:47 wal start/stop: 000000050000000000000018 / 000000050000000000000018 database size: 25.5MB, backup size: 1.7MB repository size: 3MB, repository backup size: 200.8KB
backup reference list: 20180705-221626F, 20180705-221626F_20180705-221725D
sudo pg_ctlcluster 9.4 demo stop
sudo -u postgres pgbackrest --stanza=demo --delta \ --type=time "--target=2018-07-05 22:17:32.812092+00" \ --set=20180705-221626F_20180705-221725D restore
sudo pg_ctlcluster 9.4 demo start
sudo -u postgres psql -c "select * from important_table"
message ----------------
Important Data
(1 row)
recovery stopping before...and
last completed transaction...messages showing that the recovery was successful.
sudo -u postgres cat /var/log/postgresql/postgresql-9.4-demo.log
LOG: database system was interrupted; last known up at 2018-07-05 22:17:26 UTC
LOG: starting point-in-time recovery to 2018-07-05 22:17:32.812092+00
LOG: restored log file "00000004.history" from archive LOG: restored log file "000000040000000000000016" from archive [filtered 2 lines of output] LOG: incomplete startup packet LOG: restored log file "000000040000000000000017" from archive
LOG: recovery stopping before commit of transaction 686, time 2018-07-05 22:17:33.066969+00
LOG: redo done at 0/170157F0
LOG: last completed transaction was at log time 2018-07-05 22:17:32.510815+00
LOG: restored log file "00000005.history" from archive LOG: restored log file "00000006.history" from archive [filtered 7 lines of output]
sudo -u postgres pgbackrest --stanza=demo --log-level-console=info stanza-create
P00 INFO: stanza-create command begin 1.29: --db1-path=/var/lib/postgresql/9.4/demo --log-level-console=info --log-level-stderr=off --no-log-timestamp --repo-cipher-type=none --repo-path=/ --repo-s3-bucket=demo-bucket --repo-s3-endpoint=s3.amazonaws.com --repo-s3-key=--repo-s3-key-secret= --repo-s3-region=us-east-1 --no-repo-s3-verify-ssl --repo-type=s3 --stanza=demo
P00 INFO: stanza-create command end: completed successfully
sudo -u postgres pgbackrest --stanza=demo \ --log-level-console=info backup
P00 INFO: backup command begin 1.29: --db1-path=/var/lib/postgresql/9.4/demo --log-level-console=info --log-level-stderr=off --no-log-timestamp --process-max=4 --repo-cipher-type=none --repo-path=/ --repo-s3-bucket=demo-bucket --repo-s3-endpoint=s3.amazonaws.com --repo-s3-key=--repo-s3-key-secret= --repo-s3-region=us-east-1 --no-repo-s3-verify-ssl --repo-type=s3 --retention-diff=2 --retention-full=2 --stanza=demo --start-fast --stop-auto
P00 WARN: no prior backup exists, incr backup has been changed to full
P00 INFO: execute exclusive pg_start_backup() with label "pgBackRest backup started at 2018-07-05 22:18:11": backup begins after the requested immediate checkpoint completes P00 INFO: backup start archive = 000000070000000000000018, lsn = 0/18000028 [filtered 995 lines of output] P02 INFO: backup file /var/lib/postgresql/9.4/demo/base/1/11895 (0B, 100%) P01 INFO: backup file /var/lib/postgresql/9.4/demo/base/1/11885 (0B, 100%)
P00 INFO: full backup size = 25.5MB
P00 INFO: execute exclusive pg_stop_backup() and wait for all WAL segments to archive P00 INFO: backup stop archive = 000000070000000000000018, lsn = 0/18000128 [filtered 4 lines of output]
sudo pg_ctlcluster 9.4 demo stop
sudo -u postgres pgbackrest --stanza=demo --log-level-console=info stop
P00 INFO: stop command begin 1.29: --log-level-console=info --log-level-stderr=off --no-log-timestamp --repo-cipher-type=none --repo-path=/ --repo-s3-bucket=demo-bucket --repo-s3-endpoint=s3.amazonaws.com --repo-s3-key=--repo-s3-key-secret= --repo-s3-region=us-east-1 --no-repo-s3-verify-ssl --repo-type=s3 --stanza=demo
P00 INFO: stop command end: completed successfully
sudo -u postgres pgbackrest --stanza=demo --log-level-console=info stanza-delete
P00 INFO: stanza-delete command begin 1.29: --db1-path=/var/lib/postgresql/9.4/demo --log-level-console=info --log-level-stderr=off --no-log-timestamp --repo-cipher-type=none --repo-path=/ --repo-s3-bucket=demo-bucket --repo-s3-endpoint=s3.amazonaws.com --repo-s3-key=--repo-s3-key-secret= --repo-s3-region=us-east-1 --no-repo-s3-verify-ssl --repo-type=s3 --stanza=demo
P00 INFO: stanza-delete command end: completed successfully
sudo adduser --disabled-password --gecos "" backrest
sudo apt-get install libdbd-pg-perl libio-socket-ssl-perl libxml-libxml-perl
sudo wget -q -O - \ https://github.com/pgbackrest/pgbackrest/archive/release/1.29.tar.gz | \ sudo tar zx -C /root
sudo cp -r /root/pgbackrest-release-1.29/lib/pgBackRest \ /usr/share/perl5
sudo find /usr/share/perl5/pgBackRest -type f -exec chmod 644 {} +
sudo find /usr/share/perl5/pgBackRest -type d -exec chmod 755 {} +
sudo cp /root/pgbackrest-release-1.29/bin/pgbackrest /usr/bin/pgbackrest
sudo chmod 755 /usr/bin/pgbackrest
sudo mkdir -m 770 /var/log/pgbackrest
sudo chown backrest:backrest /var/log/pgbackrest
sudo touch /etc/pgbackrest.conf
sudo chmod 640 /etc/pgbackrest.conf
sudo chown backrest:backrest /etc/pgbackrest.conf
sudo sh -c 'cd /root/pgbackrest-release-1.29/libc && \ perl Makefile.PL INSTALLMAN1DIR=none INSTALLMAN3DIR=none'
sudo make -C /root/pgbackrest-release-1.29/libc test
sudo make -C /root/pgbackrest-release-1.29/libc install
sudo mkdir /var/lib/pgbackrest
sudo chmod 750 /var/lib/pgbackrest
sudo chown backrest:backrest /var/lib/pgbackrest
sudo -u backrest mkdir -m 750 /home/backrest/.ssh
sudo -u backrest ssh-keygen -f /home/backrest/.ssh/id_rsa -t rsa -b 4096 -N ""
sudo -u postgres mkdir -m 750 -p /home/postgres/.ssh
sudo -u postgres ssh-keygen -f /home/postgres/.ssh/id_rsa -t rsa -b 4096 -N ""
sudo ssh root@db-primary cat /home/postgres/.ssh/id_rsa.pub | \ sudo -u backrest tee -a /home/backrest/.ssh/authorized_keys
sudo ssh root@backup cat /home/backrest/.ssh/id_rsa.pub | \ sudo -u postgres tee -a /home/postgres/.ssh/authorized_keys
sudo -u backrest ssh postgres@db-primary
sudo -u postgres ssh backrest@backup
sudo -u backrest pgbackrest --stanza=demo stanza-create
sudo -u postgres pgbackrest --stanza=demo check
sudo -u backrest pgbackrest --stanza=demo check
sudo -u backrest pgbackrest --stanza=demo backup
P00 WARN: no prior backup exists, incr backup has been changed to full
sudo pg_ctlcluster 9.4 demo stop
sudo -u postgres pgbackrest --stanza=demo --delta restore
sudo pg_ctlcluster 9.4 demo start
sudo -u backrest pgbackrest --stanza=demo backup
looking aheadto see which WAL segments are ready to be archived beyond the request that PostgreSQL is currently making via the archive_command. WAL segments are transferred to the archive directly from the pg_xlog/pg_wal directory and success is only returned by the archive_command when the WAL segment has been safely stored in the archive.
sudo mkdir -m 750 /var/spool/pgbackrest
sudo chown postgres:postgres /var/spool/pgbackrest
sudo -u postgres psql -c " \ select pg_create_restore_point('test async push'); select pg_switch_xlog(); \ select pg_create_restore_point('test async push'); select pg_switch_xlog(); \ select pg_create_restore_point('test async push'); select pg_switch_xlog(); \ select pg_create_restore_point('test async push'); select pg_switch_xlog(); \ select pg_create_restore_point('test async push'); select pg_switch_xlog();"
sudo -u postgres pgbackrest --stanza=demo --log-level-console=info check
P00 INFO: check command begin 1.29: --backup-host=backup --backup-user=backrest --db1-path=/var/lib/postgresql/9.4/demo --log-level-console=info --log-level-file=detail --log-level-stderr=off --no-log-timestamp --stanza=demo
P00 INFO: WAL segment 000000080000000000000024 successfully stored in the archive at '/var/lib/pgbackrest/archive/demo/9.4-1/0000000800000000/000000080000000000000024-5778280824c975d3bd7207cb890bdf519044c78f.gz'
P00 INFO: check command end: completed successfully
sudo -u postgres cat /var/log/pgbackrest/demo-archive-async.log
-------------------PROCESS START------------------- P00 INFO: archive-push command begin 1.29: --archive-async --backup-host=backup --backup-user=backrest --db1-path=/var/lib/postgresql/9.4/demo --log-level-file=detail --log-level-stderr=off --no-log-timestamp --process-max=2 --spool-path=/var/spool/pgbackrest --stanza=demo
P00 INFO: push 2 WAL file(s) to archive: 00000008000000000000001F...000000080000000000000020 P01 DETAIL: pushed WAL file 00000008000000000000001F to archive P02 DETAIL: pushed WAL file 000000080000000000000020 to archive
P00 INFO: archive-push command end: completed successfully -------------------PROCESS START------------------- P00 INFO: archive-push command begin 1.29: --archive-async --backup-host=backup --backup-user=backrest --db1-path=/var/lib/postgresql/9.4/demo --log-level-file=detail --log-level-stderr=off --no-log-timestamp --process-max=2 --spool-path=/var/spool/pgbackrest --stanza=demo
P00 INFO: push 3 WAL file(s) to archive: 000000080000000000000021...000000080000000000000023 P01 DETAIL: pushed WAL file 000000080000000000000021 to archive P02 DETAIL: pushed WAL file 000000080000000000000022 to archive P01 DETAIL: pushed WAL file 000000080000000000000023 to archive
P00 INFO: archive-push command end: completed successfully -------------------PROCESS START------------------- P00 INFO: archive-push command begin 1.29: --archive-async --backup-host=backup --backup-user=backrest --db1-path=/var/lib/postgresql/9.4/demo --log-level-file=detail --log-level-stderr=off --no-log-timestamp --process-max=2 --spool-path=/var/spool/pgbackrest --stanza=demo
P00 INFO: push 1 WAL file(s) to archive: 000000080000000000000024 P01 DETAIL: pushed WAL file 000000080000000000000024 to archive
P00 INFO: archive-push command end: completed successfully
sudo -u backrest pgbackrest --stanza=demo --type=full backup
sudo -u backrest pgbackrest --stanza=demo --type=full backup
sudo -u backrest pgbackrest info
stanza: demo status: ok db (current) wal archive min/max (9.4-1): 000000080000000000000026 / 000000080000000000000028 full backup: 20180705-221949F
timestamp start/stop: 2018-07-05 22:19:49 / 2018-07-05 22:20:04
wal start/stop: 000000080000000000000026 / 000000080000000000000026 database size: 25.5MB, backup size: 25.5MB repository size: 3MB, repository backup size: 3MB full backup: 20180705-222005F
timestamp start/stop: 2018-07-05 22:20:05 / 2018-07-05 22:20:15
wal start/stop: 000000080000000000000028 / 000000080000000000000028 database size: 25.5MB, backup size: 25.5MB repository size: 3MB, repository backup size: 3MB
sudo -u postgres pgbackrest stop
sudo -u backrest pgbackrest --stanza=demo backup
P00 ERROR: [062]: raised from remote process on 'db-primary': stop file exists for all stanzas
sudo -u postgres pgbackrest stop
P00 WARN: stop file already exists for all stanzas
sudo -u postgres pgbackrest start
sudo -u postgres pgbackrest --stanza=demo stop
sudo -u backrest pgbackrest --stanza=demo backup
P00 ERROR: [062]: raised from remote process on 'db-primary': stop file exists for stanza demo
sudo -u postgres pgbackrest --stanza=demo start
sudo apt-get install libdbd-pg-perl libio-socket-ssl-perl libxml-libxml-perl
sudo wget -q -O - \ https://github.com/pgbackrest/pgbackrest/archive/release/1.29.tar.gz | \ sudo tar zx -C /root
sudo cp -r /root/pgbackrest-release-1.29/lib/pgBackRest \ /usr/share/perl5
sudo find /usr/share/perl5/pgBackRest -type f -exec chmod 644 {} +
sudo find /usr/share/perl5/pgBackRest -type d -exec chmod 755 {} +
sudo cp /root/pgbackrest-release-1.29/bin/pgbackrest /usr/bin/pgbackrest
sudo chmod 755 /usr/bin/pgbackrest
sudo mkdir -m 770 /var/log/pgbackrest
sudo chown postgres:postgres /var/log/pgbackrest
sudo touch /etc/pgbackrest.conf
sudo chmod 640 /etc/pgbackrest.conf
sudo chown postgres:postgres /etc/pgbackrest.conf
sudo sh -c 'cd /root/pgbackrest-release-1.29/libc && \ perl Makefile.PL INSTALLMAN1DIR=none INSTALLMAN3DIR=none'
sudo make -C /root/pgbackrest-release-1.29/libc test
sudo make -C /root/pgbackrest-release-1.29/libc install
sudo pg_createcluster 9.4 demo
sudo -u postgres mkdir -m 750 -p /home/postgres/.ssh
sudo -u postgres ssh-keygen -f /home/postgres/.ssh/id_rsa -t rsa -b 4096 -N ""
sudo ssh root@db-standby cat /home/postgres/.ssh/id_rsa.pub | \ sudo -u backrest tee -a /home/backrest/.ssh/authorized_keys
sudo ssh root@backup cat /home/backrest/.ssh/id_rsa.pub | \ sudo -u postgres tee -a /home/postgres/.ssh/authorized_keys
sudo -u backrest ssh postgres@db-standby
sudo -u postgres ssh backrest@backup
sudo -u postgres pgbackrest --stanza=demo --delta restore
sudo -u postgres cat /var/lib/postgresql/9.4/demo/recovery.conf
standby_mode = 'on' restore_command = '/usr/bin/pgbackrest --stanza=demo archive-get %f "%p"'
sudo pg_ctlcluster 9.4 demo start
sudo -u postgres cat /var/log/postgresql/postgresql-9.4-demo.log
LOG: could not bind IPv6 socket: Cannot assign requested address HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry. LOG: database system was interrupted; last known up at 2018-07-05 22:20:06 UTC
LOG: entering standby mode
LOG: restored log file "00000008.history" from archive LOG: incomplete startup packet LOG: restored log file "000000080000000000000028" from archive LOG: redo starts at 0/28000028 LOG: consistent recovery state reached at 0/280000F0
LOG: database system is ready to accept read only connections
sudo -u postgres psql -c " \ begin; \ create table replicated_table (message text); \ insert into replicated_table values ('Important Data'); \ commit; \ select * from replicated_table";
message ----------------
Important Data
(1 row)
sudo -u postgres psql -c "select * from replicated_table;"
ERROR: relation "replicated_table" does not exist
LINE 1: select * from replicated_table; ^
sudo -u postgres psql -c "select *, current_timestamp from pg_switch_xlog()";
pg_switch_xlog | now ----------------+------------------------------- 0/290199E0 | 2018-07-05 22:20:49.401096+00 (1 row)
sudo -u postgres psql -c " \ select *, current_timestamp from replicated_table"
message | now ----------------+-------------------------------
Important Data | 2018-07-05 22:20:50.956462+00
(1 row)
sudo -u postgres pgbackrest --stanza=demo --log-level-console=info check
P00 INFO: check command begin 1.29: --backup-host=backup --db1-path=/var/lib/postgresql/9.4/demo --log-level-console=info --log-level-stderr=off --no-log-timestamp --stanza=demo
P00 INFO: switch xlog cannot be performed on the standby, all other checks passed successfully
P00 INFO: check command end: completed successfully
sudo -u postgres psql -c " \ create user replicator password 'jw8s0F4' replication";
CREATE ROLE
sudo -u postgres sh -c 'echo \ "host replication replicator 172.17.0.5/32 md5" \ >> /etc/postgresql/9.4/demo/pg_hba.conf'
sudo pg_ctlcluster 9.4 demo reload
sudo -u postgres sh -c 'echo \ "172.17.0.3:*:replication:replicator:jw8s0F4" \ >> /home/postgres/.pgpass'
sudo -u postgres chmod 600 /home/postgres/.pgpass
sudo pg_ctlcluster 9.4 demo stop
sudo -u postgres pgbackrest --stanza=demo --delta restore
sudo -u postgres cat /var/lib/postgresql/9.4/demo/recovery.conf
primary_conninfo = 'host=172.17.0.3 port=5432 user=replicator' standby_mode = 'on' restore_command = '/usr/bin/pgbackrest --stanza=demo archive-get %f "%p"'
sudo pg_ctlcluster 9.4 demo start
sudo -u postgres cat /var/log/postgresql/postgresql-9.4-demo.log
[filtered 10 lines of output] LOG: database system is ready to accept read only connections LOG: restored log file "000000080000000000000029" from archive
LOG: started streaming WAL from primary at 0/2A000000 on timeline 8
sudo -u postgres psql -c " \ begin; \ create table stream_table (message text); \ insert into stream_table values ('Important Data'); \ commit; \ select *, current_timestamp from stream_table";
message | now ----------------+-------------------------------
Important Data | 2018-07-05 22:21:03.489564+00
(1 row)
sudo -u postgres psql -c " \ select *, current_timestamp from stream_table"
message | now ----------------+-----------------------------
Important Data | 2018-07-05 22:21:03.7855+00
(1 row)
sudo -u backrest pgbackrest --stanza=demo --log-level-console=detail backup
[filtered 2 lines of output] P00 INFO: execute exclusive pg_start_backup() with label "pgBackRest backup started at 2018-07-05 22:21:04": backup begins after the requested immediate checkpoint completes P00 INFO: backup start archive = 00000008000000000000002B, lsn = 0/2B000028
P00 INFO: wait for replay on the standby to reach 0/2B000028 P00 INFO: replay on the standby reached 0/2B0000C8
P04 INFO: backup file db-standby:/var/lib/postgresql/9.4/demo/base/12139/12009 (240KB, 12%) checksum 14a2c1b5fe6f7155aaeaaec0ca7eb60c46aa5ac1 P02 INFO: backup file db-standby:/var/lib/postgresql/9.4/demo/base/12139/12007 (392KB, 32%) checksum 87f10131e163854653b5968b390075c2dbfbb735 P04 INFO: backup file db-standby:/var/lib/postgresql/9.4/demo/base/12139/12010 (232KB, 44%) checksum 3dbbb29edd9a48fd214a407048690b5dee1b9f75 P02 INFO: backup file db-standby:/var/lib/postgresql/9.4/demo/base/12139/11891 (128KB, 51%) checksum c111ec02806557817e44dceb037f760d69e6e58a P04 INFO: backup file db-standby:/var/lib/postgresql/9.4/demo/base/12139/11892 (88KB, 55%) checksum 5c5d1c6a0b94c76eee597f9812fc105863097dbc
P01 INFO: backup file db-primary:/var/lib/postgresql/9.4/demo/global/pg_control (8KB, 56%) checksum c3017ecef8bf1b95a65ab87e0a323d6f1035ba92
P02 INFO: backup file db-standby:/var/lib/postgresql/9.4/demo/base/12139/11900 (64KB, 59%) checksum 85f2904959a51142abfeee4ac714c0b83768ebc4
P01 INFO: backup file db-primary:/var/lib/postgresql/9.4/demo/backup_label (238B, 59%) checksum 839bb33be4e25f8a2bda51cdda80cd5761fe934a
P02 INFO: backup file db-standby:/var/lib/postgresql/9.4/demo/base/12139/11903 (56KB, 62%) checksum 6469c3d1fc92d2d1792b2f66dab2266660bdd09f P03 INFO: backup file db-standby:/var/lib/postgresql/9.4/demo/base/12139/11889 (344KB, 80%) checksum 95f362e9fd6b1863138b8c3e9d5a6bf872c9dc15 [filtered 29 lines of output]
sudo apt-get install postgresql-9.5
sudo pg_dropcluster 9.5 main
sudo -u postgres /usr/lib/postgresql/9.5/bin/initdb \ -D /var/lib/postgresql/9.5/demo -k -A peer
sudo pg_createcluster 9.5 demo
Configuring already existing cluster (configuration: /etc/postgresql/9.5/demo, data: /var/lib/postgresql/9.5/demo, owner: 5000:5000) Ver Cluster Port Status Owner Data directory Log file 9.5 demo 5433 down postgres /var/lib/postgresql/9.5/demo /var/log/postgresql/postgresql-9.5-demo.log
sudo pg_ctlcluster 9.4 demo stop
sudo apt-get install postgresql-9.5
sudo pg_dropcluster 9.5 main
sudo pg_ctlcluster 9.4 demo stop
sudo -u postgres sh -c 'cd /var/lib/postgresql && \ /usr/lib/postgresql/9.5/bin/pg_upgrade \ --old-bindir=/usr/lib/postgresql/9.4/bin \ --new-bindir=/usr/lib/postgresql/9.5/bin \ --old-datadir=/var/lib/postgresql/9.4/demo \ --new-datadir=/var/lib/postgresql/9.5/demo \ --old-options=" -c config_file=/etc/postgresql/9.4/demo/postgresql.conf" \ --new-options=" -c config_file=/etc/postgresql/9.5/demo/postgresql.conf"'
[filtered 68 lines of output] Creating script to delete old cluster ok
Upgrade Complete
---------------- Optimizer statistics are not transferred by pg_upgrade so, [filtered 4 lines of output]
sudo cp /etc/postgresql/9.4/demo/pg_hba.conf \ /etc/postgresql/9.5/demo/pg_hba.conf
sudo -u backrest pgbackrest --stanza=demo --no-online \ --log-level-console=info stanza-upgrade
P00 INFO: stanza-upgrade command begin 1.29: --no-backup-standby --db1-host=db-primary --db1-path=/var/lib/postgresql/9.5/demo --db1-user=postgres --db2-host=db-standby --db2-path=/var/lib/postgresql/9.5/demo --db2-user=postgres --log-level-console=info --log-level-stderr=off --no-log-timestamp --no-online --repo-path=/var/lib/pgbackrest --stanza=demo
P00 INFO: stanza-upgrade command end: completed successfully
sudo pg_ctlcluster 9.5 demo start
sudo -u postgres pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file 9.4 demo 5432 down postgres /var/lib/postgresql/9.4/demo /var/log/postgresql/postgresql-9.4-demo.log 9.5 demo 5432 online postgres /var/lib/postgresql/9.5/demo /var/log/postgresql/postgresql-9.5-demo.log
sudo -u postgres pgbackrest --stanza=demo check
sudo -u backrest pgbackrest --stanza=demo check
P00 WARN: [056]: raised from remote process on 'db-standby': could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
sudo pg_dropcluster 9.4 demo
sudo -u backrest pgbackrest --stanza=demo --type=full backup
sudo pg_dropcluster 9.4 demo
sudo -u postgres /usr/lib/postgresql/9.5/bin/initdb \ -D /var/lib/postgresql/9.5/demo -k -A peer
sudo pg_createcluster 9.5 demo
Configuring already existing cluster (configuration: /etc/postgresql/9.5/demo, data: /var/lib/postgresql/9.5/demo, owner: 5000:5000) Ver Cluster Port Status Owner Data directory Log file 9.5 demo 5432 down postgres /var/lib/postgresql/9.5/demo /var/log/postgresql/postgresql-9.5-demo.log
sudo -u postgres pgbackrest --stanza=demo --delta restore
sudo pg_ctlcluster 9.5 demo start