Backup/restore drill report
Date: 2026-07-18
Environment tested: Tauri profile (PGlite driver, AUTH_MODE=none), on
macOS-arm64 host, Node 22, backend at 1.0.0-desktop-beta1.
Environment not tested this pass: Docker/Postgres — deferred pending
a live stack. The scripted drill can be re-run against Postgres with
DB_DRIVER=postgres DATABASE_URL=… (untested; the driver factory
supports it end-to-end via abstract-the-db-driver-behind-a-factory).
Runner: backend/scripts/backup-drill.ts (add test:drill to
backend/package.json if you want a stable invocation; the raw command
is node_modules/.bin/tsx scripts/backup-drill.ts from backend/).
What the drill does
- Pinned env:
DB_DRIVER=pglite,AUTH_MODE=none,DATA_DIRandPGLITE_PATHset to a freshmkdtemp()underos.tmpdir(). - Runs migrations, calls
ensureLocalUser()— same startup path asbackend/src/entry/tauri.ts. - Seeds via
app.inject()(HTTP-level, avoiding a real network round trip): 2 accounts, 8 categories, 5 rules, 3 budgets, 1 balance checkpoint. Then bulk-inserts 210 transactions directly via drizzle (faster than 210 HTTP calls, gives deterministic dedup_keys). - Computes hashPre: SHA-256 of
{ perTableCounts, sha256(last-10 tx by dedup_key, ordered) }. - Calls
GET /api/backup/exportin-process. Saves the envelope to disk, records its SHA-256. - Calls
POST /api/backup/importwith the same envelope. The route deletes the current user's rows in a transaction, then repopulates from the envelope. - Computes hashPost from the freshly-restored state.
- Asserts
hashPre.combinedSha256 === hashPost.combinedSha256. Exits 0 on match, 1 on mismatch. Cleans up the temp dir either way.
Latest run
[pre-export]
accounts 2
categories 9
rules 5
transactions 210
balanceCheckpoints 1
budgets 3
accountFilenamePatterns 0
fileImports 0
transactionSplits 0
lastTenSha256 4464907e1a9f5dcc48133bb277aa08519b19c9d2bd341669734537520f93f8f5
combinedSha256 799a9402342226bb47b9d1dba2272dcec1bb13bd2d4921d861d3d8cdf366ee37
[export] file /tmp/athena-drill-XXXX/export.json
size 73272 bytes
sha256 a4659d0f22e2cad44eeb2f9e5fd16cf116d6d75a450f181cc7f91e25e262a1e2
[post-restore]
accounts 2
categories 9
rules 5
transactions 210
balanceCheckpoints 1
budgets 3
accountFilenamePatterns 0
fileImports 0
transactionSplits 0
lastTenSha256 4464907e1a9f5dcc48133bb277aa08519b19c9d2bd341669734537520f93f8f5
combinedSha256 799a9402342226bb47b9d1dba2272dcec1bb13bd2d4921d861d3d8cdf366ee37
[result] round-trip MATCH ✓
[timings]
migrate 213.3 ms
ensureLocalUser 4.9 ms
seed 81.5 ms
hashPre 17.1 ms
export 8.2 ms
restore 106.8 ms
hashPost 6.5 ms
Findings
- Round-trip is lossless at the row-count and content level for the fields the exporter emits.
categoriesshows 9, not the 8 seeded.ensureLocalUser()seeds a default category on first user creation. The count matches pre and post so it isn't a leak — but note that the exporter includesisDefault: truecategories, so a restore into an already-onboarded DB would try to re-insert the default and hit a unique index. The restore route wipes the user's rows first, so this only bites you cross-user (not on the Tauri single-user profile).- Export size: 73 KB for 210 transactions + 9 categories + 5 rules
- 3 budgets + 1 checkpoint — roughly 350 bytes per transaction. A
10-year archive (~50k tx) projects to ~17 MB. Well under the 50 MB
bodyLimit on
/api/backup/import.
- 3 budgets + 1 checkpoint — roughly 350 bytes per transaction. A
10-year archive (~50k tx) projects to ~17 MB. Well under the 50 MB
bodyLimit on
- Timings: the round trip finishes in ~440 ms end-to-end, dominated by the migration pass and the restore transaction. The export itself is ~8 ms. Backups on the desktop machine happen fast enough that a UI progress spinner is only cosmetic.
Follow-up items (recorded, NOT fixed here)
- Side-by-side UI screenshots. The plan asked for pre- and post-restore Dashboard/Transactions/Budgets screenshots. Deferred: no live app is available in this session's environment. Retake when the drill re-runs against a running Tauri build.
- Docker path. The drill exercises PGlite. A Postgres run under
the same script would confirm the driver-agnostic promise; blocked
on a live Docker runtime this session (see project memory
never-launch-orbstack). categoriesdefault-row bump. IfensureLocalUser()seeds extra rows in the future, the count assertion in the drill will drift silently. Consider comparing per-field lists rather than counts.
How to re-run
From the repo root:
cd backend
node_modules/.bin/tsx scripts/backup-drill.ts
The temp dir under os.tmpdir() is created and removed automatically.
Exit code is 0 on match, 1 on mismatch — safe to wire into CI.