我正在使用pg_basebackup
这样从Postgresql数据库(v11)进行备份:
pg_basebackup -h localhost -p 5432 -U postgres -D /tmp/backup -Ft -z -Xs -P
备份过程顺利完成,没有任何错误。然后,作为一项测试,我想从备份中恢复,为此,我执行以下步骤:
删除/var/lib/postgresql/data
文件夹中的所有内容
rm -rf /var/lib/postgresl/data/*
在此处解压基本存档:
tar xvf /tmp/backup/base.tar.gz -C /var/lib/postgresql/data
将沃尔玛档案解压缩到一个临时目录中
tar xvf /tmp/backup/pg_wal.tar.gz -C /tmp/archived_wals
在recovery.conf
文件夹中创建文件/var/lib/postgresql/data
:
touch /var/lib/postgresql/data/recovery.conf
chown postgres:postgres /var/lib/postgresql/data/recovery.conf
在recovery.conf文件中指定恢复命令:
restore_command = 'cp /path/archived_wals/%f "%p" '
重新启动postgres实例,并等待恢复完成。
然而,当postgres启动时,我在日志中收到以下错误:
2020-02-04 11:34:52.599 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2020-02-04 11:34:52.599 UTC [1] LOG: listening on IPv6 address "::", port 5432
2020-02-04 11:34:52.613 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2020-02-04 11:34:52.709 UTC [18] LOG: database system was interrupted; last known up at 2020-02-04 08:39:54 UTC
cp: can't stat '/tmp/archived_wals/00000002.history': No such file or directory
2020-02-04 11:34:52.735 UTC [18] LOG: starting archive recovery
2020-02-04 11:34:52.752 UTC [18] LOG: invalid checkpoint record
2020-02-04 11:34:52.752 UTC [18] FATAL: could not locate required checkpoint record
2020-02-04 11:34:52.752 UTC [18] HINT: If you are not restoring from a backup, try removing the file "/var/lib/postgresql/data/backup_label".
2020-02-04 11:34:52.753 UTC [1] LOG: startup process (PID 18) exited with exit code 1
2020-02-04 11:34:52.753 UTC [1] LOG: aborting startup due to startup process failure
2020-02-04 11:34:52.769 UTC [1] LOG: database system is shut down
我想我缺少了一些东西,也许我需要对postgres进行其他配置才能恢复pg_basebackup
备份?
尝试一下:
/pgsql-11/bin/pg_basebackup -D /pgdata/pg11/data -X stream --waldir=/pglog/pg11/wal_log/ -P -c fast -h remoteserver\localserver -U username
让我知道是否可行。
毕竟,这是我的坏事。
我将目标占位符放在%中,而不是在recovery.conf
中使用双引号。
但是,我描述的备份和还原方式是有效的,并且由于我更正了该类型,所以它对我来说很好用,所以我将这个问题留待进一步参考。