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 volume | What it is |
|---|---|
/data/yap.db | Accounts, spaces, channels, messages, roles, invites, API key hashes. Everything. |
/data/yap.db-wal | Write-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-shm | Shared-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-key | The 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
- One backup on the same disk is not a backup. Copy it somewhere else: another host, object storage, or a machine at home.
- Encrypt it. The archive holds private messages in plaintext for any space that is not end-to-end encrypted;
age,gpgor a restic repository all do the job, and restic also gives you retention. - Keep more than one. A corrupt database gets backed up faithfully every night; a daily for 7 days and a weekly for 4 weeks costs almost nothing at this size.
- Rehearse the restore once. A backup nobody has restored is a hope.
Restore
docker compose down. Theyap-datavolume stays.- Empty the volume, so an old
-walcannot be replayed into the restored file:docker run --rm -v yap-data:/data alpine sh -c 'rm -rf /data/*'. - Extract the archive back into the volume with the same two-mount trick, in reverse.
docker compose up -d. Migrations run at startup, so a backup from an older release is upgraded to the current schema automatically.curl -sS https://HOST/api/v1/healthreturnsok, 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.