A Docker-based solution for automated PostgreSQL database backups to S3-compatible storage services. This tool provides a simple way to schedule and manage database backups with automatic cleanup of old backup files.
Inspired by pg-dump-to-s3
- Automated PostgreSQL database backups
- Support for multiple databases
- S3-compatible storage support
- Automatic cleanup of old backups
- Configurable retention period
- Docker-based for easy deployment
- Docker
- S3-compatible storage access (AWS S3, CloudHost, etc.)
- PostgreSQL database access
- Build the Docker image:
docker build -t pg-dump-to-s3-v1 .- Run the backup container:
docker run \
-e AWS_ACCESS_KEY_ID=your_access_key \
-e AWS_SECRET_ACCESS_KEY=your_secret_key \
-e AWS_ENDPOINT_URL=your_s3_endpoint \
-e S3_PATH=your/backup/path \
-e DELETE_AFTER="7 days" \
-e PG_DATABASES=database1,database2 \
-e PG_PATH=postgresql://user:password@host:port \
pg-dump-to-s3-v1or if you want to use the latest image from docker hub:
sudo docker run \
-e AWS_ACCESS_KEY_ID=your_access_key \
-e AWS_SECRET_ACCESS_KEY=your_secret_key \
-e AWS_ENDPOINT_URL=your_s3_endpoint \
-e S3_PATH=your/backup/path \
-e DELETE_AFTER="7 days" \
-e PG_DATABASES=database1,database2 \
-e PG_PATH=postgresql://user:password@host:port \
putrafirman/pg-auto-backup-to-s3:latest| Variable | Description | Example |
|---|---|---|
AWS_ACCESS_KEY_ID |
S3 access key | AKIAXXXXXXXX |
AWS_SECRET_ACCESS_KEY |
S3 secret key | xxxxxxxxxxxxxxxx |
AWS_ENDPOINT_URL |
S3-compatible endpoint URL | https://s3.amazonaws.com |
S3_PATH |
Backup destination path in S3 | bucket/backup/path |
DELETE_AFTER |
Retention period for backups | 7 days |
PG_DATABASES |
Comma-separated list of databases to backup | db1,db2,db3 |
PG_PATH |
PostgreSQL connection string | postgresql://user:pass@host:5432 |
- The script connects to the specified PostgreSQL database(s)
- Creates a dump file for each database
- Uploads the dump files to the specified S3 path
- Removes local dump files after successful upload
- Cleans up old backup files based on the retention period
Backup files are named using the following format:
YYYY-MM-DD-at-HH-MM-SS_database-name.dump
- Store sensitive credentials securely
- Use environment variables for configuration
- Ensure proper S3 bucket permissions
- Use secure PostgreSQL connection strings
This project is not-so-open-source. Feel free to use and modify as needed.