feat(backup): add MinIO snapshot backups via CLI and scheduler
This commit is contained in:
@@ -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.');
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -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');
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user