/ self-hosting / backup ← self-hosting

Backups and restore

The whole server is one SQLite file in one volume. That makes backups cheap enough that there is no excuse, and it makes exactly one mistake fatal: copying that file while the server is running.

What is actually on disk

Path in the volumeWhat it is
/data/yap.dbAccounts, spaces, channels, messages, roles, invites, API key hashes. Everything.
/data/yap.db-walWrite-ahead log. The server runs SQLite in WAL mode, so recent commits live here until they are checkpointed into the main file.
/data/yap.db-shmShared-memory index for the WAL. Not worth keeping, but it must be deleted along with an old WAL if you restore one.
/data/yap.db.signup-keyThe HMAC key behind the per-address sign-up counter. Losing it does not lose accounts; it resets the cap. Keep it anyway so the cap stays honest across a restore.

Why "copy the .db" is not a backup

In WAL mode the main file is not the current database on its own: a chunk of what people just wrote is in yap.db-wal. A copy of yap.db taken from a running server can therefore be missing the last minutes of messages, and can be a torn view of a transaction caught mid-write.

Two honest ways out: stop the server, or ask SQLite to write a consistent copy for you.

The simple one: stop, archive, start

cd Yap/deploy
docker compose stop yap
docker run --rm -v yap-data:/data -v "$PWD":/backup alpine \
  tar czf /backup/yap-data-YYYY-MM-DD.tgz -C /data .
docker compose start yap

Stopping checkpoints the WAL, so the archive contains one coherent database. Downtime is the stop and start, which is seconds on a small box. Run it from cron at a quiet hour and you have a nightly backup for one line of crontab.

The online one: VACUUM INTO

SQLite can write a defragmented, transactionally consistent copy while the server keeps running. This project uses exactly that when it rewrites the sign-up table, so it is a supported path, but note that the runtime image has no sqlite3 binary in it:

docker run --rm -v yap-data:/data -v "$PWD":/backup alpine \
  sh -c 'apk add --no-cache sqlite >/dev/null && sqlite3 /data/yap.db "VACUUM INTO '"'"'/backup/yap-YYYY-MM-DD.db'"'"'"'

The output is a single file with no WAL beside it, which is what you want for offsite copies. Do not point VACUUM INTO at an existing file: it refuses, which is the safe behaviour.

Getting it off the box

Restore

  1. docker compose down. The yap-data volume stays.
  2. Empty the volume, so an old -wal cannot be replayed into the restored file: docker run --rm -v yap-data:/data alpine sh -c 'rm -rf /data/*'.
  3. Extract the archive back into the volume with the same two-mount trick, in reverse.
  4. docker compose up -d. Migrations run at startup, so a backup from an older release is upgraded to the current schema automatically.
  5. curl -sS https://HOST/api/v1/health returns ok, and the oldest message you expect is still in its channel.

RPO and RTO, in plain words

RPO is how much you are willing to lose: if you archive nightly, expect to lose up to a day of messages. RTO is how long you are down: with this page open, a restore is minutes — stop, empty, extract, start, check.

For a group of friends the nightly archive is usually enough. For anything people would miss, take a nightly archive plus a VACUUM INTO copy every few hours and keep both off the box.

Updated . Part of hosting and self-hosting.