Run scheduled backups in an isolated subprocess

This commit is contained in:
syntaxbullet
2026-09-08 16:12:53 +02:00
parent 31e4f3b2ef
commit b0950cb4b4
4 changed files with 98 additions and 14 deletions

View File

@@ -0,0 +1,16 @@
import { Database } from 'bun:sqlite';
import { createBackup, latestBackupTime, type BackupConfig } from '../src/ops/backups';
const path = process.argv[2];
if (!path || !process.argv[3]) throw new Error('Expected database path and backup configuration');
const config = JSON.parse(process.argv[3]) as BackupConfig;
const latest = latestBackupTime(config);
if (latest && Date.now() - latest < config.intervalMs) console.log(JSON.stringify({ timestamp: latest, created: false }));
else {
const db = new Database(path, { readonly: true, strict: true });
try {
db.exec('PRAGMA busy_timeout=5000');
createBackup(db, config);
console.log(JSON.stringify({ timestamp: latestBackupTime(config), created: true }));
} finally { db.close(); }
}