A lightweight, reliable, and containerized utility to automate PostgreSQL backups and restores to AWS S3, MinIO, Google Cloud Storage, Backblaze B2, or any other cloud storage provider supported by Rclone.
- Automated Backups: Runs backups on a customizable cron schedule.
- Direct Streaming: Streams
pg_dumpdirectly to Rclone's S3 upload (rcat) without saving intermediate dump files to disk, saving space and improving performance. - Easy Restores: Restore your database from the latest backup automatically, or target a specific file.
- Robust Cron Environment: Environment variables are safely propagated to cron jobs.
- Precise PostgreSQL Compatibility: Uses the official
postgres:alpinebase image ensuringpg_dumpandpsqlclients match your database version exactly. - Customizable Rclone Backend: Configure any Rclone-supported backend via Docker environment variables.
The following environment variables can be configured to customize the database connection and S3 backup destination:
| Variable | Description | Default |
|---|---|---|
POSTGRES_HOST |
PostgreSQL server hostname. | localhost |
POSTGRES_PORT |
PostgreSQL server port. | 5432 |
POSTGRES_USER |
PostgreSQL username. | postgres |
POSTGRES_PASSWORD |
PostgreSQL password. | postgres |
POSTGRES_DATABASE |
PostgreSQL database name to back up. | postgres |
BUCKET_NAME |
S3 bucket name. | backups |
BACKUP_SCHEDULE |
Cron schedule for automated backups. | 0 1 * * * (Daily at 1:00 AM) |
RCLONE_CONFIG_REMOTE_TYPE |
Rclone backend type (e.g. s3, gcs, b2, etc.) |
s3 |
RCLONE_CONFIG_REMOTE_PROVIDER |
Rclone S3 provider (e.g. Minio, AWS, etc.) |
Minio |
RCLONE_CONFIG_REMOTE_ENDPOINT |
Endpoint URL of the storage provider. | http://minio:9000 |
RCLONE_CONFIG_REMOTE_ACCESS_KEY_ID |
Storage access key ID. | minioadmin |
RCLONE_CONFIG_REMOTE_SECRET_ACCESS_KEY |
Storage secret access key. | minioadmin |
Add the backup service to your docker-compose.yml:
services:
postgres:
image: postgres:17-alpine
environment:
POSTGRES_PASSWORD: secret_password
POSTGRES_USER: pg_user
POSTGRES_DB: main_db
backup:
image: ghcr.io/minibikini/postgres-backup-rclone:latest
environment:
POSTGRES_HOST: postgres
POSTGRES_PORT: 5432
POSTGRES_USER: pg_user
POSTGRES_PASSWORD: secret_password
POSTGRES_DATABASE: main_db
BUCKET_NAME: my-app-backups
BACKUP_SCHEDULE: "0 */6 * * *" # Every 6 hours
RCLONE_CONFIG_REMOTE_TYPE: s3
RCLONE_CONFIG_REMOTE_PROVIDER: AWS
RCLONE_CONFIG_REMOTE_ACCESS_KEY_ID: YOUR_AWS_KEY
RCLONE_CONFIG_REMOTE_SECRET_ACCESS_KEY: YOUR_AWS_SECRET
depends_on:
postgres:
condition: service_healthyYou can trigger manual backups and restores using docker compose run:
docker compose run --rm backup backup.shThis generates a backup file with the format: ${POSTGRES_DATABASE}-YYYY-MM-DD-HH-MM-SS.sql.gz.
docker compose run --rm backup restore.shThis automatically fetches the newest .sql.gz file from your bucket and streams it into the database.
docker compose run --rm backup restore.sh main_db-2026-07-11-10-30-00.sql.gzThis project uses BATS (Bash Automated Testing System) for integration tests.
Ensure you have Node.js installed, then run:
npm install
npm testThe integration tests will spin up PostgreSQL, MinIO, and the Backup container via Docker Compose, perform manual backups, verify files in MinIO, execute restores, and validate the automated cron backup functionality.
This project is licensed under the MIT License - see the LICENSE file for details.