fix(backup): manual snapshot CLI must open its own DB handle (getRawDb undefined in standalone process)
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user