Operations

Database Backup and Restore

Daily Postgres backups to S3-compatible object storage and restore commands.

Setup used in this repo

Backup runs as Kamal accessory db_backup with image:

  • eeshugerman/postgres-backup-s3:16

Configured in config/deploy.yml with:

  • SCHEDULE: "@daily"
  • BACKUP_KEEP_DAYS: 7
  • S3_ENDPOINT: https://nbg1.your-objectstorage.com
  • S3_BUCKET: <your-existing-bucket>
  • S3_PREFIX: backups

You can use any S3-compatible storage provider. Create the target bucket before enabling backup jobs.

Secrets used:

  • POSTGRES_PASSWORD
  • S3_ACCESS_KEY_ID
  • S3_SECRET_ACCESS_KEY

Start or restart backup accessory

kamal accessory reboot db_backup

Check backup logs

kamal accessory logs db_backup

Run backup manually

kamal accessory exec db_backup "sh backup.sh"

Restore latest backup

kamal accessory exec db_backup "sh restore.sh"

Warning

Restore is destructive. Run it only when you are sure.

Verify

  • Daily backups are visible in your configured S3 bucket.
  • Backup logs show successful upload.
  • Restore procedure is tested in a non-production environment.

On this page