feat(backup): back up and restore everything, across installs and databases (#96) #97

Merged
jfro merged 4 commits from feat/96-backup-restore into main 2026-11-28 21:51:32 +00:00
Owner

What changed

PR #97 at 39a2eb0 is unchanged since the last Prover found nothing wrong (C52) but ended stuck; CI is green on all 4 jobs. Repro: in /home/peak/work/lamplighter-v1-4/wt-96 run env -u FORGEJO_TOKEN MIX_TEST_PARTITION=_prover mix test after mise activate, then again with LAMPLIGHTER_DB=sqlite MIX_BUILD_ROOT=_build_sqlite.

Fixes #96

Red, then green

  • Backup round-trip, cross-adapter, wrong-passphrase, newer-schema and UI restore tests pass on both Postgres and SQLite builds.: bash -c 'source ~/.rmenv; export PATH=$HOME/.local/bin:$PATH; eval "$(mise activate bash --shims)"; T="test/lamplighter/backup_test.exs test/lamplighter_web/live/backup_settings_live_test.exs"; env -u FORGEJO_TOKEN MIX_TEST_PARTITION=_96p mix test $T && env -u FORGEJO_TOKEN LAMPLIGHTER_DB=sqlite MIX_BUILD_ROOT=_build_sqlite MIX_TEST_PARTITION=_96p mix test $T'
    • fails on the base (448212f): exit 1
    • passes on the branch (1233c18): exit 0

Checks

  • PR #97 head 56b5c48 has green CI: tests on Postgres and SQLite plus both images. (Upper Wolfjaw): test "$(curl -s https://git.knope.dev/api/v1/repos/jfro/lamplighter/commits/56b5c48/status | jq -r .state)" = success, exit 0
  • Cross-database restore works in a real browser at 1233c18: a Postgres backup restored through /restore on an empty SQLite build (different secret_key_base), then a SQLite backup restored through Settings → Backup on Postgres. All 17 tables, users and every sealed secret came through, and Postgres handed out id 14 after the restore, so its sequence was moved past the restored rows. (Nye): /home/peak/work/lamplighter-v1-4/nye-checks/l97/xdb_verify.sh, exit 0
  • The full test suite passes on both builds at 1233c18: 1335 tests on Postgres and 1335 on SQLite. (Nye): git -C /home/peak/work/lamplighter-v1-4/lamplighter stash -u -q 2>/dev/null; git -C /home/peak/work/lamplighter-v1-4/lamplighter checkout -q --detach 1233c18 && /home/peak/work/lamplighter-v1-4/nye-checks/l97/suites.sh; rc=$?; git -C /home/peak/work/lamplighter-v1-4/lamplighter checkout -q nye/97-review; git -C /home/peak/work/lamplighter-v1-4/lamplighter stash pop -q 2>/dev/null; exit $rc, exit 0
  • Chromium check at 390px and 1440px passed: /restore links, the wrong-passphrase error, restore then log-in, /restore closing once accounts exist, Settings → Backup's passphrase errors with no overflow, and the 20-minute sign-in gate hiding both forms. This command re-checks the gates live. (Nye): /home/peak/work/lamplighter-v1-4/nye-checks/l97/gates.sh, exit 0
  • A backup that unpacks past the limit (a gzip bomb) is refused in seconds with nothing written, and the normal backup still restores. (Upper Wolfjaw): bash -c 'source ~/.rmenv; eval "$(mise activate bash --shims)"; env -u FORGEJO_TOKEN MIX_TEST_PARTITION=_96 mix test test/lamplighter/backup_test.exs', exit 0
  • F2 re-check: my own test (a manifest with a huge PBKDF2 count is refused quickly and changes nothing) passes on 343b6a3, separate from Upper Wolfjaw's test. (Nye): bash /home/peak/work/lamplighter-v1-4/nye-checks/l97/kdf_test.sh, exit 0
  • PR #97 at 343b6a3 works in WebKit at 390px and 1440px: the passphrase rules keep the button disabled, the page stays live after a download, the re-auth gate works, and /restore is closed. 27 screenshots, no overflow. (Nye): bash /home/peak/work/lamplighter-v1-4/nye-checks/l97/wk_check.sh, exit 0
  • Both full suites (Postgres and SQLite) pass at 343b6a3 plus my F2 test: 1338/1338 each. (Nye): bash /home/peak/work/lamplighter-v1-4/nye-checks/l97/suites.sh, exit 0
  • F2 stays fixed at 39a2eb0: my own test (a restore whose manifest asks for a huge PBKDF2 count is refused quickly) passes on the new head. (Nye): bash /home/peak/work/lamplighter-v1-4/nye-checks/l97/kdf_test.sh, exit 0
  • At 39a2eb0 the real /restore page with no accounts refuses a 9.4 MB upload that unpacks to 9 GiB in about 20 s and writes nothing, on Postgres at 390px and SQLite at 1440px. The seed fixture then restores across databases, and /settings/ai renders the restored "claude" provider. (Nye): bash /home/peak/work/lamplighter-v1-4/nye-checks/l97/recheck.sh, exit 0
  • Both full suites pass at 39a2eb0 plus my F2 test: 1339/1339 on Postgres and on SQLite. (Nye): bash /home/peak/work/lamplighter-v1-4/nye-checks/l97/suites.sh, exit 0
  • At 39a2eb0 I read the backup, restore and /restore code and ran both full suites 13 times each, 1338 passing, with one unexplained failure in the first run that never came back. Not tried: a real production restore. (Prover): bash -c 'source ~/.rmenv; export PATH=$HOME/.local/bin:$PATH; eval "$(mise activate bash --shims)"; T="test/lamplighter/backup_test.exs test/lamplighter_web/live/backup_settings_live_test.exs"; env -u FORGEJO_TOKEN MIX_TEST_PARTITION=_prv96 mix test $T && env -u FORGEJO_TOKEN LAMPLIGHTER_DB=sqlite MIX_BUILD_ROOT=_build_sqlite MIX_TEST_PARTITION=_prv96 mix test $T', exit 0
  • At 39a2eb0 I read the backup/restore diff (PBKDF2 cap 10x, 8 GiB unpack cap) and ran both full suites, 1338 passing on Postgres and SQLite, clean. Not tried: a real production-size restore, or the over-8 GiB tar entry edge. (Prover): bash -c 'source ~/.rmenv; export PATH=$HOME/.local/bin:$PATH; eval "$(mise activate bash --shims)"; cd /home/peak/scratch/prove96 && T="test/lamplighter/backup_test.exs test/lamplighter_web/live/backup_settings_live_test.exs"; env -u FORGEJO_TOKEN MIX_TEST_PARTITION=_prv96c mix test $T && env -u FORGEJO_TOKEN LAMPLIGHTER_DB=sqlite MIX_BUILD_ROOT=_build_sqlite MIX_TEST_PARTITION=_prv96c mix test $T', exit 0

Found and fixed

  • F2 bug: Restore runs PBKDF2 with whatever iteration count the uploaded manifest asks for (no cap), so a 2-billion-iteration file pins a CPU core for a long time, and /restore needs no sign-in on an empty install. It should refuse counts far above the 600k that create writes before deriving the key. (fixed)
  • F3 bug: Before the cap (343b6a3), restore unpacks a 200 MB gzip bomb in full instead of refusing it, so an upload to the no-sign-in /restore page can fill the disk. (fixed)

Shipping it

  • Goes live when it merges: no. Main CI runs tests and builds images with push: false; releases only run on tags Jeremy cuts with mise run release.
  • Undo: a revert puts it back.
  • Not tried on the real thing: A restore on a real production install with full-size data; tests and browser walks used seed and dev example data.
  • For later: After a failed restore you have to pick the file again (#99). A crafted tar entry over 8 GiB is read as empty by erl_tar and slips the unpack cap, restoring that table empty (Nye's low note). #98 filed outside v1.4.

Prover

Passed (Sonnet): At 39a2eb0 I read the backup/restore diff (PBKDF2 cap 10x, 8 GiB unpack cap) and ran both full suites, 1338 passing on Postgres and SQLite, clean. Not tried: a real production-size restore, or the over-8 GiB tar entry edge.

Every command above was run by Fortysix's Basecamp itself, on the branch named.

## What changed PR #97 at 39a2eb0 is unchanged since the last Prover found nothing wrong (C52) but ended stuck; CI is green on all 4 jobs. Repro: in /home/peak/work/lamplighter-v1-4/wt-96 run `env -u FORGEJO_TOKEN MIX_TEST_PARTITION=_prover mix test` after mise activate, then again with LAMPLIGHTER_DB=sqlite MIX_BUILD_ROOT=_build_sqlite. Fixes #96 ## Red, then green - Backup round-trip, cross-adapter, wrong-passphrase, newer-schema and UI restore tests pass on both Postgres and SQLite builds.: `bash -c 'source ~/.rmenv; export PATH=$HOME/.local/bin:$PATH; eval "$(mise activate bash --shims)"; T="test/lamplighter/backup_test.exs test/lamplighter_web/live/backup_settings_live_test.exs"; env -u FORGEJO_TOKEN MIX_TEST_PARTITION=_96p mix test $T && env -u FORGEJO_TOKEN LAMPLIGHTER_DB=sqlite MIX_BUILD_ROOT=_build_sqlite MIX_TEST_PARTITION=_96p mix test $T'` - fails on the base (448212f): exit 1 - passes on the branch (1233c18): exit 0 ## Checks - PR #97 head 56b5c48 has green CI: tests on Postgres and SQLite plus both images. (Upper Wolfjaw): `test "$(curl -s https://git.knope.dev/api/v1/repos/jfro/lamplighter/commits/56b5c48/status | jq -r .state)" = success`, exit 0 - Cross-database restore works in a real browser at 1233c18: a Postgres backup restored through /restore on an empty SQLite build (different secret_key_base), then a SQLite backup restored through Settings → Backup on Postgres. All 17 tables, users and every sealed secret came through, and Postgres handed out id 14 after the restore, so its sequence was moved past the restored rows. (Nye): `/home/peak/work/lamplighter-v1-4/nye-checks/l97/xdb_verify.sh`, exit 0 - The full test suite passes on both builds at 1233c18: 1335 tests on Postgres and 1335 on SQLite. (Nye): `git -C /home/peak/work/lamplighter-v1-4/lamplighter stash -u -q 2>/dev/null; git -C /home/peak/work/lamplighter-v1-4/lamplighter checkout -q --detach 1233c18 && /home/peak/work/lamplighter-v1-4/nye-checks/l97/suites.sh; rc=$?; git -C /home/peak/work/lamplighter-v1-4/lamplighter checkout -q nye/97-review; git -C /home/peak/work/lamplighter-v1-4/lamplighter stash pop -q 2>/dev/null; exit $rc`, exit 0 - Chromium check at 390px and 1440px passed: /restore links, the wrong-passphrase error, restore then log-in, /restore closing once accounts exist, Settings → Backup's passphrase errors with no overflow, and the 20-minute sign-in gate hiding both forms. This command re-checks the gates live. (Nye): `/home/peak/work/lamplighter-v1-4/nye-checks/l97/gates.sh`, exit 0 - A backup that unpacks past the limit (a gzip bomb) is refused in seconds with nothing written, and the normal backup still restores. (Upper Wolfjaw): `bash -c 'source ~/.rmenv; eval "$(mise activate bash --shims)"; env -u FORGEJO_TOKEN MIX_TEST_PARTITION=_96 mix test test/lamplighter/backup_test.exs'`, exit 0 - F2 re-check: my own test (a manifest with a huge PBKDF2 count is refused quickly and changes nothing) passes on 343b6a3, separate from Upper Wolfjaw's test. (Nye): `bash /home/peak/work/lamplighter-v1-4/nye-checks/l97/kdf_test.sh`, exit 0 - PR #97 at 343b6a3 works in WebKit at 390px and 1440px: the passphrase rules keep the button disabled, the page stays live after a download, the re-auth gate works, and /restore is closed. 27 screenshots, no overflow. (Nye): `bash /home/peak/work/lamplighter-v1-4/nye-checks/l97/wk_check.sh`, exit 0 - Both full suites (Postgres and SQLite) pass at 343b6a3 plus my F2 test: 1338/1338 each. (Nye): `bash /home/peak/work/lamplighter-v1-4/nye-checks/l97/suites.sh`, exit 0 - F2 stays fixed at 39a2eb0: my own test (a restore whose manifest asks for a huge PBKDF2 count is refused quickly) passes on the new head. (Nye): `bash /home/peak/work/lamplighter-v1-4/nye-checks/l97/kdf_test.sh`, exit 0 - At 39a2eb0 the real /restore page with no accounts refuses a 9.4 MB upload that unpacks to 9 GiB in about 20 s and writes nothing, on Postgres at 390px and SQLite at 1440px. The seed fixture then restores across databases, and /settings/ai renders the restored "claude" provider. (Nye): `bash /home/peak/work/lamplighter-v1-4/nye-checks/l97/recheck.sh`, exit 0 - Both full suites pass at 39a2eb0 plus my F2 test: 1339/1339 on Postgres and on SQLite. (Nye): `bash /home/peak/work/lamplighter-v1-4/nye-checks/l97/suites.sh`, exit 0 - At 39a2eb0 I read the backup, restore and /restore code and ran both full suites 13 times each, 1338 passing, with one unexplained failure in the first run that never came back. Not tried: a real production restore. (Prover): `bash -c 'source ~/.rmenv; export PATH=$HOME/.local/bin:$PATH; eval "$(mise activate bash --shims)"; T="test/lamplighter/backup_test.exs test/lamplighter_web/live/backup_settings_live_test.exs"; env -u FORGEJO_TOKEN MIX_TEST_PARTITION=_prv96 mix test $T && env -u FORGEJO_TOKEN LAMPLIGHTER_DB=sqlite MIX_BUILD_ROOT=_build_sqlite MIX_TEST_PARTITION=_prv96 mix test $T'`, exit 0 - At 39a2eb0 I read the backup/restore diff (PBKDF2 cap 10x, 8 GiB unpack cap) and ran both full suites, 1338 passing on Postgres and SQLite, clean. Not tried: a real production-size restore, or the over-8 GiB tar entry edge. (Prover): `bash -c 'source ~/.rmenv; export PATH=$HOME/.local/bin:$PATH; eval "$(mise activate bash --shims)"; cd /home/peak/scratch/prove96 && T="test/lamplighter/backup_test.exs test/lamplighter_web/live/backup_settings_live_test.exs"; env -u FORGEJO_TOKEN MIX_TEST_PARTITION=_prv96c mix test $T && env -u FORGEJO_TOKEN LAMPLIGHTER_DB=sqlite MIX_BUILD_ROOT=_build_sqlite MIX_TEST_PARTITION=_prv96c mix test $T'`, exit 0 ## Found and fixed - F2 bug: Restore runs PBKDF2 with whatever iteration count the uploaded manifest asks for (no cap), so a 2-billion-iteration file pins a CPU core for a long time, and /restore needs no sign-in on an empty install. It should refuse counts far above the 600k that create writes before deriving the key. (fixed) - F3 bug: Before the cap (343b6a3), restore unpacks a 200 MB gzip bomb in full instead of refusing it, so an upload to the no-sign-in /restore page can fill the disk. (fixed) ## Shipping it - Goes live when it merges: no. Main CI runs tests and builds images with push: false; releases only run on tags Jeremy cuts with mise run release. - Undo: a revert puts it back. - Not tried on the real thing: A restore on a real production install with full-size data; tests and browser walks used seed and dev example data. - For later: After a failed restore you have to pick the file again (#99). A crafted tar entry over 8 GiB is read as empty by erl_tar and slips the unpack cap, restoring that table empty (Nye's low note). #98 filed outside v1.4. ## Prover Passed (Sonnet): At 39a2eb0 I read the backup/restore diff (PBKDF2 cap 10x, 8 GiB unpack cap) and ran both full suites, 1338 passing on Postgres and SQLite, clean. Not tried: a real production-size restore, or the over-8 GiB tar entry edge. Every command above was run by Fortysix's Basecamp itself, on the branch named.
jfro added this to the v1.4 milestone 2026-11-28 20:23:03 +00:00
feat(backup): back up and restore everything, across installs and databases (#96)
All checks were successful
CI / image (postgres) (pull_request) Successful in 1m22s
CI / image (sqlite) (pull_request) Successful in 1m25s
CI / test (postgres) (pull_request) Successful in 1m57s
CI / test (sqlite) (pull_request) Successful in 1m58s
1233c18385
Settings → Backup downloads one .tar.gz (manifest.json + JSON lines per
table) and restores one, replacing all data in a single transaction.
Secrets are sealed with an admin passphrase (PBKDF2-SHA256, AES-256-GCM)
and stored under the new install's Vault on restore. Session tokens are
left out. A newer-schema backup or a wrong passphrase is refused with
nothing changed. An empty install can restore from the log-in screen.
fix(backup): keep the page live while the backup downloads; test secrets move to a new key
All checks were successful
CI / image (postgres) (pull_request) Successful in 1m22s
CI / image (sqlite) (pull_request) Successful in 1m27s
CI / test (postgres) (pull_request) Successful in 1m48s
CI / test (sqlite) (pull_request) Successful in 1m51s
56b5c48896
A phx-trigger-action submit unloads the LiveView, so the restore form on
the same page stopped working after a download. The download is now a
plain form post, enabled once the passphrase checks out as it's typed.
Author
Owner

Screenshots (Chromium) at 56b5c48, with the example data in the dev database (3 sources, 30 reports, 105 events, 5 notification channels, 2 users, a chat).

The walkthrough was a real move from Postgres to SQLite: I downloaded a backup from the Postgres dev server and restored it on an empty SQLite dev server through its first-run screen. Then I signed in there with the same account. Every table's row count matched, and the source and notification secrets opened under the SQLite install's Vault.

Settings → Backup (desktop, 390px)

Passphrase checks as you type (download stays disabled)

Wrong passphrase on restore: nothing changed

Empty install (SQLite build): the log-in screen offers a restore, then the restore form, then back at log-in after it's done


SQLite dashboard after the restore, signed in with the restored account

Screenshots (Chromium) at 56b5c48, with the example data in the dev database (3 sources, 30 reports, 105 events, 5 notification channels, 2 users, a chat). The walkthrough was a real move from Postgres to SQLite: I downloaded a backup from the **Postgres** dev server and restored it on an empty **SQLite** dev server through its first-run screen. Then I signed in there with the same account. Every table's row count matched, and the source and notification secrets opened under the SQLite install's Vault. **Settings → Backup** (desktop, 390px) ![](https://git.knope.dev/attachments/9ce55f60-72d6-464d-880b-afcec3086d59) ![](https://git.knope.dev/attachments/c52f291f-8cca-4045-b14e-68ed2c5f7d08) Passphrase checks as you type (download stays disabled) ![](https://git.knope.dev/attachments/2f4f5a7c-a11e-40a1-b712-9fee1ee1496e) Wrong passphrase on restore: nothing changed ![](https://git.knope.dev/attachments/1b480e2d-a82d-42b5-b2d1-86717a87255a) **Empty install** (SQLite build): the log-in screen offers a restore, then the restore form, then back at log-in after it's done ![](https://git.knope.dev/attachments/90a637d7-7ed7-4d55-8a7a-64a2761a82df) ![](https://git.knope.dev/attachments/1558712d-31d5-4c33-9c29-4c55043c811c) ![](https://git.knope.dev/attachments/57470250-c079-4143-b4cd-5631e850a36c) SQLite dashboard after the restore, signed in with the restored account ![](https://git.knope.dev/attachments/eeee3b1f-9793-46b6-adbf-113bf2c5762b)
fix(backup): refuse key-derivation counts far past what create writes (#96)
All checks were successful
CI / image (postgres) (pull_request) Successful in 1m32s
CI / image (sqlite) (pull_request) Successful in 1m34s
CI / test (postgres) (pull_request) Successful in 1m52s
CI / test (sqlite) (pull_request) Successful in 1m59s
343b6a3f00
fix(backup): cap how much a restore unpacks; seed a real AI kind
All checks were successful
CI / image (postgres) (pull_request) Successful in 1m29s
CI / image (sqlite) (pull_request) Successful in 1m31s
CI / test (postgres) (pull_request) Successful in 1m54s
CI / test (sqlite) (pull_request) Successful in 1m53s
39a2eb0858
Restore now reads the archive through a reader that stops past 8 GiB
(max_unpacked: option), so a gzip bomb uploaded to /restore can't fill
the disk or keep a core busy. The backup test seed used AI kind
"anthropic", which isn't a provider; it's "claude" now, fixtures
regenerated on both builds.
jfro merged commit d8f468aa76 into main 2026-11-28 21:51:31 +00:00
jfro deleted branch feat/96-backup-restore 2026-11-28 21:51:32 +00:00
Sign in to join this conversation.
No description provided.