Supaffi

Self-hosting/Backups

Backups

Back up the database and the encryption key, and keep them apart.

Everything Supaffi knows is in one PostgreSQL database: products, affiliates, clicks, commissions and payouts. Two things need backing up: that database, and the key that decrypts the Stripe keys inside it.

Backups before updates

Every update dumps the database to /opt/supaffi/backups before it changes anything, as supaffi-YYYYMMDD-HHMMSS.sql.gz (UTC time). The folder and the files are readable by root only. If the dump fails, the update stops.

Older dumps are kept, so delete the ones you no longer need. These dumps sit on the same disk as the database and do not survive a dead server.

Off-server backups

Dump the database on a schedule and copy the file off the server. The dump command:

Terminal
docker compose exec -T db pg_dump -U supaffi supaffi | gzip > supaffi.sql.gz

For example, a daily dump at 03:00 in root's crontab (sudo crontab -e):

crontab
0 3 * * * cd /opt/supaffi && docker compose exec -T db pg_dump -U supaffi supaffi | gzip > /var/backups/supaffi-$(date +\%F).sql.gz

Then copy /var/backups to storage on another machine with the tool you already use, and prune old files.

The encryption key

MASTER_ENCRYPTION_KEY in /opt/supaffi/.env decrypts every Stripe key and webhook signing secret in the database. Keep a copy off the server, stored apart from the database dumps.

A password manager or a secrets vault is a good home for it.

Restore a backup

Run these as root from /opt/supaffi. Restoring replaces the whole database, so take a fresh dump first if the current data matters.

  1. Stop the app

    Terminal
    cd /opt/supaffi && docker compose stop app
  2. Empty the database

    Terminal
    docker compose exec -T db dropdb -U supaffi supaffi
    docker compose exec -T db createdb -U supaffi supaffi
  3. Load the dump

    Terminal
    gunzip -c backups/supaffi-20261020-030000.sql.gz | docker compose exec -T db psql -q -U supaffi -d supaffi
  4. Start the app

    Terminal
    docker compose up -d

    Any migrations the dump is missing run as the app starts.

On a new server, install the same Supaffi version, replace MASTER_ENCRYPTION_KEY in its .env with your saved one, then follow the steps above. Point each product's DNS record at the new server's address.

Data retention

  • Stripe events are kept for 90 days after they are processed, then deleted by a daily cleanup. Commissions, clicks, affiliates and payouts are kept.
  • Deleting a product deletes its affiliates, links, clicks and commissions. There is no undo, other than restoring a backup.

To restore after a downgrade, see Downgrade.