PlotDirector/Docs/Recovery/book-backup-implementation.md

11 KiB
Raw Blame History

Unified book backup and restore — 6 November 2026

Delivered implementation

Projects and the shared application/PWA menus use one Back up books / Restore books from backup workflow. Book actions preselect one book; project actions select all, with individual selection available. Manuscript onboarding remains separate. The PWA ribbon uses the same wizards and an antiforgery-protected manuscript-onboarding action. The old ordinary Import JSON route redirects to restore; compatibility readers and guarded POST endpoints remain for recovery. Archive/Unarchive is distinct from downloaded recovery and saved-point rewind.

The implementation extends the audited project graph, stored-field contract, typed remapper, file staging and transactional SQL apply engine. It does not replace those mechanisms. See the package and identity contract for inclusion, conflict and compatibility decisions.

PlotDirector.BookBackup version2.0 wraps project snapshot1.4. Required native/Intent author state is mandatory in current packages. Upload validation precedes persistent changes. Previews bind the author, immutable upload, selection, destination and snapshot hash in an expiring protected confirmation. Explicit confirmation is required. Restore is additive and owner-authorised; conflicting definitions copy independently. Serializable SQL, account-scoped locks, slot reservations, fresh file names, rollback cleanup and durable receipts protect commit/retry.

Native captures are source-decrypted and destination-reprotected, with new portable-import review/manuscript identities and no live session. Author review/Intent decisions and original evidence/provenance survive. Receipts and consent/job authority do not replay. Restored Intent evidence is stale until reassessed. Historical project formats1.0–1.3 have explicit limitations; incomplete current packages refuse.

Migration236 adds source namespaces, typed mappings, external-reference history and operation receipts. It wraps the existing SQL graph engine for native/Intent state and invalid receipt cleanup, and enforces book capacity on net-positive saved-point rewinds. Usage/reservation/summary procedures count archived books and books in archived projects. The existing explicit archived-book permanent-delete route is extended for newer dependent tables; download never invokes it.

Verification and deployment

Qualification results, migration backup identity and release details are recorded below after the final gates. No Production changes or Windows Companion installation/source changes are included.

Deliberate bounds

  • 64MiB JSON package ceiling, at most100 selected books per restore, 30-minute author upload workspace and20-minute confirmations. Restart requires re-upload.
  • Required unresolved cross-book dependencies refuse; select connected books or restore the mapped dependency first. Optional external references remain visible disconnected history when safe reconnection is unavailable.
  • Maps copy as independent bundles; identical authorised image blobs can reuse. Shared entities without proven durable mappings copy independently; the original project can therefore receive duplicate common definitions rather than an unsafe name/number merge.
  • Existing destination project/singleton timeline settings are retained. Book/filter-specific timeline presets belonging to excluded books are excluded.
  • A file integrity checksum detects accidental alteration, not cryptographic proof of who authored a backup. Imported content still undergoes ownership, typed graph, file and resource validation.
  • SQL/files publication is transaction-backed; a process kill before commit can leave unreferenced newly staged files, but not published references to partially committed books. Exceptions before commit is requested delete staged files. Once commit is requested, files are retained if its outcome becomes uncertain; an original-confirmation receipt retry resolves completion without needing the temporary upload. This favours retaining unreferenced files over deleting bytes that might already have committed references. No background automatic import/analysis resumes.
  • Normal restore has no replace-existing-book option. Saved restore points remain the explicit same-project historical rewind with safety snapshot and owner checks.

Qualification evidence

All SQL mutation tests use the literal, extended-property-guarded PlotDirector_Phase2_20261103_2305 synthetic database. No existing author's project was used for deletion, replacement or restore testing. Before qualification, a unique COPY_ONLY/CHECKSUM backup was taken and RESTORE VERIFYONLY succeeded: /var/opt/mssql/backups/PlotDirector_Phase2_20261103_2305-book-recovery-20261106T160114.bak.

  • Solution build: zero warnings/errors (dotnet build PlotLine.slnx --disable-build-servers -m:1 /p:UseSharedCompilation=false).
  • Selective recovery database harness: 33 passed assertions. Covers single/multiple/all books, new/existing project, cross-account transfer with independent encryption keys, exact prose and uploaded-file SHA256 values, map/floor-plan graph, multiple authors' Intent decisions, populated native receipts excluded from packages, full-rewind receipt invalidation even with unchanged IDs, live destination capture preservation, re-export/shared reuse after local-ID changes, divergent copies/fork identity stability, stale destination refusal, binary handling of active web files, archive accounting, full-capacity refusal without project allocation, backup/delete/restore slot exchange, injected file and SQL failures, durable cacheless receipt retry, project deletion cleanup, and expired-account export versus restore refusal.
  • Existing guarded project-transfer harness: exit0. SQL-to-backup comparison covers106 populated entity sets/2,599 stored values; copy comparison covers103 persistent collections/2,467 stored values, and in-place restore compares2,563 stored values. Its53 malformed-data/map/version pre-allocation cases, actor/reference isolation, uploaded files, writing plans, omission/refusal guards, same-project safety restore and historical illustration handling remain enabled. Direct SQL regression inputs now explicitly model the trusted protected-state boundary so old negative tests still reach their intended graph guards.
  • Separate rollback-only capacity script covers a book inside an archived project, unarchive invariance, full capacity rejection and capacity after explicit deletion.

Commands:

dotnet run --no-build --project PlotLine.Tests/PlotLine.Tests.csproj -- --project-transfer-database --book-recovery-only PlotDirector_Phase2_20261103_2305
dotnet run --no-build --project PlotLine.Tests/PlotLine.Tests.csproj -- --project-transfer-database PlotDirector_Phase2_20261103_2305
dotnet run --no-build --project PlotLine.Tests/PlotLine.Tests.csproj
node PlotLine.Tests/Browser/backup-upload-generation.cjs
# With the existing --toolbar-browser-host running on loopback5238:
node PlotLine.Tests/Browser/book-recovery.cjs

The browser host renders actual compiled Razor and application assets with controlled fixture data; it is separate from the application and does not connect to a database. It is not evidence of native Windows/Word execution. Test logs and fixture screenshots are under /tmp/book-recovery-*; the synthetic portable fixture is outside the repository under /srv/repos/plotdirector-phase2-artifacts/book-recovery-validation/.

Final normal regression harness: 414 passed checks, exit0. Browser regressions pass for actual Razor at1440px and390px; additional narrow theme checks use modern-light, modern-dark and warm-dark (the main fixture is warm-light). They cover book select-all/clear, explicit confirmation, capacity-disabled restore, manuscript-onboarding POST/antiforgery wiring, and absence of legacy ribbon import. The separate FileReader regression forces out-of-order completion and manual edits. These are controlled fixtures, not screenshots of an author's data.

Desktop restore preview

Narrow dark restore preview

Historical compatibility retains the existing1.0–1.3 readers and refusal/warning policy. These tests cover version/older-shape contracts; no claim is made that an arbitrary external historical archive contains data that its original writer never exported. Missing vocabulary definitions or required dependencies fail safely rather than trusting numeric IDs.

Development deployment — verified

Application commit: b4bf21328e88be8f836268dca7e01205a9f733bf on codex/word-companion-native-phase1-20261104 (pushed). The later documentation-only handover commit records this deployment without changing its application build.

  • Migration236 applied to PlotDirector_Development only, after prerequisite and idle-work gates. It is now a live forward-only migration; subsequent repairs require a new numbered migration.
  • Unique pre-migration backup: /var/opt/mssql/backups/PlotDirector_Development-book-recovery-20261106T190600Z.bak; COPY_ONLY/CHECKSUM and RESTORE VERIFYONLY succeeded.
  • Migration SHA256: d5d647c6c7e8e0c9cdc762f9446c3656543d318a3b8c4708ad99a420dacce762.
  • Release: /srv/apps/plotdirector-dev/releases/book-recovery-b4bf213-20261106T190216Z/.
  • Previous application preserved at /srv/apps/plotdirector-dev/current-before-book-recovery-b4bf213-20261106T190216Z/.
  • Published/deployed PlotLine.dll SHA256 matches: 15dafca838cb2dd8678efe69136fcc400c370585b16a6e2a49909536235a0b66.
  • plotdirector-dev active; local GET and public TLS-validated HTTPS GET both200. No warning-priority service journal entries during qualification. Application-principal SQL smoke checks confirm new tables, append-state handling and archive-inclusive reservation procedure.
  • Live browser smoke used normal antiforgery-protected login and a dedicated temporary account: owner empty state, .plotdirector upload validation, filename/book selection, new-project preview, explicit unchecked confirmation, manuscript ribbon POST, /Imports redirect and contextual Help all passed. No live restore was confirmed. The temporary identity was removed through the normal complete account-deletion workflow; its private credential file was deleted.

Configuration, uploads and existing data-protection keys were preserved. No new configuration or external services are required. Production and the Windows Companion source/installation were not changed.

Author acceptance

Use a non-production test book first. On Development, back up one book, inspect the file and restore into a new test project. Check scene prose, planning/Intent, characters, maps and attachments. Repeat with several/all books and an existing owned destination. Verify duplicate refusal, preserved archive status and shared-data conflict previews. Only deliberately delete an online test book after checking its backup; then verify its released slot permits a fresh restore. Saved-point rewind remains a separate explicit replacement operation.