Periodic PostgreSQL backups to S3, Cloudflare R2 or any S3 compatible storage with Telegram notifications.
Adapted from:
- eeshugerman/postgres-backup-s3 — S3 upload via aws CLI
- prodrigestivill/docker-postgres-backup-local — retention logic
your-bucket/
└── postgres-backups/
└── your-database/
├── daily/
│ ├── yourdb_2026-06-05T02-00-00Z.sql.gz
│ └── yourdb_2026-06-06T02-00-00Z.sql.gz
├── weekly/
│ └── yourdb_2026-06-01T02-00-00Z.sql.gz ← uploaded every Sunday
└── monthly/
└── yourdb_2026-06-01T02-00-00Z.sql.gz ← uploaded on 1st of month- Go to Cloudflare Dashboard → R2 → Create Bucket
- Go to R2 → Manage R2 API Tokens → Create API Token
- Permissions: Object Read & Write
- Scope: your backup bucket
- Note your Account ID, Access Key ID, and Secret Access Key
- Message @BotFather → /newbot
- Copy the bot token
- Add the bot to your group
- Get the chat ID via @userinfobot
- Push this repo to a private GitHub repository
- In Coolify → New Resource → Docker Compose
- Point to your GitHub repo
- Add environment variables from .env.example
- Deploy
After deploying, trigger a manual backup:
docker exec pgphylax /bin/sh /usr/local/bin/backup.sh| Event | Telegram | Sound |
|---|---|---|
| Backup started | ✅ | Silent |
| Backup succeeded | ✅ | Silent |
| Backup failed | ✅ | Audible alert |
# List available backups
aws s3 ls s3://your-bucket/postgres-backups/your-db/daily/ \
--endpoint-url https://your-account-id.r2.cloudflarestorage.com
# Download a backup
aws s3 cp s3://your-bucket/postgres-backups/your-db/daily/your-db_2026-06-05T02-00-00Z.gpg \
./restore.gpg \
--endpoint-url https://your-account-id.r2.cloudflarestorage.com
# Restore
#### Create New Database (Skip if restoring to existing db)
psql -h <postgres-host> -U <postgres-user> -c "CREATE DATABASE <target_db_name>;"
#### Decrypt
gpg --batch --passphrase "your_secure_encryption_password" -d <path/to/backup.dump.gpg> > <path/to/decrypted_backup.dump>
#### Restore Dump File
pg_restore -h <postgres-host> -U <postgres-user> -d <target_db_name> -v <path/to/decrypted_backup.dump>