This guide describes how to copy and validate pgBackRest backups locally, and how to restore PostgreSQL from backup.
- PostgreSQL installed and configured.
pgBackRestinstalled and configured with the correct stanza.- Access to the backup repository.
- Appropriate permissions to run PostgreSQL and
pgBackRestcommands. - The target database service should be stopped before restoring.
sudo apt update
sudo apt install pgbackrestUse this process to copy the backup repository from OpenShift to your local machine and inspect backups.
-
Create a local destination directory
pgbackrestrequires an absolute repository path.mkdir -p $PWD/pgbackrest/repo1 -
Copy repo files from OpenShift repo host pod
oc cp -n bfc7dd-<env> hesp-crunchydb-repo-host-0:/pgbackrest/repo1 $PWD/pgbackrest/repo1 -c pgbackrest
Example for DEV:
oc cp -n bfc7dd-dev hesp-crunchydb-repo-host-0:/pgbackrest/repo1 $PWD/pgbackrest/repo1 -c pgbackrest -
Inspect backups locally using
infopgbackrest --stanza=db --repo1-path=$PWD/pgbackrest/repo1 infoIf you receive
missing stanza path, check whether the copy created an extrarepo1level and point to that path instead:pgbackrest --stanza=db --repo1-path=$PWD/pgbackrest/repo1/repo1 info
-
Stop the PostgreSQL service
pg_ctl stop
-
Run
pgBackRestrestorepgbackrest --stanza=db restore --repo=1 --type=default --delta
Option summary:
--stanza=db: Stanza name defined in yourpgBackRestconfiguration.--repo=1: Backup repository number.--type=default: Default restore type.--delta: Restore only changed files when possible.
-
Start the PostgreSQL service
pg_ctl start
-
Update the
postgresuser passwordpsql -U postgres -d hesp-crunchydb
ALTER USER postgres WITH PASSWORD '<new_password>';
-
Confirm
pgBackRestsees backups (sanity check)oc exec -n bfc7dd-<env> $(oc get pods -n bfc7dd-<env> | grep crunchydb-repo-host | awk '{print $1}') -- pgbackrest info
This should output the stanza and one or more full/incremental backups.
-
Shut down the cluster (operator-native)
oc patch -n bfc7dd-<env> postgrescluster hesp-crunchydb \ -p '{"spec":{"shutdown":true}}' --type=merge
Wait for PostgreSQL pods to terminate before continuing.
-
Delete the pgdata PVC
Note: this does not delete the backup repo PVC.
oc get pvc -n bfc7dd-<env> oc delete pvc -n bfc7dd-<env> <pgdata_pvc_name>
-
Edit the cluster to restore from
pgBackRestoc edit postgrescluster hesp-crunchydb -n bfc7dd-<env>
Add or update:
spec: dataSource: pgbackrest: stanza: db repo: name: repo1
-
Start the cluster to trigger restore
oc patch -n bfc7dd-<env> postgrescluster hesp-crunchydb \ -p '{"spec":{"shutdown":false}}' --type=merge
Expected behavior:
- Operator creates a new pgdata PVC.
- New pgdata directory is initialized.
pgBackRestrestore runs.- Pod may start as replica and then promote.
- PostgreSQL completes startup.
-
Watch restore logs
oc logs -n bfc7dd-<env> -f $(oc get pods -n bfc7dd-<env> | grep hesp-crunchydb-ha | awk '{print $1}')
-
Verify in application
Log in to the application and validate expected data/state.