使用 pgbackrest 从 s3 恢复 postgres 集群时出错

问题描述

我想通过 pgbackrest 使用来自 s3 的备份来测试恢复集群

我有: OpenShift 4.7 PGO 镜像标签:centos8-13.2-4.6.2 Postgres 版本 13

如何复制:

第一步: 我安装了 crunchy operator 并创建了集群:

pgo create cluster example-db \
  --pgbouncer \
  --replica-count=1 \
  --password-superuser="%%%%%" \
  --password-replication="%%%%%" \
  --database test-db \
  --username test-user \
  --password="%%%%%%" \
  --pvc-size 20Gi \
  --pgbackrest-pvc-size 40Gi \
  --metrics \
  --pgbackrest-storage-type=s3 \
  --pgbackrest-s3-key=test-db-backup-rw \
  --pgbackrest-s3-key-secret=%%%%% \
  --pgbackrest-s3-bucket=test-db-backup \
  --pgbackrest-s3-endpoint=s3.my_site.com \
  --pgbackrest-s3-uri-style=path \
  --pgbackrest-s3-verify-tls=false

没关系。

第 2 步: 我创建备份

pgo backup example-db --backup-opts="--type=full --repo1-retention-full=3 --archive-timeout=300" --pgbackrest-storage-type=s3

那也行。

第 3 步: 我删除集群(模拟这个集群的丢失)。

pgo delete cluster example-db

备份仍保留在 s3 中。

第 4 步: 我正在尝试通过创建备用集群来恢复此集群

pgo create cluster standby-test-db \
  --standby \
  --pgbouncer \
  --replica-count=1 \
  --password-superuser="%%%%%" \
  --password-replication="%%%%" \
  --database test-db \
  --username test-user \
  --password="%%%%" \
  --pvc-size 20Gi \
  --pgbackrest-pvc-size 40Gi \
  --metrics \
  --pgbackrest-storage-type=s3 \
  --pgbackrest-s3-key=test-db-backup-rw \
  --pgbackrest-s3-key-secret=%%%%% \
  --pgbackrest-s3-bucket=test-db-backup \
  --pgbackrest-s3-endpoint=s3.my_site.com \
  --pgbackrest-s3-uri-style=path \
  --pgbackrest-s3-verify-tls=false \
  --pgbackrest-repo-path=/backrestrepo/example-db-backrest-shared-repo

我的 pod 中收到了很多相同的警告:

...
�[0;33mTue Jun 22 16:30:16 UTC 2021 WARN: Detected an earlier Failed attempt to initialize�[0m
�[0;32mTue Jun 22 16:30:16 UTC 2021 INFO: Correct the issue,remove '/pgdata/standby-test-db.initializing',and try again�[0m
�[0;32mTue Jun 22 16:30:16 UTC 2021 INFO: Your data might be in: /pgdata/standby-test-db_*�[0m
�[0;33mTue Jun 22 16:30:26 UTC 2021 WARN: Detected an earlier Failed attempt to initialize�[0m
�[0;32mTue Jun 22 16:30:26 UTC 2021 INFO: Correct the issue,and try again�[0m
�[0;32mTue Jun 22 16:30:26 UTC 2021 INFO: Your data might be in: /pgdata/standby-test-db_*�[0m
...

如果我删除 /pgdata/standby-test-db_* 它不会改变消息 如果我重新启动 pod - /pgdata/standby-test-db_* 将再次创建。

我完全被这个问题搞糊涂了。

解决方法

我研究了这个问题,结果发现 pgbackrest 没有找到正确的完整备份。 我重新创建了完整备份,问题解决了。