Backup PostgreSQL 13 to S3 (supports periodic backups)
Docker:
$ docker run -e S3_ACCESS_KEY_ID=key -e S3_SECRET_ACCESS_KEY=secret -e S3_BUCKET=my-bucket -e S3_PREFIX=backup -e POSTGRES_DATABASES=dbname -e POSTGRES_USER=user -e POSTGRES_PASSWORD=password -e POSTGRES_HOST=localhost dzangolab/postgres-13-backup-s3
Docker Compose:
postgres:
image: postgres:13
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: password
pgbackups3:
image: dzangolab/postgres-13-backup-s3
links:
- postgres
environment:
SCHEDULE: '@daily'
S3_REGION: region
S3_ACCESS_KEY_ID: key
S3_SECRET_ACCESS_KEY: secret
S3_BUCKET: my-bucket
S3_PREFIX: backup
POSTGRES_DATABASES: dbname
POSTGRES_USER: user
POSTGRES_PASSWORD: password
POSTGRES_EXTRA_OPTS: '--schema=public --blobs'
ENCRYPTION_PASSWORD if not empty, backups will be encrypted using this passwordPOSTGRES_DATABASES list of databases you want to backup. ALL to backup all databases requiredPOSTGRES_EXTRA_OPTS pg_dump options (default: '')POSTGRES_HOST the postgres host requiredPOSTGRES_PORT the postgres port (default: 5432)POSTGRES_USER the postgres user requiredPOSTGRES_PASSWORD the postgres password requiredPOSTGRES_PASSWORD_FILE path to file containing the postgres password; alternative to POSTGRES_PASSWORDS3_ACCESS_KEY_ID your AWS access key requiredS3_ACCESS_KEY_ID_FILE path to file containing your AWS access key; alternative to S3_ACCESS_KEY_IDS3_SECRET_ACCESS_KEY your AWS secret key requiredS3_SECRET_ACCESS_KEY_FILE path to file containing your AWS secret key; alternative to S3_SECRET_ACCESS_KEYS3_BUCKET your AWS S3 bucket path requiredS3_PREFIX path prefix in your bucketS3_REGION the AWS S3 bucket region (default: us-west-1)S3_ENDPOINT the AWS Endpoint URL, for S3 Compliant APIs such as minio (default: none)S3_S3V4 set to yes to enable AWS Signature Version 4, required for minio servers (default: no)SCHEDULE backup schedule time, see explanations belowYou can additionally set the SCHEDULE environment variable like -e SCHEDULE="@daily" to run the backup automatically.
More information about the scheduling can be found here.
Run restore.sh inside the container, passing either the name of a database (to restore its most recent backup) or an explicit S3 key:
$ docker exec -it <container> sh restore.sh dbname
$ docker exec -it <container> sh restore.sh dbname/2026/06/dbname.2026-06-21T00:52:18Z.sql.gz
The argument is treated as an S3 key if it ends in .sql, .sql.gz, .sql.enc, or .sql.gz.enc; otherwise it is treated as a database name and the most recent backup for that database is located automatically, using the same naming convention backup.sh writes (<db>/<year>/<month>/<db>[.version].<timestamp>.sql.gz[.enc]).
The backup is downloaded, decrypted (if ENCRYPTION_PASSWORD is set and the file ends in .enc), decompressed (if .gz), and restored into the database named by the leading path segment of the backup key with psql.
Content type
Image
Digest
sha256:41a2fdfe4…
Size
205.1 MB
Last updated
about 2 months ago
docker pull dzangolab/postgres-13-backup-s3:1.0.0-beta3