接着上一篇pg备份文档:https://blog.csdn.net/weixin_41561946/article/details/104183555
六、 pgbackRest恢复
1. 查看现有备份
[cddb@cddb-node1 ~]$ pgbackrest info
stanza: demo
status: ok
cipher: aes-256-cbc
db (current)
wal archive min/max (11-1): 0000000A00000001000000F8/0000000A00000001000000FC
full backup: 20200204-163558F
timestamp start/stop: 2020-02-04 16:35:58 / 2020-02-04 16:46:14
wal start/stop: 0000000A00000001000000F8 / 0000000A00000001000000F8
database size: 3.9GB, backup size: 3.9GB
repository size: 810.3MB, repository backup size: 810.3MB
full backup: 20200205-142255F
timestamp start/stop: 2020-02-05 14:22:55 / 2020-02-05 14:30:50
wal start/stop: 0000000A00000001000000FB / 0000000A00000001000000FB
database size: 3.9GB, backup size: 3.9GB
repository size: 810.3MB, repository backup size: 810.3MB
2. 准备恢复环境
数据目录:/cddb5.0/data2
表空间目录:/cddb5.0/tablespace
关闭数据库
pg_ctl stop –D /cddb5.0/data2
删除data2/和tablespace目录
rm –f /cddb5.0/data2/*
rm –f /cddb5.0/tablespace
3. 执行完全恢复操作
[cddb@cddb-node1 cddb5.0]$ pgbackrest restore --stanza=demo --delta --log-level-console=detail
2020-02-05 14:58:45.779 P00 DETAIL: sync path ‘/cddb5.0/data2/global’
2020-02-05 14:58:46.124 P00 INFO: restore command end: completed successfully (226917ms)
4. 执行部分数据库恢复操作
创建测试数据库
[cddb@cddb-node1 cddb5.0]$ psql -d SWDS -p 7321 -U swds2014
SWDS=# create database test1;
SWDS=# create database test2;
执行增量备份
[cddb@cddb-node1 cddb5.0]$ pgbackrest --stanza=demo --type=incr backup
创建测试表
test1=# create table test1_table(id int);
test1=# insert into test1_table values(1);
test1=# \c test2
test2=# create table test2_table(id int);
test2=# insert into test2_table values(2);
恢复数据库test2
[cddb@cddb-node1 cddb5.0] p g c t l s t o p – D