Sign inSign up

xsystems/postgres-gs-restore

By xsystems

Updated about 6 years ago

Service to one-off restore a PostgreSQL database backup from a Google Storage Bucket

Image
0

1.0K

xsystems/postgres-gs-restore repository overview

xSystems PostgreSQL Google Storage Restore

Service to one-off restore a PostgreSQL database backup from a Google Storage Bucket

Usage

Run

Create a GCP service account and create a key for that service account. Next, assign the service account the role Storage Admin w.r.t. the Google Cloud Storage bucket.

Create a PostgreSQL password file, matching your database's configuration AND environment variables mentioned later on.

NOTE: Make sure that, on Unix systems, the permissions on both before mentioned credential files are set to 0400. For example, to achieve this run: chmod 0400 gcp-credentials.json .pgpass

When running a container of this image you MUST mount both before mentioned credentials under /run/secrets/ inside the container. That is, the following files MUST be available inside the container:

  • /run/secrets/gcp-credentials.json
  • /run/secrets/.pgpass

This can either be achieved using Docker Volumes or Docker Secrets.

Also, when running a container of this image you MUST specify the environment variables GCP_PROJECT, GCP_BUCKET, POSTGRES_DATABASE. Other environment variables are available, but are optional.

All available environment variables are:

Environment VariableDefault ValueRequiredDescription
GCP_BUCKETThe Google Cloud Storage Bucket name
GCP_PROJECTThe Google Cloud Project ID of the project the Google Cloud Storage Bucket is part of
POSTGRES_DATABASEThe PostgreSQL database. Should match the .pgpass file mentioned above
POSTGRES_HOST172.18.0.1The PostgreSQL hostname. Should match the .pgpass file mentioned above
POSTGRES_PORT5432The PostgreSQL port. Should match the .pgpass file mentioned above
POSTGRES_USERpostgresThe PostgreSQL username. Should match the .pgpass file mentioned above

NOTE: A backup file with the name ${POSTGRES_DATABASE}.gz is expected in the specified Google Storage Bucket called.

NOTE: It is required that BOTH the backup AND database exist.

Example

This image can be used as follows:

docker run  --tty \
            --interactive \
            --rm \
            --env GCP_PROJECT=<REPLACE_WITH_PROJECT_NAME> \
            --env GCP_BUCKET=<REPLACE_WITH_BUCKET_NAME> \
            --env POSTGRES_DATABASE=<REPLACE_WITH_DATABASE_NAME> \
            --volume `pwd`/gcp-credentials.json:/run/secrets/gcp-credentials.json \
            --volume `pwd`/.pgpass:/run/secrets/.pgpass \
            xsystems/postgres-gs-restore

Build the Image

Run build.sh to build an image of the current codebase state with tag latest.

Release the Image

  1. Set the VERSION environment variable to the version that needs to be released.
  2. Optionally, set the COMMIT environment variable to the hash of the Git commit that needs to be released. It defaults to the latest commit.
  3. Run release.sh.

Example release statement:

VERSION=1.3.42 ./release.sh

Tag summary

Content type

Image

Digest

Size

172 MB

Last updated

about 6 years ago

docker pull xsystems/postgres-gs-restore