import { pathToFileURL } from 'node:url'; import { openReadOnlyStore } from './db.mjs'; export async function createBackup(args, env = process.env) { if (args.length !== 2 || args[0] !== '--output') throw new Error('Invalid arguments'); const store = openReadOnlyStore(env.DB_PATH); try { await store.backup(args[1]); } finally { store.close(); } } if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { createBackup(process.argv.slice(2)).then(() => { process.stdout.write('{"ok":true}\n'); }).catch(() => { process.stderr.write('Backup failed; check existing DB_PATH and a new absolute private --output path\n'); process.exitCode = 1; }); }