PostgreSQL备份工具pgBackRest使用说明
2021-01-08 20:42:58.887 P00 INFO: stanza-create command begin 2.31: --exec-id=9283-e9744c3e --log-level-console=info --pg1-host=sungsasong --pg1-host-config-path=/data/pg10/pgbackrest --pg1-host-port=22 --pg1-host-user=postgres --pg1-path=/data/pg10/pgdata --pg1-port=10001 --pg1-user=postgres --repo1-path=/pgbackrest/repos --stanza=demo 2021-01-08 20:42:59.835 P00 INFO: stanza-create command end: completed successfully (948ms)
检查配置
[postgres@sungsasong ~]$ pgbackrest --stanza=demo --log-level-console=info check 2021-01-08 21:41:29.851 P00 INFO: check command begin 2.31: --exec-id=21648-1862ac0d --log-level-console=info --pg1-path=/data/pg10/pgdata --pg1-port=10001 --pg1-user=postgres --repo1-path=/pgbackrest/repos --stanza=demo 2021-01-08 21:41:32.826 P00 INFO: WAL segment 000000010000000000000006 successfully archived to '/pgbackrest/repos/archive/demo/10-1/0000000100000000/000000010000000000000006-2f027934f4f35cd3983ca4b1b7b43c32ab089448.gz' 2021-01-08 21:41:32.826 P00 INFO: check command end: completed successfully (2975ms)
执行备份
默认为增量备份,增量备份将会请求一个基础全备,如果没有基础全备,增量备份将会变更到全备。
pgbackrest --stanza=demo --log-level-console=info backup 2021-01-08 21:43:55.014 P00 INFO: backup command begin 2.31: --exec-id=21661-13c54272 --log-level-console=info --pg1-path=/data/pg10/pgdata --pg1-port=10001 --pg1-user=postgres --repo1-path=/pgbackrest/repos --repo1-retention-full=2 --stanza=demo WARN: no prior backup exists, incr backup has been changed to full ... 此处省略很多输出 ... 2021-01-08 21:44:00.951 P00 INFO: full backup size = 23.3MB 2021-01-08 21:44:00.951 P00 INFO: execute non-exclusive pg_stop_backup() and wait for all WAL segments to archive 2021-01-08 21:44:01.153 P00 INFO: backup stop archive = 000000010000000000000008, lsn = 0/8000130 2021-01-08 21:44:01.154 P00 INFO: check archive for segment(s) 000000010000000000000008:000000010000000000000008 2021-01-08 21:44:01.273 P00 INFO: new backup label = 20210108-214355F 2021-01-08 21:44:01.301 P00 INFO: backup command end: completed successfully (6288ms) 2021-01-08 21:44:01.301 P00 INFO: expire command begin 2.31: --exec-id=21661-13c54272 --log-level-console=info --repo1-path=/pgbackrest/repos --repo1-retention-full=2 --stanza=demo 2021-01-08 21:44:01.304 P00 INFO: expire command end: completed successfully (3ms)
可以定义备份的类型为增量还是差异备份
使用—type参数指定
[postgres@sungsasong ~]$ pgbackrest --stanza=demo --log-level-console=info --type=diff backup 2021-01-08 21:47:00.964 P00 INFO: backup command begin 2.31: --exec-id=21671-d3f8f8bf --log-level-console=info --pg1-path=/data/pg10/pgdata --pg1-port=10001 --pg1-user=postgres --repo1-path=/pgbackrest/repos --repo1-retention-full=2 --stanza=demo --type=diff 2021-01-08 21:47:01.770 P00 INFO: last backup label = 20210108-214355F, version = 2.31 2021-01-08 21:47:01.770 P00 INFO: execute non-exclusive pg_start_backup(): backup begins after the next regular checkpoint completes 2021-01-08 21:47:02.309 P00 INFO: backup start archive = 00000001000000000000000A, lsn = 0/A000028 2021-01-08 21:47:03.617 P01 INFO: backup file /data/pg10/pgdata/global/pg_control (8KB, 99%) checksum 5f020e7df484269ea245041be3228673560184ef 2021-01-08 21:47:03.721 P01 INFO: backup file /data/pg10/pgdata/pg_logical/replorigin_checkpoint (8B, 100%) checksum 347fc8f2df71bd4436e38bd1516ccd7ea0d46532 2021-01-08 21:47:03.722 P00 INFO: diff backup size = 8KB 2021-01-08 21:47:03.722 P00 INFO: execute non-exclusive pg_stop_backup() and wait for all WAL segments to archive 2021-01-08 21:47:03.942 P00 INFO: backup stop archive = 00000001000000000000000A, lsn = 0/A0000F8 2021-01-08 21:47:03.943 P00 INFO: check archive for segment(s) 00000001000000000000000A:00000001000000000000000A 2021-01-08 21:47:04.062 P00 INFO: new backup label = 20210108-214355F_20210108-214701D 2021-01-08 21:47:04.092 P00 INFO: backup command end: completed successfully (3129ms) 2021-01-08 21:47:04.092 P00 INFO: expire command begin 2.31: --exec-id=21671-d3f8f8bf --log-level-console=info --repo1-path=/pgbackrest/repos --repo1-retention-full=2 --stanza=demo 2021-01-08 21:47:04.095 P00 INFO: expire command end: completed successfully (3ms)
备份信息查看
[postgres@sungsasong ~]$ pgbackrest info stanza: demo status: ok cipher: none
db (current) wal archive min/max (10-1): 000000010000000000000001/00000001000000000000000A
full backup: 20210108-214355F timestamp start/stop: 2021-01-08 21:43:55 / 2021-01-08 21:44:01 wal start/stop: 000000010000000000000008 / 000000010000000000000008 database size: 23.3MB, backup size: 23.3MB repository size: 2.7MB, repository backup size: 2.7MB
diff backup: 20210108-214355F_20210108-214701D timestamp start/stop: 2021-01-08 21:47:01 / 2021-01-08 21:47:03 wal start/stop: 00000001000000000000000A / 00000001000000000000000A database size: 23.3MB, backup size: 8.2KB repository size: 2.7MB, repository backup size: 425B backup reference list: 20210108-214355F
还原一个备份
模拟数据库损坏
[postgres@sungsasong ~]$ cd $PGDATA/ [postgres@sungsasong pgdata]$ rm -rf * #100分警告:千万不要拿生产库执行
执行还原
1[postgres@sungsasong pgdata]$ pgbackrest --stanza=demo restore
重新启动数据库
[postgres@sungsasong pgdata]$ pg_ctl start -D $PGDATA -l /tmp/logfile waiting for server to start.... done server started [postgres@sungsasong pgdata]$ psql psql (10.13) Type "help" for help.
以上就是pgbackrest介绍及使用。当前使用的最新版本已经可以支持PostgreSQL13版本,仅仅是文档上标注支持最新到PostgreSQL11版本。感兴趣的同学可以下去试一下。 (编辑:焦作站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |