Treasury & Bank Transfer Management System — سامانه مدیریت خزانه‌داری و حواله‌های بانکی

Document secure offline-only SQLite backup and rollback rehearsal, with UNKNOWN no-retry and no-overwrite constraints

davoodmehraban89 committed Oct 23, 2026 at 14:54 UTC dc9da189f31a6243d723ae685992ab824e37dc83
1 file changed +35
docs/V7_LOCAL_SQLITE_BACKUP_RECOVERY.md new
+35
@@ -0,0 +1,35 @@
1 +# TreasuryFlow — Local SQLite backup and safe recovery (nonfinal)
2 +
3 +This is an **offline, operator-controlled procedure** for the local SQLite store. It does **not** certify V7 upgrade/rollback, production database disaster recovery, bank reconciliation or RPO/RTO. Keep all bank adapters disabled during recovery.
4 +
5 +## Preconditions
6 +- Node.js 22 and the checked-out matching TreasuryFlow source are required.
7 +- Stop the desktop application **before restoring** and keep a separately protected backup outside the active database directory.
8 +- Treat every SQLite backup as **sensitive financial data**, not an export for public GitHub/CI.
9 +- Perform this only on an authorized device with encrypted/private storage. The utility does not encrypt its output.
10 +
11 +## Offline commands
12 +
13 +```sh
14 +node --experimental-strip-types scripts/treasury-sqlite-recovery.mjs backup /path/to/current.sqlite /secure/new-backup.sqlite
15 +node --experimental-strip-types scripts/treasury-sqlite-recovery.mjs verify /secure/new-backup.sqlite
16 +node --experimental-strip-types scripts/treasury-sqlite-recovery.mjs restore-new /secure/new-backup.sqlite /path/to/new-recovery.sqlite
17 +```
18 +
19 +The backup uses SQLite `VACUUM INTO` for a consistent committed snapshot, even when the source has WAL activity. It validates `PRAGMA integrity_check`, required schema tables and exact schema version. The destination is created exclusively: **an existing file, including a zero-byte file, is never overwritten**. Restore works **only to a new filename** and does not modify the active database.
20 +
21 +## Operational handover / rollback
22 +1. Capture and verify a protected backup; record its SHA-256 in private release records.
23 +2. Run recovery into a **new** path and compare account, beneficiary, payment and audit counts.
24 +3. Have a finance checker independently reconcile balances, payment identifiers and critical audit sequences against authorized records. Counts alone are not reconciliation.
25 +4. Transactions in `UNKNOWN` and `DISPATCHING` must remain blocked from automatic bank resubmission after restore. Confirm their status externally with the bank through approved channels and maker/checker review.
26 +5. Point a **separate test deployment** at the recovered database for smoke verification. Production path switching is a separately authorized deployment action; this utility never performs it.
27 +
28 +## Security boundaries
29 +- Never upload a real customer SQLite file, backup or restored copy to public CI artifacts, public repositories or support logs.
30 +- This is not an automatic scheduled backup service and does not guarantee any production RPO/RTO.
31 +- A valid file alone does not prove finance correctness or permission to replay bank transactions.
32 +- Corrupt, unsupported-schema and existing-target cases fail closed, with no operational file replacement.
33 +
34 +## Test acceptance
35 +See `src/platform/local/verified-sqlite-backup.test.ts` and `scripts/treasury-sqlite-recovery.test.ts` for normal, WAL, corruption, version, no-overwrite and operator command regressions. Final release status depends on current CI results, not the existence of these files.