This docker image backup and encrypt PostgreSQL database to S3/Minio periodically.
docker run -d --restart unless-stopped \
--name postgres_backup \
-e AWS_ACCESS_KEY_ID="your-access-key" \
-e AWS_SECRET_ACCESS_KEY="your-secret-access-keys" \
-e PGP_KEY=YOUR_PGP_PUBLIC_KEY \
-e BACKUP_SCHEDULE="0 * * * *" \
-e POSTGRES_DB=your-dbname \
-e POSTGRES_HOST=your-postgres-container \
-e POSTGRES_USER=your-postgres-username \
-e POSTGRES_PASSWORD="your-postgres-password" \
--network your-network \
chaifeng/postgres-backup-s3-gpg
docker run -d --restart unless-stopped \
--name postgres_backup \
-e AWS_ENDPOINT="https://your.minio.server.example.com" \
-e AWS_ACCESS_KEY_ID="your-access-key" \
-e AWS_SECRET_ACCESS_KEY="your-secret-access-keys" \
-e PGP_KEY=YOUR_PGP_PUBLIC_KEY \
-e BACKUP_SCHEDULE="0 * * * *" \
-e POSTGRES_DB=your-dbname \
-e POSTGRES_HOST=your-postgres-container \
-e POSTGRES_USER=root \
-e POSTGRES_PASSWORD="your-postgres-password" \
--network your-network \
chaifeng/postgres-backup-s3-gpg
docker run -d --restart unless-stopped \
--name postgres_backup \
-e AWS_ACCESS_KEY_ID="your-access-key" \
-e AWS_SECRET_ACCESS_KEY="your-secret-access-keys" \
-v /path/to/your/pgp-key.txt:/pgp.txt \
-e PGP_KEY=/pgp.txt \
-e BACKUP_SCHEDULE="0 * * * *" \
-e POSTGRES_DB=your-dbname \
-e POSTGRES_HOST=your-postgres-container \
-e POSTGRES_USER=your-postgres-username \
-e POSTGRES_PASSWORD="your-postgres-password" \
--network your-network \
chaifeng/postgres-backup-s3-gpg
docker run -d --restart unless-stopped \
--name postgres_backup \
-e AWS_ACCESS_KEY_ID="your-access-key" \
-e AWS_SECRET_ACCESS_KEY="your-secret-access-keys" \
-e PGP_KEY=https://exaple.com/pgp-key.txt \
-e BACKUP_SCHEDULE="0 * * * *" \
-e POSTGRES_DB=your-dbname \
-e POSTGRES_HOST=your-postgres-container \
-e POSTGRES_USER=your-postgres-username \
-e POSTGRES_PASSWORD="your-postgres-password" \
chaifeng/postgres-backup-s3-gpg
AWS_ACCESS_KEY_ID
Access KeyAWS_SECRET_ACCESS_KEY
Securet Access KeyPGP_KEY
Your PGP public key ID, used to encrypt your backupsPOSTGRES_HOST
the host/ip of your postgres databasePOSTGRES_DB
the database name to dump.POSTGRES_USER
the username of your postgres databasePOSTGRES_PASSWORD
the password of your postgres database
AWS_DEFAULT_REGION
us-east-1
by defaultAWS_ENDPOINT
Customize this variable if you are using Minio, the url of your Minio serverPGP_KEYSERVER
the PGP key server used to retrieve you PGP public keyBACKUP_SCHEDULE
the interval of cron job to run postgresdump.0 0 * * *
by defaultBACKUP_BUCKET
the bucket of your S3/MinioBACKUP_PREFIX
the default value ispostgres/%Y/%m/%d/postgres-
, please see the strftime(3) manual pageBACKUP_SUFFIX
the default value is-%Y%m%d-%H%M.sql.gz.gpg
, please see the strftime(3) manual page
gpg --decrypt your-backup.gpg
aws s3 cp s3://your-bucket/path/to/your/backup.gpg - | gpg --output backup.sql --decrypt
mc cat minio/your-bucket/path/to/your/backup.gpg | gpg --output backup.sql --decrypt