Unable to restore from s3 when source cluster has been deleted
Version 4.6.0
This is attempting to test disaster recovery in the event of total loss of the cluster, where the only data that can be salvaged is what was written to s3 by pgBackRest. Or alternatively, bootstrapping a new cluster from a pgBackRest backup regardless of specific scenario. I attempt to follow the steps in the documentation to do this (docs linked below).
To Reproduce
- Create a cluster called
hippowithbackrestStorageTypesset tos3only, and add some data. - Trigger a backup of
hippo(any kind) and wait for it to complete. Verify it completed successfully, and data has been added to the configured S3 bucket. - Delete cluster
hippo - Use either (A) a custom resource or (B) pgo CLI to restore to a new cluster called
newcluster(see below)
Here are the two attempted methods:
Method (A): Custom Resource
- Create a cluster called
newclusteras described in https://access.crunchydata.com/documentation/postgres-operator/latest/custom-resources/ with the exception of modifying the following values in the yaml:
pgDataSource:
restoreFrom: "hippo"
restoreOpts: "--repo-type=s3"
- apply the generated yaml
Result
No pods are created, and the following is logged by the operator container:
level=error msg="secrets \"hippo-backrest-repo-config\" not found" func="internal/controller/pgcluster.(*Controller).processNextItem()" file="internal/controller/pgcluster/pgclustercontroller.go:126" version=4.6.0
Attempting to fix this by creating a secret called hippo-backrest-repo-config with keys backrest_s3_key and backrest_s3_key_secret yields the following in the operator logs:
level=error msg="strconv.Atoi: parsing \"\": invalid syntax" func="internal/controller/pgcluster.(*Controller).processNextItem()" file="internal/controller/pgcluster/pgclustercontroller.go:126" version=4.6.0
There is no full stack trace so this is a guess, but this might be due to the secret missing the annotations that are normally created by the operator? https://github.com/CrunchyData/postgres-operator/blob/dcd4c103e1578fea674148acd0abee183ff4a0b5/internal/operator/backrest/repo.go#L204 Perhaps creating the secret may not be the intended way to approach this?
Method (B): pgo CLI
- In line with the instructions in https://access.crunchydata.com/documentation/postgres-operator/4.6.0/architecture/provisioning/ (introduced in #1687) run the following command
pgo -n pgo create cluster newcluster --restore-from=hippo --restore-opts="--repo-type=s3"
Result
Error: Unable to find PVC hippo-pgbr-repo for cluster hippo, cannot to restore from the specified data source
Clearly this is not going to find a PVC in this scenario, the intent is to restore solely from S3. This message appears to be from https://github.com/CrunchyData/postgres-operator/blob/9d10bea60aa2a1b6e8c401e323f288bec5c93e93/internal/apiserver/clusterservice/clusterimpl.go#L2359 That function seems to unconditionally check for the existence of a PVC for the old cluster which seems like it will always prevent restores from S3 alone.
Neither of these methods result in a restored cluster - am I performing the correct steps in these methods? I've attempted to follow the documentation as closely as possible, but it may be that I've made an error somewhere in the process.
This worked for me:
Step 1: Create cluster with S3 backups
pgo create cluster hippo --pgbackrest-storage-type s3
--pgbackrest-s3-bucket=
--pgbackrest-s3-endpoint=
--pgbackrest-s3-region=
--pgbackrest-s3-key=
--pgbackrest-s3-key-secret=
Step 2: Delete cluster
pgo delete cluster hippo --keep-backups
Step 3: Create cluster from existing backups, use same repository
pgo create cluster hippo --pgbackrest-storage-type s3
--pgbackrest-s3-bucket=
--pgbackrest-s3-endpoint=
--pgbackrest-s3-region=
--pgbackrest-s3-key=
--pgbackrest-s3-key-secret=
--restore-from=hippo
--restore-opts="--repo-type=s3"
If you're preconfiguring some of the settings either in a Secret or in the pgo.yaml entry in the pgo-config ConfigMap that you may be missing some of the S3 values?
@jkatz Unfortunately this only works because of --keep-backups in step 2, which preserves the hippo-pgbr-repo PVC and the hippo-backrest-repo-config secret. I'm attempting to restore a database from only the S3 backup, without any cluster resources as would be the case in a cluster failure, for example, or migrating to another cluster).
Your steps as written work, but without --keep-backups step 3 results in the same error as Method (B) above:
Error: Unable to find PVC hippo-pgbr-repo for cluster hippo, cannot to restore from the specified data source
What steps should be taken to restore a cluster from just the S3 backup?
@alex-weaver I think you may have inadvertently spelled out the issue in your original answer based on your use case. The issue is not the PVC hanging around, but rather, having the existence of the hippo-backrest-repo-config Secret. This Secret is derived from the pgo-backrest-repo-config Secret, that is created along side the Operator in its namespace, with the addition of the aws-s3-key and aws-s3-key-secret.
The Secret should be present, if not recreated to accommodate this case.
However, you are right, it is currently expecting to be a PVC available, even in the S3 only use case. I think that could be treated as a bug, and I'm going to drill into it a bit further.
As a quick update, I made some modifications to the code locally and was able to get the desired case up and running without initially having the PVC available. However, there is a step where having the existence of the PVC is mandatory even with the S3 backup. I need to look into how mandatory that piece is. This may actually end up falling into "new work." (You can see I've toggled the labels a bit).
However, it is possible to still perform the disaster migration/recovery case that you specify. You would effectively follow some of the steps described in the multi-cluster setup:
This method is typically used for migrations and is available as a disaster recovery option. It does not need to work "cross-cluster" per se -- I typically test it within the same Kubernetes cluster -- in fact, the same namespace.
@jkatz thanks, I've been able to restore a cluster by setting up a standby cluster, then promoting it. However, this does seem to at least require the password for primaryuser, which is held in the secrets of the old cluster. In this disaster recovery scenario, that is lost too. Is it possible to start a standby cluster if the primaryuser password has been lost?
You would need to rotate the credential.