diff --git a/packages/server/src/scripts/snapshot.ts b/packages/server/src/scripts/snapshot.ts index b094a8b7..86a3683f 100644 --- a/packages/server/src/scripts/snapshot.ts +++ b/packages/server/src/scripts/snapshot.ts @@ -1,6 +1,17 @@ -import { getRawDb } from '../db/index.js'; +import Database from 'better-sqlite3'; +import { config } from '../config.js'; import { createSnapshot, pruneSnapshots } from '../utils/backup.js'; -const p = createSnapshot(getRawDb(), 'manual'); -pruneSnapshots(); -console.log('Manual snapshot written: ' + p); +// Standalone manual-snapshot CLI (run via `./backup.sh` → docker exec). Unlike the +// scheduled worker and the pre-migration hook (which run inside the server process +// where initDatabase() already ran), this is a FRESH node process — getRawDb() would +// be undefined here. Open our own handle. VACUUM INTO takes a consistent read snapshot, +// so this is safe to run concurrently with the live server on the same WAL database. +const db = new Database(config.dbPath); +try { + const p = createSnapshot(db, 'manual'); + pruneSnapshots(); + console.log('Manual snapshot written: ' + p); +} finally { + db.close(); +}