mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-29 19:59:32 +00:00
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
import {
|
|
createBackupArchive,
|
|
formatBackupCreateSummary,
|
|
type BackupCreateOptions,
|
|
type BackupCreateResult,
|
|
} from "../infra/backup-create.js";
|
|
import { type RuntimeEnv, writeRuntimeJson } from "../runtime.js";
|
|
import { createLazyImportLoader } from "../shared/lazy-promise.js";
|
|
export type { BackupCreateOptions, BackupCreateResult } from "../infra/backup-create.js";
|
|
|
|
type BackupVerifyRuntime = typeof import("./backup-verify.js");
|
|
|
|
const backupVerifyRuntimeLoader = createLazyImportLoader<BackupVerifyRuntime>(
|
|
() => import("./backup-verify.js"),
|
|
);
|
|
|
|
function loadBackupVerifyRuntime(): Promise<BackupVerifyRuntime> {
|
|
return backupVerifyRuntimeLoader.load();
|
|
}
|
|
|
|
export async function backupCreateCommand(
|
|
runtime: RuntimeEnv,
|
|
opts: BackupCreateOptions = {},
|
|
): Promise<BackupCreateResult> {
|
|
const result = await createBackupArchive({
|
|
...opts,
|
|
log: opts.log ?? (opts.json ? undefined : (message: string) => runtime.log(message)),
|
|
});
|
|
if (opts.verify && !opts.dryRun) {
|
|
const { backupVerifyCommand } = await loadBackupVerifyRuntime();
|
|
await backupVerifyCommand(
|
|
{
|
|
...runtime,
|
|
log: () => {},
|
|
},
|
|
{ archive: result.archivePath, json: false },
|
|
);
|
|
result.verified = true;
|
|
}
|
|
if (opts.json) {
|
|
writeRuntimeJson(runtime, result);
|
|
} else {
|
|
runtime.log(formatBackupCreateSummary(result).join("\n"));
|
|
}
|
|
return result;
|
|
}
|