Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
docs(02-01): complete backup engine plan - summary, state, roadmap, requirements
Adam Eivy84466da2e208
diff --git a/.changelog/v1.14.x.md b/.changelog/v1.14.x.mdindex e3dc1e4d0b..7d7bc29043 100644--- a/.changelog/v1.14.x.md+++ b/.changelog/v1.14.x.md@@ -6,6 +6,13 @@ Released: YYYY-MM-DDGenome migration cleanup — completed the meatspace data migration so genome, ClinVar, and epigenetic services read/write from the correct `data/meatspace/` directory, with all stale path references updated across services, routes, client navigation, and documentation.+## Features++- **Data backup engine** — rsync-based incremental backup from `./data/` to a configured external drive path, with SHA-256 manifest generation for integrity verification after each snapshot+- **Backup REST API** — `GET /api/backup/status`, `POST /api/backup/run`, `GET /api/backup/snapshots`, `POST /api/backup/restore` with Zod request validation+- **Backup cron scheduler** — daily backup at 2 AM (configurable via `settings.backup.cronExpression`), registered with the existing eventScheduler and started at server boot+- **Backup client API** — `getBackupStatus`, `triggerBackup`, `getBackupSnapshots`, `restoreBackup` added to `client/src/services/api.js` for widget consumption+## Improvements- **Genome migration: service data paths** — updated `genome.js`, `clinvar.js`, and `epigenetic.js` services to use `PATHS.meatspace` instead of `PATHS.digitalTwin`, completing the migration from digital-twin to meatspace storagediff --git a/.planning/REQUIREMENTS.md b/.planning/REQUIREMENTS.mdindex a5c11e0014..3e251d95ac 100644--- a/.planning/REQUIREMENTS.md+++ b/.planning/REQUIREMENTS.md@@ -15,9 +15,9 @@ Requirements for this milestone batch. Each maps to roadmap phases.### Backup-- [ ] **BAK-01**: Incremental rsync backup copies changed files from `./data/` to configurable external drive path-- [ ] **BAK-02**: SHA-256 manifest tracks file integrity across backups-- [ ] **BAK-03**: Daily backup runs via existing scheduler with configurable interval+- [x] **BAK-01**: Incremental rsync backup copies changed files from `./data/` to configurable external drive path+- [x] **BAK-02**: SHA-256 manifest tracks file integrity across backups+- [x] **BAK-03**: Daily backup runs via existing scheduler with configurable interval- [ ] **BAK-04**: Dashboard widget shows last backup time, next scheduled, health status (green/yellow/red)- [ ] **BAK-05**: One-click manual backup trigger from dashboard- [ ] **BAK-06**: Restore from named snapshot with dry-run mode showing what would change@@ -92,9 +92,9 @@ Which phases cover which requirements. Updated during roadmap creation.| GEN-01 | Phase 1 | Complete || GEN-02 | Phase 1 | Complete || GEN-03 | Phase 1 | Complete |-| BAK-01 | Phase 2 | Pending |-| BAK-02 | Phase 2 | Pending |-| BAK-03 | Phase 2 | Pending |+| BAK-01 | Phase 2 | Complete |+| BAK-02 | Phase 2 | Complete |+| BAK-03 | Phase 2 | Complete || BAK-04 | Phase 2 | Pending || BAK-05 | Phase 2 | Pending || BAK-06 | Phase 2 | Pending |diff --git a/.planning/ROADMAP.md b/.planning/ROADMAP.mdindex da85b5baf6..d95b966845 100644--- a/.planning/ROADMAP.md+++ b/.planning/ROADMAP.md@@ -102,7 +102,7 @@ Note: Phases 1 and 2 have no dependency on each other and can execute in paralle| Phase | Plans Complete | Status | Completed ||-------|----------------|--------|-----------|| 1. Genome Migration Cleanup | 1/1 | Complete | 2026-02-26 |-| 2. Data Backup & Recovery | 0/2 | Not started | - |+| 2. Data Backup & Recovery | 1/2 | In Progress| || 3. Apple Health Integration | 0/2 | Not started | - || 4. Cross-Domain Insights Engine | 0/2 | Not started | - || 5. Unified Search (Cmd+K) | 0/1 | Not started | - |diff --git a/.planning/STATE.md b/.planning/STATE.mdindex dbf7711f84..c46edb10ef 100644--- a/.planning/STATE.md+++ b/.planning/STATE.md@@ -2,13 +2,13 @@gsd_state_version: 1.0milestone: v1.0milestone_name: milestone-status: unknown-last_updated: "2026-02-26T21:28:05.121Z"+status: in_progress+last_updated: "2026-02-26T22:08:05.000Z"progress:- total_phases: 1+ total_phases: 5completed_phases: 1- total_plans: 1- completed_plans: 1+ total_plans: 6+ completed_plans: 2---# Project State@@ -18,16 +18,16 @@ progress:See: .planning/PROJECT.md (updated 2026-02-26)**Core value:** Ship five next actions that transform PortOS from siloed features into a connected, protected, and searchable system-**Current focus:** Phase 1 - Genome Migration Cleanup+**Current focus:** Phase 2 - Data Backup & Recovery## Current Position-Phase: 1 of 5 (Genome Migration Cleanup)-Plan: 1 of 1 in current phase+Phase: 2 of 5 (Data Backup & Recovery)+Plan: 1 of 2 in current phaseStatus: In progress-Last activity: 2026-02-26 -- Plan 01-01 complete+Last activity: 2026-02-26 -- Plan 02-01 complete-Progress: [█░░░░░░░░░] 10%+Progress: [██░░░░░░░░] 20%## Performance Metrics@@ -41,10 +41,11 @@ Progress: [█░░░░░░░░░] 10%| Phase | Plans | Total | Avg/Plan ||-------|-------|-------|----------|| 01-genome-migration-cleanup | 1 | 108s | 108s |+| 02-data-backup-recovery | 1 | 135s | 135s |**Recent Trend:**-- Last 5 plans: 01-01 (108s)-- Trend: N/A (first plan)+- Last 5 plans: 01-01 (108s), 02-01 (135s)+- Trend: stable (~2 min/plan)*Updated after each plan completion*@@ -61,6 +62,9 @@ Recent decisions affecting current work:- Genome-to-health and taste-to-identity as priority insight domains- Used PATHS.meatspace (existing constant) for genome migration — no new constant needed- Moved genome data files with mv (not copy) to prevent stale digital-twin copies+- createReadStream only available on 'fs' not 'fs/promises' — fixed import in backup.js+- Exit code 24 from rsync means files vanished mid-transfer (acceptable for active systems)+- startBackupScheduler is async (reads settings) — called with .catch() in index.js like other async inits### Pending Todos@@ -75,5 +79,5 @@ None yet.## Session ContinuityLast session: 2026-02-26-Stopped at: Completed 01-01-PLAN.md (genome migration cleanup)+Stopped at: Completed 02-01-PLAN.md (backup engine and API)Resume file: Nonediff --git a/.planning/phases/02-data-backup-recovery/02-01-SUMMARY.md b/.planning/phases/02-data-backup-recovery/02-01-SUMMARY.mdnew file mode 100644index 0000000000..bbe44d738c--- /dev/null+++ b/.planning/phases/02-data-backup-recovery/02-01-SUMMARY.md@@ -0,0 +1,109 @@+---+phase: 02-data-backup-recovery+plan: "01"+subsystem: backup+tags: [backup, rsync, scheduler, api, validation]+dependency_graph:+ requires:+ - server/services/eventScheduler.js+ - server/services/settings.js+ - server/lib/fileUtils.js+ - server/lib/errorHandler.js+ - server/lib/validation.js+ provides:+ - server/services/backup.js+ - server/services/backupScheduler.js+ - server/routes/backup.js+ affects:+ - server/index.js+ - server/lib/validation.js+ - client/src/services/api.js+tech_stack:+ added:+ - rsync (system binary, /usr/bin/rsync)+ - Node.js crypto.createHash (SHA-256)+ - Node.js fs.createReadStream (streaming hash for large files)+ patterns:+ - Rsync incremental backup with itemize-changes and exit code 24 tolerance+ - SHA-256 file manifest with size-based streaming threshold (512KB)+ - eventScheduler cron integration (mirroring brainScheduler pattern)+ - asyncHandler + validateRequest route pattern+key_files:+ created:+ - server/services/backup.js+ - server/services/backupScheduler.js+ - server/routes/backup.js+ modified:+ - server/lib/validation.js+ - server/index.js+ - client/src/services/api.js+decisions:+ - "Used fs.createReadStream (not fs/promises) for streaming hash — createReadStream is only available on the synchronous fs module"+ - "Exit code 24 accepted as success — rsync code 24 means files vanished mid-transfer, normal for active systems"+ - "startBackupScheduler is async (reads settings) and called with .catch() in index.js to match other async inits"+metrics:+ duration: 135s+ completed: 2026-02-26+ tasks_completed: 2+ files_created: 3+ files_modified: 3+---++# Phase 02 Plan 01: Backup Engine and API Summary++**One-liner:** Rsync-based incremental backup engine with SHA-256 manifests, daily cron scheduling via eventScheduler, and a complete REST + client API.++## What Was Built++A complete backup infrastructure for PortOS data:++1. **`server/services/backup.js`** — Core backup engine with 7 exports:+ - `runBackup(destPath, io)` — spawns rsync to copy `data/` to a timestamped snapshot directory, generates manifest, saves state+ - `generateManifest(snapshotDataDir, manifestPath)` — walks snapshot files, hashes each (streaming for 512KB+), writes `manifest.json`+ - `listSnapshots(destPath)` — reads snapshot directories, returns metadata sorted newest-first+ - `restoreSnapshot(destPath, snapshotId, { dryRun, subdirFilter })` — reverse rsync from snapshot back to live data+ - `getState()` / `saveState(patch)` — persist backup state to `data/backup/state.json`+ - `getNextRunTime()` — delegates to eventScheduler's `getEvent('backup-daily')`++2. **`server/services/backupScheduler.js`** — Reads settings, conditionally registers `backup-daily` cron with eventScheduler. Skips if disabled or no destPath configured.++3. **`server/routes/backup.js`** — 4 REST endpoints:+ - `GET /api/backup/status` — state + destPath + nextRun+ - `POST /api/backup/run` — trigger immediate backup+ - `GET /api/backup/snapshots` — list snapshots+ - `POST /api/backup/restore` — restore with dryRun support++4. **`server/lib/validation.js`** — Added `backupConfigSchema` and `restoreRequestSchema` Zod schemas.++5. **`server/index.js`** — Routes mounted at `/api/backup`; `startBackupScheduler()` called after `startBrainScheduler()`.++6. **`client/src/services/api.js`** — Added `getBackupStatus`, `triggerBackup`, `getBackupSnapshots`, `restoreBackup`.++## Deviations from Plan++### Auto-fixed Issues++**1. [Rule 3 - Blocking] Fixed `createReadStream` import from wrong module**+- **Found during:** Task 1 verification+- **Issue:** `createReadStream` is not exported by `fs/promises`; initial code imported it from there+- **Fix:** Split import — `createReadStream` from `'fs'`, file stat/read functions from `'fs/promises'`+- **Files modified:** `server/services/backup.js`+- **Commit:** 8a01c2b (fixed inline before committing)++## Commits++| Task | Name | Commit | Key Files |+|------|------|--------|-----------|+| 1 | Backup service and scheduler | 8a01c2b | server/services/backup.js, server/services/backupScheduler.js |+| 2 | Routes, validation, server wiring, client API | 523ffd7 | server/routes/backup.js, server/lib/validation.js, server/index.js, client/src/services/api.js |++## Verification Results++- backup.js imports without errors: exports generateManifest, getNextRunTime, getState, listSnapshots, restoreSnapshot, runBackup, saveState+- backupScheduler.js imports without errors: exports startBackupScheduler, stopBackupScheduler+- All 42 server test files pass (1192 tests) — no regressions+- validation.js contains backupConfigSchema and restoreRequestSchema (2 schema exports)+- server/index.js mounts /api/backup and calls startBackupScheduler()+- client/src/services/api.js exports all 4 backup API functions++## Self-Check: PASSED