pgDump & pgRestore

pgDump & pgRestore Examples

The following examples will demonstrate how the crunchy-pgdump container can be utilized to create a database backup using the pg_dump utility, while also demonstrating how the backup created can then be utilized to restore the database using the pg_restore utility.

Backup (pg_dump)

The script assumes you are going to backup the primary example and that container is running.

This example assumes you have configured a storage filesystem as described in the Storage Configuration document.

A successful backup will perform pg_dump/pg_dumpall on the primary and store the resulting files in the mounted volume under a directory named <HOSTNAME>-backups as a sub-directory, then followed by a unique backup directory based upon a date and timestamp - allowing any number of backups to be kept.

For more information on how to configure this container, please see the Container Specifications document.

To shutdown the instance and remove the container for each example, run the following:

./cleanup.sh

Docker

Run the backup with this command:

cd $CCPROOT/examples/docker/pgdump/backup
./run.sh

Kubernetes and OpenShift

Running the example:

cd $CCPROOT/examples/kube/pgdump/backup
./run.sh

The Kubernetes Job type executes a pod and then the pod exits. You can view the Job status using this command:

${CCP_CLI} get job

The pgdump.json file within that directory specifies options that control the behavior of the pgdump job. Examples of this include whether to run pg_dump vs pg_dumpall and advanced options for specific backup use cases.

Restore (pg_restore)

The script assumes that the pg_dump backup example above has been run. Therefore, the primary example should still be running and pg_dump backup should have been successfully created.

This example assumes you have configured a storage filesystem as described in the Storage Configuration document.

Successful use of the crunchy-pgrestore container will run a job to restore files generated by pg_dump/pg_dumpall to a container via psql/pg_restore; then container will terminate successfully and signal job completion.

For more information on how to configure this container, please see the Container Specifications document.

To shutdown the instance and remove the container for each example, run the following:

./cleanup.sh

Docker

Run the restore with this command:

cd $CCPROOT/examples/docker/pgdump/pgrestore
./run.sh

Kubernetes and OpenShift

By default, the crunchy-pgrestore container will automatically restore from the most recent backup. If you want to restore to a specific backup, edit the pgrestore.json file and update the PGRESTORE_BACKUP_TIMESTAMP setting to specify the backup path you want to restore with. For example:

"name":"PGRESTORE_BACKUP_TIMESTAMP",
"value":"2018-03-27-14-35-33"

Running the example:

cd $CCPROOT/examples/kube/pgdump/pgrestore
./run.sh

The Kubernetes Job type executes a pod and then the pod exits. You can view the Job status using this command:

${CCP_CLI} get job

The pgrestore.json file within that directory specifies options that control the behavior of the pgrestore job.