Skip to content

Backup and restore

Back up the metadata database and the attachment bucket as one logical unit. A database restore without the matching objects leaves attachment metadata pointing at missing bytes; a bucket restore without the database loses the review and audit context.

  • Metadata — Postgres database or SQLite file. Includes tenants, users, API keys, towns, parcels, captures, attachments, audit events, sessions, rate-limit counters, retention settings, webhook endpoints, and deliveries.
  • Attachments — S3-compatible bucket or local attachment directory.
  • Configuration — environment variables and secret references, not their values, in your secret manager or deployment configuration.
  • Backup keys — the encryption keys or KMS configuration needed to restore.

Use a consistent logical dump:

Terminal window
pg_dump --format=custom --no-owner --file=commitment-desk.dump "$DATABASE_URL"
pg_restore --clean --if-exists --no-owner --dbname "$RESTORE_DATABASE_URL" commitment-desk.dump

For larger deployments, use your provider’s continuous backup or snapshot capability and verify point-in-time recovery. A snapshot must be taken with the bucket snapshot or at least a known bucket version.

Stop the API or use SQLite’s online backup command. Copy the database and any -wal/-shm files together, or checkpoint first:

Terminal window
sqlite3 .data/commitment-desk.sqlite "PRAGMA wal_checkpoint(TRUNCATE);"
cp .data/commitment-desk.sqlite backup/commitment-desk-$(date +%F).sqlite

Do not copy only the main file while the service is writing unless you also capture the WAL.

Use versioning and replication where available, and copy the bucket with the tool for your provider:

Terminal window
aws s3 sync s3://commitment-desk-attachments backup/attachments --endpoint-url "$S3_ENDPOINT"

The bucket contains tenant-scoped keys. Preserve key names exactly; restoring into a different prefix will break attachment metadata.

Archive the attachment directory with the database backup:

Terminal window
tar -czf backup/attachments-$(date +%F).tar.gz -C .data attachments
  1. Stop the API so no writes occur.
  2. Restore the metadata database into an empty database.
  3. Restore the attachment bucket or directory with the same keys.
  4. Set the same WEB_BASE_URL, storage driver, and bucket settings.
  5. Start the API and confirm GET /v1/health returns ok.
  6. Sign in with a synthetic reviewer where available and confirm capture lists, detail, attachments, and audit events load.
  7. Run the shared contract suite against a restored staging copy when possible.
Terminal window
DATABASE_URL=postgres://... pnpm --filter @commitment-desk/api-node migrate
pnpm --filter @commitment-desk/api-node test
  • Health endpoint responds.
  • A capture detail loads and its attachment metadata matches an object in the bucket.
  • Audit events are present and ordered.
  • Exports return the expected capture count.
  • Webhook endpoints and delivery history are present.
  • Deleted or expired captures remain absent from lists and exports.
  • Secrets and API keys still authenticate; revoke and reissue any key exposed during recovery.

Backups contain sensitive data. Encrypt them, restrict access, and apply a retention period that matches the tenant policy. Deleted live data may remain in older backups; document that in the operator’s retention policy and rotate backups accordingly.

If a restore fails verification, keep the failed environment isolated, restore the previous backup set, and compare counts before reopening the service. Do not partially restore attachments into a live bucket.