Skip to content

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.

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:

Terminal window
COMPOSE_PROFILES=backup # or backup,garage

Then 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 under daily/, weekly/, monthly/ subfolders. Dumps use pg_dump’s custom format (--format=custom) — restore with pg_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_BUCKET must be set in .env and 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:

Terminal window
docker compose exec postgres-backup /backup.sh
Terminal window
# Database dump to a local file
docker 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.

Fetch the dump from S3 (any S3 client works), then apply it to the database:

Terminal window
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-exists