30 lines
1.7 KiB
TypeScript
Executable File
30 lines
1.7 KiB
TypeScript
Executable File
import { createCoordinatedCustodyBackup, verifyCoordinatedCustodyBackup } from '../server/coordinated-backup.ts';
|
|
|
|
const [action, ...args] = process.argv.slice(2);
|
|
if (action !== 'create' && action !== 'verify') throw new Error('Expected create or verify');
|
|
const allowed = new Set(['--source', '--destination', '--consent', '--pg-restore-binary']);
|
|
for (let index = 0; index < args.length; index++) {
|
|
if (!allowed.has(args[index]) || (args[index] !== '--consent' && (!args[index + 1] || args[index + 1].startsWith('--')))) {
|
|
throw new Error('Invalid coordinated backup arguments');
|
|
}
|
|
if (args[index] !== '--consent') index++;
|
|
}
|
|
const value = (name: string) => { const index = args.indexOf(name); return index < 0 ? undefined : args[index + 1]; };
|
|
const source = value('--source');
|
|
if (!source) throw new Error('Explicit --source is required');
|
|
let result: unknown;
|
|
try {
|
|
if (action === 'create') {
|
|
const destination = value('--destination');
|
|
if (!destination || !args.includes('--consent')) throw new Error('Create requires --destination and explicit --consent');
|
|
result = await createCoordinatedCustodyBackup(source, destination);
|
|
} else {
|
|
if (value('--destination') || args.includes('--consent')) throw new Error('Verify accepts --source and optional --pg-restore-binary');
|
|
result = await verifyCoordinatedCustodyBackup(source, value('--pg-restore-binary'));
|
|
}
|
|
console.log(JSON.stringify(result, null, 2));
|
|
} catch {
|
|
console.error('Coordinated backup failed; check stopped-node state, separate backup credentials, PostgreSQL tools, destination permissions and partial output privately. No source database was reset.');
|
|
process.exitCode = 1;
|
|
}
|