feat(backup): add MinIO snapshot backups via CLI and scheduler

This commit is contained in:
William Valentin
2026-02-16 13:16:29 -08:00
parent 8bed99c770
commit 01ee6ba53f
13 changed files with 416 additions and 1 deletions
+40
View File
@@ -0,0 +1,40 @@
import type { Command } from 'commander';
import { getDataDir, loadConfigSafe } from './shared.js';
import { runBackupSnapshot } from '../backup/index.js';
export function registerBackupCommand(program: Command): void {
program
.command('backup')
.description('Create a snapshot backup and optionally upload to MinIO')
.option('-c, --config <path>', 'Config file path')
.option('--data-dir <path>', 'Data directory (defaults to FLYNN_DATA_DIR or ~/.local/share/flynn)')
.option('--no-upload', 'Disable MinIO upload for this run')
.action(async (opts: { config?: string; dataDir?: string; upload?: boolean }) => {
const { config, error } = loadConfigSafe(opts.config);
if (!config) {
console.error(error);
process.exit(1);
}
const backupConfig = {
...config.backup,
minio: {
...config.backup.minio,
enabled: opts.upload === false ? false : config.backup.minio.enabled,
},
};
const dataDir = opts.dataDir ?? getDataDir();
const result = await runBackupSnapshot({
dataDir,
backupConfig,
});
console.log(`Backup archive: ${result.archivePath}`);
if (result.uploaded && result.remotePath) {
console.log(`Uploaded to MinIO: ${result.remotePath}`);
} else {
console.log('MinIO upload skipped.');
}
});
}
+1
View File
@@ -13,6 +13,7 @@ describe('CLI program', () => {
expect(commandNames).toContain('doctor');
expect(commandNames).toContain('config');
expect(commandNames).toContain('skills');
expect(commandNames).toContain('backup');
expect(commandNames).toContain('openai-auth');
expect(commandNames).toContain('openai-key');
+2
View File
@@ -27,6 +27,7 @@ import { registerOpenaiKeyCommand } from './openai-key.js';
import { registerZaiAuthCommand } from './zai-auth.js';
import { registerAnthropicAuthCommand } from './anthropic-auth.js';
import { registerSkillsCommand } from './skills.js';
import { registerBackupCommand } from './backup.js';
export function createProgram(): Command {
const program = new Command();
@@ -54,6 +55,7 @@ export function createProgram(): Command {
registerZaiAuthCommand(program);
registerAnthropicAuthCommand(program);
registerSkillsCommand(program);
registerBackupCommand(program);
return program;
}