无法从 pg_basebackup 恢复 postgres v11

Couldn't restore postgres v11 from pg_basebackup

我正在使用 pg_basebackup 从我的 postgresql 数据库 (v11) 进行备份,如下所示:

pg_basebackup -h localhost -p 5432 -U postgres -D /tmp/backup -Ft -z -Xs -P

备份过程完成得很好,没有任何 errors.Then 作为测试,我想从备份中恢复,为此我执行以下步骤:

  1. 关闭 postgres 实例。
  2. 删除 /var/lib/postgresql/data 文件夹中的所有内容

    rm -rf /var/lib/postgresl/data/*

  3. 在那里解压基本存档:

    tar xvf /tmp/backup/base.tar.gz -C /var/lib/postgresql/data

  4. 将 wal 档案解压到一​​个临时目录

    tar xvf /tmp/backup/pg_wal.tar.gz -C /tmp/archived_wals

  5. /var/lib/postgresql/data 文件夹中创建文件 recovery.conf

    touch /var/lib/postgresql/data/recovery.conf
    chown postgres:postgres /var/lib/postgresql/data/recovery.conf
    
  6. 在recovery.conf文件中指定恢复命令:

    restore_command = 'cp /path/archived_wals/%f "%p" '

  7. 重启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.

中的双引号

然而,我描述的备份和恢复方式是有效的,而且由于我更正了拼写错误,它对我来说工作得很好,所以我留下这个问题以供进一步参考。