pgbackrest 支持并行备份,还支持加密备份。
有全备份、增量备份、差异备份(Full, differential, and incremental backups are supported. )。
os: centos 7.4
db: postgresql 11.7
# cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core)
#
#
# yum list installed |grep -i postgresql
postgresql11.x86_64 11.7-1PGDG.rhel7 @pgdg11
postgresql11-contrib.x86_64 11.7-1PGDG.rhel7 @pgdg11
postgresql11-debuginfo.x86_64 11.5-1PGDG.rhel7 @pgdg11
postgresql11-devel.x86_64 11.7-1PGDG.rhel7 @pgdg11
postgresql11-docs.x86_64 11.7-1PGDG.rhel7 @pgdg11
postgresql11-libs.x86_64 11.7-1PGDG.rhel7 @pgdg11
postgresql11-llvmjit.x86_64 11.7-1PGDG.rhel7 @pgdg11
postgresql11-odbc.x86_64 12.01.0000-1PGDG.rhel7 @pgdg11
postgresql11-plperl.x86_64 11.7-1PGDG.rhel7 @pgdg11
postgresql11-plpython.x86_64 11.7-1PGDG.rhel7 @pgdg11
postgresql11-plpython3.x86_64 11.7-1PGDG.rhel7 @pgdg11
postgresql11-pltcl.x86_64 11.7-1PGDG.rhel7 @pgdg11
postgresql11-server.x86_64 11.7-1PGDG.rhel7 @pgdg11
postgresql11-tcl.x86_64 2.4.0-2.rhel7.1 @pgdg11
postgresql11-test.x86_64 11.7-1PGDG.rhel7 @pgdg11
# su - postgres
Last login: Wed Jan 15 18:34:12 CST 2020 on pts/0
$
$
$ psql -c "select version();"
version
---------------------------------------------------------------------------------------------------------
PostgreSQL 11.7 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39), 64-bit
(1 row)
# pgbackrest
pgBackRest 2.26 - 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.
# mkdir -p /var/lib/pgsql/pgbackrest;
chmod 750 /var/lib/pgsql/pgbackrest;
chown postgres:postgres /var/lib/pgsql/pgbackrest;
# vi /etc/pgbackrest/pgbackrest.conf
[pg1-data]
pg1-path=/var/lib/pgsql/11/data
[global]
archive-async=y
process-max=2
start-fast=y
repo1-path=/var/lib/pgsql/pgbackrest
repo1-retention-full=5
[global:archive-push]
process-max=2
compress-level=3
[global:archive-get]
process-max=2
# vi /var/lib/pgsql/11/data/postgresql.conf
archive_command = 'pgbackrest --stanza=pg1-data archive-push %p'
archive_mode = on
listen_addresses = '*'
max_wal_senders = 20
wal_level = replica
# systemctl restart postgresql-11.service
# su - postgres
$ pgbackrest --stanza=pg1-data --log-level-console=info stanza-create
2020-05-03 23:38:27.315 P00 INFO: stanza-create command begin 2.26: --log-level-console=info --pg1-path=/var/lib/pgsql/11/data --repo1-path=/var/lib/pgsql/pgbackrest --stanza=pg1-data
2020-05-03 23:38:28.054 P00 INFO: stanza-create command end: completed successfully (740ms)
$ tree
.
├── archive
│ └── pg1-data
│ ├── archive.info
│ └── archive.info.copy
└── backup
└── pg1-data
├── backup.info
└── backup.info.copy
4 directories, 4 files
$ pgbackrest --stanza=pg1-data --log-level-console=info check
2020-05-03 23:41:21.263 P00 INFO: check command begin 2.26: --log-level-console=info --pg1-path=/var/lib/pgsql/11/data --repo1-path=/var/lib/pgsql/pgbackrest --stanza=pg1-data
2020-05-03 23:41:23.272 P00 INFO: WAL segment 00000001000000010000003F successfully archived to '/var/lib/pgsql/pgbackrest/archive/pg1-data/11-1/0000000100000001/00000001000000010000003F-56c9f61d16dbdeaa21218f9d23445eb00fb10eda.gz'
2020-05-03 23:41:23.272 P00 INFO: check command end: completed successfully (2009ms)
$ pgbackrest --stanza=pg1-data --log-level-console=info --start-fast --type=full backup
2020-05-03 23:48:02.398 P00 INFO: full backup size = 141.6MB
2020-05-03 23:48:02.398 P00 INFO: execute non-exclusive pg_stop_backup() and wait for all WAL segments to archive
2020-05-03 23:48:02.603 P00 INFO: backup stop archive = 000000010000000100000041, lsn = 1/41000168
2020-05-03 23:48:02.619 P00 INFO: check archive for segment(s) 000000010000000100000041:000000010000000100000041
2020-05-03 23:48:02.676 P00 INFO: new backup label = 20200503-234738F
2020-05-03 23:48:02.760 P00 INFO: backup command end: completed successfully (25687ms)
2020-05-03 23:48:02.760 P00 INFO: expire command begin 2.26: --log-level-console=info --repo1-path=/var/lib/pgsql/pgbackrest --stanza=pg1-data
2020-05-03 23:48:02.769 P00 INFO: option 'repo1-retention-archive' is not set - archive logs will not be expired
2020-05-03 23:48:02.889 P00 INFO: expire command end: completed successfully (129ms)
$ pgbackrest --stanza=pg1-data --log-level-console=info --start-fast --type=diff backup
2020-05-03 23:54:25.581 P00 INFO: diff backup size = 2.5MB
2020-05-03 23:54:25.581 P00 INFO: execute non-exclusive pg_stop_backup() and wait for all WAL segments to archive
2020-05-03 23:54:25.899 P00 INFO: backup stop archive = 000000010000000100000043, lsn = 1/430000F8
2020-05-03 23:54:25.904 P00 INFO: check archive for segment(s) 000000010000000100000043:000000010000000100000043
2020-05-03 23:54:25.960 P00 INFO: new backup label = 20200503-234738F_20200503-235423D
2020-05-03 23:54:26.070 P00 INFO: backup command end: completed successfully (3018ms)
2020-05-03 23:54:26.070 P00 INFO: expire command begin 2.26: --log-level-console=info --repo1-path=/var/lib/pgsql/pgbackrest --stanza=pg1-data
2020-05-03 23:54:26.078 P00 INFO: option 'repo1-retention-archive' is not set - archive logs will not be expired
2020-05-03 23:54:26.206 P00 INFO: expire command end: completed successfully (136ms)
$ pgbackrest --stanza=pg1-data --log-level-console=info --start-fast --type=incr backup
2020-05-03 23:59:08.564 P00 INFO: incr backup size = 2.4MB
2020-05-03 23:59:08.564 P00 INFO: execute non-exclusive pg_stop_backup() and wait for all WAL segments to archive
2020-05-03 23:59:08.770 P00 INFO: backup stop archive = 000000010000000100000045, lsn = 1/450000F8
2020-05-03 23:59:08.775 P00 INFO: check archive for segment(s) 000000010000000100000045:000000010000000100000045
2020-05-03 23:59:08.840 P00 INFO: new backup label = 20200503-234738F_20200503-235906I
2020-05-03 23:59:08.932 P00 INFO: backup command end: completed successfully (3345ms)
2020-05-03 23:59:08.933 P00 INFO: expire command begin 2.26: --log-level-console=info --repo1-path=/var/lib/pgsql/pgbackrest --stanza=pg1-data
2020-05-03 23:59:08.942 P00 INFO: option 'repo1-retention-archive' is not set - archive logs will not be expired
2020-05-03 23:59:09.069 P00 INFO: expire command end: completed successfully (137ms)
$ pgbackrest info
stanza: pg1-data
status: ok
cipher: none
db (current)
wal archive min/max (11-1): 00000001000000010000003F/000000010000000100000045
full backup: 20200503-234738F
timestamp start/stop: 2020-05-03 23:47:38 / 2020-05-03 23:48:02
wal start/stop: 000000010000000100000041 / 000000010000000100000041
database size: 141.6MB, backup size: 141.6MB
repository size: 15.1MB, repository backup size: 15.1MB
diff backup: 20200503-234738F_20200503-235423D
timestamp start/stop: 2020-05-03 23:54:23 / 2020-05-03 23:54:25
wal start/stop: 000000010000000100000043 / 000000010000000100000043
database size: 141.6MB, backup size: 2.5MB
repository size: 15.1MB, repository backup size: 269.5KB
backup reference list: 20200503-234738F
incr backup: 20200503-234738F_20200503-235906I
timestamp start/stop: 2020-05-03 23:59:06 / 2020-05-03 23:59:08
wal start/stop: 000000010000000100000045 / 000000010000000100000045
database size: 141.6MB, backup size: 2.4MB
repository size: 15.1MB, repository backup size: 230.7KB
backup reference list: 20200503-234738F, 20200503-234738F_20200503-235423D
参考:
https://github.com/pgbackrest/pgbackrest
https://pgbackrest.org/
https://pgbackrest.org/configuration.html
https://pgbackrest.org/command.html
https://pgbackrest.org/user-guide-index.html