backup / restoreslop

This commit is contained in:
legop3
2026-09-14 19:09:02 -04:00
parent edc1b825f2
commit 1c34849bd0
32 changed files with 1220 additions and 70 deletions
@@ -136,5 +136,17 @@ module.exports = {
get reportBuilder() {
return runtime?.reportBuilder || null;
},
backupDatabase(destinationPath) {
/*
Backups include reporting history even when collection is currently
disabled. Lazily opening the existing store keeps this one operation
behind the report service's normal database ownership boundary.
*/
if (!storage) {
storage = createStorage({ logger });
storage.open();
}
return storage.backupDatabase(destinationPath);
},
stop: stopRuntime,
};
@@ -508,6 +508,16 @@ function createStorage({ logger }) {
}), { available: false, path: DB_PATH });
}
function backupDatabase(destinationPath) {
/*
Fleet collection may continue during an online SQLite backup. Each
resulting database file represents a valid point-in-time snapshot even
when new telemetry commits before the copy completes.
*/
if (!open()) throw new Error('Fleet report database is unavailable.');
return db.backup(destinationPath);
}
return {
open,
insertEvent,
@@ -525,6 +535,7 @@ function createStorage({ logger }) {
getActiveBattery,
replaceBattery,
getDiagnostics,
backupDatabase,
};
}