Skip to content

Backups and file storage

Tradehall keeps two kinds of data: the database (PostgreSQL, or SQLite as sqlite.md describes), which holds every record, and uploaded files, such as ticket attachments. Both can go to an S3-compatible bucket, so losing the server loses neither.

Any S3-compatible service works: Amazon S3, Cloudflare R2, Backblaze B2, DigitalOcean Spaces, MinIO, RustFS, Garage. Create a bucket and an access key that can read, write, list, and delete in it, then either:

  • fill in Settings > File storage and press Test connection (the secret is stored encrypted with APP_KEY), or
  • set it in the environment, which wins over the settings page and locks it there:
Variable Example Notes
TRADEHALL_S3_BUCKET acme-tradehall Setting this turns the environment bucket on
TRADEHALL_S3_ENDPOINT https://<account>.r2.cloudflarestorage.com Empty for Amazon S3
TRADEHALL_S3_REGION auto auto for R2; defaults to auto with an endpoint
TRADEHALL_S3_ACCESS_KEY_ID / TRADEHALL_S3_SECRET_ACCESS_KEY Empty on AWS to use the server’s IAM role
TRADEHALL_S3_PATH_STYLE true MinIO, RustFS, and Garage need it
TRADEHALL_S3_PREFIX tradehall A folder for everything Tradehall writes, so one bucket can serve several installs
TRADEHALL_UPLOADS bucket Where uploads go: local or bucket

Use the environment when backups go to the bucket. Restoring onto a new server needs the bucket before there’s a database to read the settings page from. At the least, keep a copy of the bucket details and APP_KEY somewhere outside Tradehall, such as a password manager.

Inside the bucket, uploads live under <prefix>/files/ and backups under <prefix>/backups/. Turning on object versioning or a lifecycle rule in the bucket is a good second line of defence.

Uploads go to the storage volume (storage/app/files) until you switch them to the bucket on the settings page. After the switch, new files go to the bucket and older files keep opening from the volume. Copy them to the bucket on the settings page (or tradehall files:copy-to-bucket) moves the rest, so you can drop the volume later.

Hosting platforms without a persistent disk (Render’s free plan, Fly.io without a volume) lose the storage volume on every deploy, so use a bucket there.

Files are always served through Tradehall, which checks who is asking: staff with the ticket permission, or the ticket’s own client contacts (never for internal notes). Buckets can and should stay private.

Backups are on by default: every day at 08:00 UTC, to the storage volume, keeping the newest 7. Change that on Settings > Backups, where you can also back up now, download or delete a backup, and see the last ten attempts with their errors. A failed backup shows a warning on the dashboard for anyone who can manage storage (system.storage).

Each backup is a pg_dump of the whole database in PostgreSQL’s custom format (compressed), named like tradehall-2026-12-06-080000-v0.1.0.dump. The scheduler queues one when it’s due and the queue worker makes it, so both must be running. After each backup Tradehall deletes the oldest beyond the number to keep.

On SQLite, a backup is a gzipped copy of the database file, ...sqlite.gz, and needs no other tools; sqlite.md has the details.

The image ships the PostgreSQL 19 client tools, which back up every server up to 19. Running Tradehall outside the image, install pg_dump, pg_restore, and psql at least as new as the server, or point TRADEHALL_PG_BIN at the folder that holds them. A backup of a newer server than the tools fails with a message saying so.

A database backup needs APP_KEY to be useful: saved secrets (2FA, Stripe, the bucket secret) are encrypted with it.

From the command line:

Terminal window
tradehall backup:run # back up now, to where the schedule says
tradehall backup:run --to bucket # or pick the place
tradehall backup:list # backups in the volume and the bucket

Restoring replaces every record, so it’s a command, not a button. Stop the worker and scheduler first so nothing writes during the restore:

Terminal window
docker compose stop worker scheduler
docker compose exec app tradehall backup:restore tradehall-2026-12-06-080000-v0.1.0.dump
docker compose restart

Tradehall looks for the name in the volume, then the bucket (--from local|bucket to choose), and asks before going ahead (--force skips the question). It first saves the current database as a ...-before-restore.dump in the volume (--no-backup skips it; the newest three are kept), then restores in one transaction: if anything fails, the database is left as it was. Restarting runs any migrations newer than the backup.

A backup you downloaded restores with --file:

Terminal window
docker compose cp ./tradehall-2026-12-06-080000-v0.1.0.dump app:/tmp/restore.dump
docker compose exec app tradehall backup:restore --file /tmp/restore.dump
  1. Install Tradehall with the old APP_KEY and, if the backup is in a bucket, the TRADEHALL_S3_* variables. Set SEED_DEMO_DATA=false.
  2. Start it once, so the database exists, then stop the worker and scheduler.
  3. Run tradehall backup:list to find the newest backup, and tradehall backup:restore NAME --force.
  4. Restart. Uploads in the bucket open as before; uploads that were only in the old server’s volume are gone, which is why the bucket is worth it.

Kubernetes: kubectl exec deploy/tradehall -- tradehall backup:restore NAME --force with the worker and scheduler scaled to zero.