Restore PostgreSQL¶
This operation can be executed from any macOS or GNU/Linux machine that has enough space to store the backup.
注意
If your DataRobot platform is configured to use managed services (external PCS) for PostgreSQL, do not follow this guide. Instead, refer to the backup and restore documentation provided by your cloud provider, for example, the AWS documentation on backing up and restoring Amazon RDS for PostgreSQL.
復元¶
備考
You must fulfill the prerequisites before proceeding.
The restore process requires you to forward a local port to the remote PostgreSQL service:
export LOCAL_PGSQL_PORT=54321
備考
Define which local port you use by setting the LOCAL_PGSQL_PORT value. This example uses port 54321, but you can use another.
Obtain the PostgreSQL admin user password:
export PGPASSWORD=$(kubectl -n $NAMESPACE get secret pcs-postgresql -o jsonpath='{.data.postgres-password}' | base64 -d)
echo $PGPASSWORD
Forward local port to remote PostgreSQL service deployed in the Kubernetes:
kubectl -n $NAMESPACE port-forward svc/pcs-postgresql --address 127.0.0.1 $LOCAL_PGSQL_PORT:5432 &
Wait a few seconds for the port-forwarding to establish.
Restore all databases from the $BACKUP_LOCATION/pgsql directory, excluding specified system databases.
for db_backup_path in $(find $BACKUP_LOCATION/pgsql -mindepth 1 -maxdepth 1 -type d ! -name postgres ! -name sushihydra ! -name identityresourceservice ! -name cnshydra); do
echo "Restoring database from path: $db_backup_path"
pg_restore -v -Upostgres -hlocalhost -p$LOCAL_PGSQL_PORT -cC -j4 -d postgres "$db_backup_path"
done
After the restore completes, find the process ID of the port-forwarding process:
ps aux | grep -E "port-forwar[d].*$LOCAL_PGSQL_PORT"
Then stop it:
kill PID_OF_THE_KUBECTL_PORT_FORWARD
備考
Replace PID_OF_THE_KUBECTL_PORT_FORWARD with the process ID obtained from the previous command.
Restore PostgreSQL credentials by patching the existing pcs-postgresql secret with data from your backed-up secret file (e.g., ${BACKUP_LOCATION}/secrets/pcs/pcs-postgresql.json):
kubectl -n $NAMESPACE patch secret pcs-postgresql --patch-file="$BACKUP_LOCATION/secrets/pcs/pcs-postgresql.json"