Backups
Database dumps and restore procedures for the Sancho Docker Compose deployment. Persistent state lives under ./data/ next to the compose file — see Persistent data.
Automated Postgres backup to S3
Section titled “Automated Postgres backup to S3”The postgres-backup service is optional — it is defined in docker-compose.yaml but only starts when the backup Compose profile is active. To enable, add to .env:
COMPOSE_PROFILES=backup # or backup,garageThen docker compose up -d. Without that, BACKUP_S3_BUCKET is ignored and no dumps run. If you operate Postgres backups out-of-band (host-level snapshot, managed Postgres replica, etc.), leave the profile off.
The service (image: prodrigestivill/postgres-backup-local:18-s3) runs pg_dump daily at 02:00 UTC, gzips the dump, and uploads it to S3 using the same credentials configured for the api (S3_ENDPOINT, S3_API_KEY, S3_API_SECRET).
- Destination: the
${BACKUP_S3_BUCKET}bucket, dumps underdaily/,weekly/,monthly/subfolders. Dumps usepg_dump’s custom format (--format=custom) — restore withpg_restore. - Retention: 28 daily, 4 weekly, and 4 monthly backups (
BACKUP_KEEP_DAYS=28,BACKUP_KEEP_WEEKS=4,BACKUP_KEEP_MONTHS=4). Older dumps are pruned automatically. - Requirement:
BACKUP_S3_BUCKETmust be set in.envand the bucket must exist (on external S3, pre-create it; on Garage, see the Aside above). The service crash-loops with a clear error if the bucket is missing or the credentials are wrong. - Logs:
docker compose logs -f postgres-backup— each run reports size, duration, and pruning.
To verify a backup worked without waiting until 02:00, force one on demand:
docker compose exec postgres-backup /backup.shAd-hoc / full backup
Section titled “Ad-hoc / full backup”# Database dump to a local filedocker compose exec postgres pg_dump -U $PG_USER $PG_DB | gzip > "sancho-$(date +%F).sql.gz"
# Full data tree (postgres + rabbitmq + redis + caddy state)sudo tar -czf "sancho-data-$(date +%F).tar.gz" data/Also back up your S3 bucket contents (the api’s buckets) — handled by your storage provider.
Restore
Section titled “Restore”Fetch the dump from S3 (any S3 client works), then apply it to the database:
mc cp <alias>/$BACKUP_S3_BUCKET/daily/sancho-YYYY-MM-DD.sql.gz ./gunzip -c sancho-YYYY-MM-DD.sql.gz | docker compose exec -T postgres pg_restore -U $PG_USER -d $PG_DB --clean --if-existsgunzip -c sancho-YYYY-MM-DD.sql.gz | docker compose exec -T postgres psql -U $PG_USER $PG_DBStop the stack before restoring:
docker compose downsudo tar -xzf sancho-data-YYYY-MM-DD.tar.gzdocker compose up -d