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
fix(backup): namespace snapshots by machine hostname
[._.]/ Adam Eivy39a5a2befd7a
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex c14982b894..e0b3e6a59a 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -32,6 +32,8 @@## Changed+- **Backup snapshots are namespaced by machine hostname.** Snapshots now write to `<destPath>/snapshots/<hostname>/<snapshotId>` instead of the prior flat `<destPath>/snapshots/<snapshotId>` layout, so a single shared destination (e.g. an iCloud Drive folder) can host backups from multiple machines without snapshot-ID collisions. The hostname is lowercased and stripped to `[\w.\-]` for filesystem safety, captured once at module load. `listSnapshots` and `restoreSnapshot` both scope to the current machine's hostname dir, and the containment guard in `restoreSnapshot` was re-rooted to match. Existing flat-layout snapshots from earlier versions stop appearing in the UI until moved into a hostname subfolder — backward-incompatible on the disk layout but no migration is shipped because the user-base is small and the snapshots are recoverable by hand.+- **Organize from the lightbox + from inside a collection.** `MediaLightbox` footer now hosts an Add-to-collection (folder+) button alongside Download — pick a collection (or create one) without closing the larger preview. `MediaCollectionDetail` cards no longer suppress the same menu, so you can move/copy an item between collections from inside any collection view. `AddToCollectionMenu` gained a `size` prop (`sm` default for the card action row, `md` for the lightbox footer) so both surfaces share one component without duplicate styling, and long collection names in the picker now wrap instead of getting clipped with ellipsis. `browser/data/` is now gitignored (CDP profile cache shouldn't be tracked).- **Bulk actions on a collection's contents.** A new "Select" button on `/media/collections/:id` flips the grid into selection mode — click cards to add to the selection, then act on the lot via a sticky toolbar: **Star** / **Unstar** all selected, **Move…** or **Copy…** to a target collection (pick from a popover anchored to the button, or create a new collection inline), **Remove** from the current collection without deleting the underlying file. Move/Copy guarantees data integrity by tracking which items actually placed in the target before removing them from the source. Sequential per-item HTTP because the server has no per-collection lock; PLAN.md tracks a bulk endpoint for the inevitable 50+-item case.diff --git a/server/services/backup.js b/server/services/backup.jsindex 3711b3a5de..dc96c35518 100644--- a/server/services/backup.js+++ b/server/services/backup.js@@ -10,6 +10,7 @@ import { spawn } from 'child_process';import { createHash } from 'crypto';import { createReadStream } from 'fs';import { access, readFile, readdir, stat, writeFile } from 'fs/promises';+import { hostname } from 'os';import { join, resolve, relative, isAbsolute } from 'path';import { PATHS, ensureDir, readJSONFile } from '../lib/fileUtils.js';import { getEvent } from './eventScheduler.js';@@ -19,6 +20,12 @@ import { checkHealth } from '../lib/db.js';let isRunning = false;const STATE_PATH = join(PATHS.data, 'backup', 'state.json');++// Snapshots live under snapshots/<hostname>/<snapshotId> so a single shared+// destination (e.g. iCloud) can host backups from multiple machines without+// their snapshot IDs colliding.+const MACHINE_HOST = hostname().toLowerCase().replace(/[^\w.\-]/g, '_') || 'unknown';+const DEFAULT_STATE = {lastRun: null,status: 'never',@@ -96,7 +103,7 @@ export async function runBackup(destPath, io = null, { excludePaths = [] } = {})isRunning = true;const snapshotId = new Date().toISOString().replace(/:/g, '-').replace(/\..+/, '');- const snapshotDir = join(destPath, 'snapshots', snapshotId);+ const snapshotDir = join(destPath, 'snapshots', MACHINE_HOST, snapshotId);const dataDestDir = join(snapshotDir, 'data');console.log(`💾 Backup starting: snapshot ${snapshotId}${excludePaths.length ? ` (excluding ${excludePaths.length} paths)` : ''}`);@@ -254,7 +261,7 @@ export async function generateManifest(snapshotDataDir, manifestPath) {export async function listSnapshots(destPath) {if (!destPath) return [];- const snapshotsDir = join(destPath, 'snapshots');+ const snapshotsDir = join(destPath, 'snapshots', MACHINE_HOST);const entries = await readdir(snapshotsDir).catch(() => []);const snapshots = await Promise.all(@@ -289,11 +296,10 @@ export async function restoreSnapshot(destPath, snapshotId, { dryRun = true, subif (!snapshotId || !/^[\w\-.:T]+$/.test(snapshotId)) {throw new Error(`Invalid snapshotId: ${snapshotId}`);}- const srcDir = join(destPath, 'snapshots', snapshotId, 'data');- // Containment check: resolved path must stay within the snapshots directory.+ const snapshotsRoot = resolve(join(destPath, 'snapshots', MACHINE_HOST));+ const srcDir = join(snapshotsRoot, snapshotId, 'data');// Use path.relative to stay cross-platform and avoid prefix-match pitfalls// (e.g. /snaps vs /snaps2).- const snapshotsRoot = resolve(join(destPath, 'snapshots'));const rel = relative(snapshotsRoot, resolve(srcDir));if (!rel || rel.startsWith('..') || isAbsolute(rel)) {throw new Error(`Path traversal detected for snapshotId: ${snapshotId}`);