Prove that you can recover
Back up your site's data, lose a page on purpose, restore the backup into a new folder, and check that the restored site has your pages, your draft and your account, while the original stays as it was.
deploy/README.txt have not yet run on a Linux server.Allow 25–40 minutes. This is an editorial estimate. Continue in the same my-site folder.
Read
Start at L21. A backup you have never restored is a hope, not a backup. In this lesson you prove yours works.
run-what backup copies the site's data into a new folder outside the project: the store (your pages, their publication state and your accounts) and the uploads/ folder, with backup.json listing the storage engine, the schema and a checksum for every file. It copies the store as one consistent database, never as a plain copy of a file a server is writing. It holds no sessions and none of your site files. The backup contains your accounts' password hashes, so it is private to you: keep it outside the project and out of any served folder.
Stop every server using the project before a backup. A backup refuses a server that is writing at that moment, but an idle server may not be noticed, so do not rely on that.
run-what restore checks the backup first, then puts its data into a new folder, where your what.toml says the store and the uploads belong, together with a copy of that what.toml. It never replaces a folder that already exists and never changes the backup. A damaged backup, or one from a newer version of the store, is refused. The restored store remembers that data/pages.json was already imported, so the starter pages are not imported again.
Sessions are never restored: after a restore, users of the site's own accounts sign in again with the same name and password. Credentials from an external sign-in provider (JWTs) are not revoked by a restore.
A backup holds data only. To bring a site back you also need the site files and the what.toml that match that data, so keep them in a separate private folder beside each backup, never inside the backup folder: an extra file there, even the .DS_Store that Finder adds when you open the folder, makes the backup refused. Leave backups unopened and unmodified. In this lesson the current files match, because you change only data.
Change
1. Keep a copy. Stop the dev server with Ctrl+C. Copy the whole my-site folder to a new folder such as my-site-before-L22.
2. Add the recovery steps to the recipe. Replace deploy/README.txt. It gains a RECOVERY section: how to back up and restore on your server, keeping the old installation for rollback. Nothing else in deploy/ changes.
PRODUCTION RECIPE: one What site on a Linux server with systemd, Caddy in front.
Not run on a Linux server. These files are checked by parsing
(scripts/recipe-check.py) and the configuration by starting run-what on a
development machine. Starting the service under systemd on Linux, real
TLS and hosting are unverified.
FILES
what.service systemd unit, installed as /etc/systemd/system/what.service
Caddyfile Caddy site, installed as /etc/caddy/Caddyfile
env.example the form secret's file, copied to /etc/my-site/env
what.toml the server's what.toml: the project's own, with [server]
set for Caddy (the public HTTPS origin, one proxy hop)
PREREQUISITES (yours to provide; nothing here creates them)
1. A Linux server with systemd, a domain whose DNS points at it, ports 80
and 443 open, and Caddy installed (Caddy obtains the certificate).
2. A run-what binary built for that server. A binary built on macOS does
not run on Linux. Build it from the What source with
cargo build --release --bin run-what on the server, or on a Linux
machine with the same architecture and a C library no newer than the
server's. Install it as /usr/local/bin/run-what, owned by root, mode
0755.
3. A service account that cannot log in and owns only the data, with its
own group of the same name (Group=what in the unit):
sudo useradd --system --user-group --home-dir /srv/my-site --shell /usr/sbin/nologin what
4. The two persistent folders, owned by the account, private, created
before the service starts (systemd refuses a missing ReadWritePaths):
sudo install -d -o root -g root -m 0755 /srv/my-site
sudo install -d -o what -g what -m 0700 /srv/my-site/data /srv/my-site/uploads
data/ holds the store (data/app.db, with -wal and -shm while running)
and the sessions database (data/sessions.db); uploads/ holds uploaded
files. Both folders must persist across restarts and upgrades. A
backup (L22) holds the store and uploads/ only: sessions are never
backed up or restored, so after a restore, sign-ins through the site's
own accounts start again.
5. The site files in /srv/my-site, owned by root, directories 0755 and
files 0644, so the service reads them and cannot change them:
this folder's what.toml as /srv/my-site/what.toml (with your domain),
site/, static/ and components/. Put data/pages.json (read once, on the
first start) in on its own, so data/ and uploads/ keep the owner and
mode from step 4:
sudo install -o root -g root -m 0644 data/pages.json /srv/my-site/data/pages.json
Never copy a whole data/ or uploads/ folder over them, and never
chown or chmod the project recursively. Copy no data/app.db, no
sessions database and no .env: the server creates its own data, and a
.env in the project would be loaded and travel with every copy of the
project.
6. The secret, outside the project:
sudo install -d -o root -g root -m 0755 /etc/my-site
sudo install -o root -g root -m 0600 env.example /etc/my-site/env
openssl rand -hex 32
Paste the generated value after WHAT_SERVER_FORM_SECRET= in
/etc/my-site/env (sudoedit /etc/my-site/env). Left empty, run-what
refuses to start.
7. Your domain in two places, the same origin in both: the site address
in the Caddyfile and allowed_origins in /srv/my-site/what.toml
("https://" plus the domain, nothing after it).
START
The first editor account (there is no built-in one), as the service
account so its files belong to it, before the first start:
sudo -u what /usr/local/bin/run-what admin add editor --path /srv/my-site
Then:
sudo install -o root -g root -m 0644 what.service /etc/systemd/system/what.service
sudo systemctl daemon-reload
sudo systemctl enable --now what
sudo install -o root -g root -m 0644 Caddyfile /etc/caddy/Caddyfile
sudo systemctl reload caddy
Logs: journalctl -u what. For JSON log lines, add WHAT_LOG_FORMAT=json to
/etc/my-site/env and restart.
RECOVERY (back up and restore on the server; documented steps, not yet run
on a Linux server)
A backup holds the store (accounts, pages, publication state) and uploads/,
with backup.json listing the engine, the schema and every checksum. It
holds no sessions and no site files. Keep the site files and what.toml
that match each backup in a separate private folder beside it, never
inside the backup folder (an extra file there, even the .DS_Store that
Finder adds when you open it, makes verify and restore refuse the
backup; keep backups unopened and unmodified): a restore needs both. Stop the service first: a backup refuses a server that is writing,
but an idle server may not be noticed, so never rely on that.
Run each command on its own and stop at the first one that fails. The new
backup, restore, rollback and failed-attempt destinations must not exist
yet, not even as a link; the test commands check that.
Back up, as root, into a private folder outside the project:
sudo systemctl stop what
test ! -e /var/backups/my-site-2026-10-27 && test ! -L /var/backups/my-site-2026-10-27
sudo /usr/local/bin/run-what backup --path /srv/my-site --output /var/backups/my-site-2026-10-27
sudo /usr/local/bin/run-what backup --verify /var/backups/my-site-2026-10-27
sudo systemctl start what
The folder is owner-only (root). Keep a copy off the server as well.
Restore into a new folder, with the service stopped:
sudo systemctl stop what
test ! -e /srv/my-site-restored && test ! -L /srv/my-site-restored
sudo /usr/local/bin/run-what restore --from /var/backups/my-site-2026-10-27 --config /srv/my-site/what.toml --output /srv/my-site-restored
The restored folder and its files are private to root, and an empty
uploads folder in the backup leaves no uploads/ folder at all. Make the
project traversable and its configuration readable, copy in the site files
that match the backup as root (here the current ones), make sure data/ and
uploads/ exist, and give only those two to the service account:
sudo chmod 0755 /srv/my-site-restored
sudo chmod 0644 /srv/my-site-restored/what.toml
sudo cp -R --preserve=mode /srv/my-site/site /srv/my-site/static /srv/my-site/components /srv/my-site-restored/
sudo install -d -o what -g what -m 0700 /srv/my-site-restored/data /srv/my-site-restored/uploads
sudo chown -R what:what /srv/my-site-restored/data /srv/my-site-restored/uploads
Never copy the old data/, uploads/, sessions database or another
what.toml over the restored folder. The environment file in
/etc/my-site/env stays where it is.
Promote the restored folder, keeping the old installation for rollback.
mv -T (GNU) renames a folder and never moves it inside another one:
test ! -e /srv/my-site-before-restore-2026-10-27 && test ! -L /srv/my-site-before-restore-2026-10-27
sudo mv -T /srv/my-site /srv/my-site-before-restore-2026-10-27
sudo mv -T /srv/my-site-restored /srv/my-site
sudo systemctl start what
systemctl status what
The status must say active; then open your site and check the restored
pages and an editor sign-in. Users of the site's own accounts sign in
again: sessions are never restored. Credentials from an external sign-in
provider (JWTs) are not revoked by a restore.
Only if the promoted site fails verification, roll back, keeping the
failed restore for inspection:
sudo systemctl stop what
test ! -e /srv/my-site-failed-restore-2026-10-27 && test ! -L /srv/my-site-failed-restore-2026-10-27
sudo mv -T /srv/my-site /srv/my-site-failed-restore-2026-10-27
sudo mv -T /srv/my-site-before-restore-2026-10-27 /srv/my-site
sudo systemctl start what
systemctl status what
WHY EACH SETTING
--production no file watching, live reload, developer tools, debug
output or detailed error pages; session cookies keep
Secure, so the site needs HTTPS (Caddy).
127.0.0.1 only Caddy, on the same machine, reaches run-what; the
plain HTTP port is never public. trusted_proxy_hops = 1 is
correct only while this holds.
allowed_origins state-changing requests are accepted only from the
public HTTPS origin.
WHAT_SERVER_FORM_SECRET signs the rules of <form w-validate> forms; with
the same secret such a form opened before a restart still
submits after it, with a new one it must be reloaded. Forms
without w-validate (the course's edit forms) do not depend
on it; keep it stable for the w-validate forms you add.
KillSignal=SIGINT run-what shuts down cleanly on SIGINT; systemd's
default SIGTERM stops it without the clean shutdown.
ProtectSystem=strict, ReadWritePaths within the project the service can
write only data/ and uploads/; the site files and what.toml
stay as you installed them. (PrivateTmp gives it its own
writable temporary folder outside the project.)
3. Make something to lose. In my-site, run run-what dev, sign in at http://127.0.0.1:8085/login, create a page titled “Recovery check” with the address recovery-check, and publish it. Keep one other page as a draft. Stop the server with Ctrl+C.
4. Back up. In my-site, with no server running:
run-what backup --path . --output ../my-site-backup
run-what backup --verify ../my-site-backup
The first command says what it copied and what it left out. The second checks every file against backup.json.
5. Lose the page. Run run-what dev again, unpublish “Recovery check” and delete it. Its address now answers “Page Not Found”. Stop the server with Ctrl+C.
6. Restore into a new folder. Still in my-site:
run-what restore --from ../my-site-backup --config what.toml --output ../my-site-restored
7. Copy the site files in. A backup has no site files. Copy the ones that match the backed-up data: here the current site/, static/, components/ and deploy/ from my-site, into my-site-restored. Never copy data/, uploads/ or what.toml: the restored folder already has its own, and copying the old ones over it would undo the restore.
8. Start the restored site. In my-site-restored, run run-what dev and open http://127.0.0.1:8085.
Check
http://127.0.0.1:8085/pages/recovery-checkshows “Recovery check” again.- You are signed out. Sign in with the same name and password as before; All pages lists the same pages as before you deleted it, and your draft is still a draft. Visitors cannot open it.
- Stop the server with Ctrl+C. In
my-site, runrun-what dev: “Recovery check” is still gone there. The original was not changed. Stop it with Ctrl+C. - Run
run-what restore --from ../my-site-backup --config what.toml --output ../my-site-restoredagain: it refuses, because the folder exists, and changes nothing.
Exercise
Explain in two sentences why you copied site/ into the restored folder but not data/, and what you would see if you had copied data/ as well.
If something goes wrong
- “another process is writing to the store”. A server is still running on the project. Stop every server using it, then back up again.
- “… already exists; a restore never replaces anything”. Backups and restores never replace a folder. Choose a new name, or remove the old folder yourself if you are sure.
- The restore refuses the backup. A file changed since the backup, or the backup comes from a newer version of the store. Nothing was created; use another backup, or the matching
run-what. - Every page answers “Page Not Found” on the restored site. The site files were not copied in; do step 7.
- “Recovery check” is missing on the restored site. The original
data/was copied over the restored one, or the backup was made after the deletion. Restore again into a new folder. - Start again from a known state. Download the L22 checkpoint into a new, empty folder; never unpack it over your project. It has no database, no account and no secret: run
run-what admin add editorin the new folder, thenrun-what dev.
Next: back to the course.