Skip to content

Backup and Restore

sassanix edited this page Oct 30, 2026 · 3 revisions

database icon Backup and Restore

Warracker stores data in two places, and a complete backup covers both:

  1. The PostgreSQL database — all warranties, users, claims, tags, and settings.
  2. The uploads folder — all product photos, invoices, manuals, and other files (/data/uploads inside the container).

Back up a third thing too: your .env file. It holds the database passwords and SECRET_KEY. Store it somewhere safe and private — never in a public repository.

CSV export is a useful extra safety net for warranty data, but it does not include uploaded files, so it is not a substitute for a real backup.

Contents

Backing up the database

From the directory containing your compose file (replace warranty_db, warranty_user, and the container name with your own values from .env if they differ):

docker compose exec warrackerdb pg_dump -U warranty_user warranty_db > warracker-backup.sql

Backing up the uploads

If you use a bind mount (for example, ./uploads next to your compose file), copy that directory:

cp -r uploads uploads-backup

If you use a named volume (warracker_uploads), export it through a throwaway container:

docker run --rm -v warracker_uploads:/data -v "$(pwd)":/backup alpine \
  tar -czf /backup/uploads-backup.tar.gz -C /data .

Automating backups

Schedule both commands with cron (for example, nightly) and keep at least one copy off the machine — a second disk, another computer, or cloud storage. A backup you have never restored is a hope, not a backup: test the restore steps below on a spare setup at least once.

Filesystem or VM snapshots alone are not recommended as your only backup method — they are harder to restore selectively and easier to get subtly wrong.

Restoring

  1. Start a fresh stack (or stop the app container on the existing one):

    docker compose stop warracker
  2. Recreate the empty database and restore the dump into it:

    docker compose exec warrackerdb psql -U warranty_user postgres \
      -c "DROP DATABASE warranty_db;" -c "CREATE DATABASE warranty_db;"
    docker compose exec -T warrackerdb psql -U warranty_user warranty_db < warracker-backup.sql
  3. Restore the uploads folder to its bind mount or volume, then restart the app:

    docker compose up -d warracker

    Database migrations run automatically on startup, so if the backup came from an older version, the database is brought up to date for you.

  4. Log in and spot-check a few warranties, including one with documents attached.

Two things that trip people up

  • SECRET_KEY: if you never set it in .env, the app generated one inside the container, and it is lost when the container is recreated. That only invalidates sessions — your data is unaffected — but users will have to log in again. Setting SECRET_KEY explicitly in .env avoids this entirely. See Configuration.
  • Mismatched names: the database name, user, and volume names in the restore commands must match your own .env and compose file, not the examples above. If a command complains about a missing database or container, check docker compose ps and your .env first.

Clone this wiki locally