Postgres Backup to S3
Docker Compose: pg_dump cron container that dumps, compresses, encrypts with GPG, and ships backups to S3 on a configurable schedule with retention management.
Postgres Backup to S3
A lightweight Docker Compose service that adds automated, encrypted Postgres backups to any stack. A cron container runs pg_dump on your schedule, compresses with gzip, encrypts with GPG, and uploads to S3. A separate retention script prunes old backups automatically.
What's Included
- pg_dump Cron Container — Debian-slim image with pg_dump, gzip, GPG, and the AWS CLI; runs on a cron schedule you set in
.env - GPG Encryption — backups encrypted at rest with a public key you supply; only recoverable with your private key
- S3 Upload — uploads via the AWS CLI with configurable bucket, prefix, and storage class
- Retention Management — companion script that deletes S3 objects older than a configurable number of days
- Restore Script — documented restore procedure: download from S3, decrypt, decompress, restore with psql
What You Get
docker-compose.yml— drop-in sidecar service; add it to your existing stack or run standaloneDockerfile— backup container image definitionentrypoint.sh— backup script (dump → compress → encrypt → upload)scripts/retention.sh— S3 retention management scriptscripts/restore.sh— documented restore procedure.env.example— all variables documented with sensible defaultsREADME.md— setup guide, restore walkthrough, and cron schedule examples
Requirements
Docker Engine, an existing Postgres instance (local container or remote), an S3 bucket, an IAM user with s3:PutObject and s3:DeleteObject permissions, and a GPG key pair for encryption.