Sign inSign up

lifely/postgres-backup

By lifely

•Updated over 7 years ago

This container will make a backup of PostgreSQL and backup to S3.

Image
0

488

lifely/postgres-backup repository overview

⁠Postgres backup container

This container will make a pg_dump backup of the given PostgreSQL host (default: postgres:5432). Then it'll push the backup to S3 in a gzipped file (e.g. "backup-2018-05-25-10-10-02.sql.gz").

Currently using Postgres 10 and the official AWS CLI (installed with pip).

Somewhat inspired by schickling/postgres-backup-s3⁠.

⁠Usage

Run the docker container:

docker run \
    --link <postgres container> \
    --env AWS_ACCESS_KEY_ID= \
    --env AWS_SECRET_ACCESS_KEY= \
    --env AWS_S3_BUCKET= \
    --env POSTGRES_DB=postgres \
    --env POSTGRES_USER=postgres \
    --env POSTGRES_PASSWORD=secret \
    lifely/postgres-backup-container

The variables AWS_S3_PREFIX, AWS_S3_BACKUP_NAME, AWS_S3_ENABLE_VERSIONING, AWS_S3_LIFECYLCE_CONFIGURATION, AWS_REGION, AWS_SSE_KEY POSTGRES_HOST, POSTGRES_PORT, POSTGRES_EXTRA_OPTS and SCHEDULE are optional:

docker run \
    --link <postgres container> \
    --env AWS_ACCESS_KEY_ID= \
    --env AWS_SECRET_ACCESS_KEY= \
    --env AWS_S3_BUCKET= \
    --env AWS_S3_PREFIX= \
    --env AWS_S3_BACKUP_NAME= \
    --env AWS_S3_ENABLE_VERSIONING= \
    --env AWS_S3_LIFECYLCE_CONFIGURATION= \
    --env AWS_REGION=eu-west-1 \
    --env AWS_SSE_KEY= \
    --env POSTGRES_DB=postgres \
    --env POSTGRES_HOST=postgres \
    --env POSTGRES_PORT=5432 \
    --env POSTGRES_USER=postgres \
    --env POSTGRES_PASSWORD=secret \
    --env POSTGRES_EXTRA_OPTS= \
    --env SCHEDULE: '0 * * * *' \
    lifely/postgres-backup-container

When passing the AWS_S3_BACKUP_NAME variable, the backup will be stored in $AWS_S3_BUCKET/$AWS_S3_PREFIX/$AWS_S3_BACKUP_NAME otherwise a filename will be generated: $AWS_S3_BUCKET/$AWS_S3_PREFIX/backup-%Y-%m-%d-%H-%M-%S

⁠Docker compose

Docker compose will start a postgres container exposing port 5432 and a backup container that will run the backup script. Don't forget to set the AWS credentials.

⁠Automatic Periodic Backups

You can set the SCHEDULE environment variable like -e SCHEDULE="0 * * * *" (hourly) to run the backup automatically. This uses regular cron syntax: minute hour day-of-month month day-of-week

⁠AWS SSE

The AWS_SSE_KEY should be a string of exactly 32 characters⁠.

⁠AWS Versioning

To set the versioning state, you must be the bucket owner⁠.

Tag summary

Content type

Image

Digest

Size

85.3 MB

Last updated

over 7 years ago

docker pull lifely/postgres-backup