UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

109 lines (108 loc) • 4.32 kB
import { o as writeRuntimeJson } from "./runtime-B-SLYP-m.mjs"; import { r as terminalText } from "./safe-text-C80HAQ2e.mjs"; import { t as formatErrorMessage } from "./errors-BKzCeTYb.mjs"; import { t as createDeferredCore } from "./deferred-D0La5CRk.mjs"; import { c as registerSignalExitGate } from "./signal-exit-barrier-BOGtFHQL.mjs"; import { f as withCommandProcessScope } from "./exec-spawn-DMKoejF-.mjs"; import { t as beginLifecycleWriteCustody } from "./lifecycle-write-custody-B171kU9T.mjs"; import { a as recordBackupOutcomeBestEffort } from "./backup-shared-BmR-itzA.mjs"; import { n as createBackupArchive } from "./backup-create-DPz1QWv1.mjs"; import { i as resolveBackupNamespace } from "./backup-retention-D-I6jsEu.mjs"; //#region src/commands/backup.ts async function backupCreateCommand(e, t = {}) { if (t.to === void 0 && [ t.namespace, t.claimNamespace, t.keepDaily, t.keepWeekly, t.keepMonthly ].some((e) => e !== void 0)) throw new Error("--namespace, --claim-namespace, and retention flags require --to <location>."); let n = t.output ?? (t.to === void 0 ? process.cwd() : `storage://${t.to}`); const r = t.dryRun ? void 0 : beginLifecycleWriteCustody("backup"); const i = createDeferredCore(); let a; const o = registerSignalExitGate(i.promise, () => a?.()); let s; let c = t.namespace; try { if (t.to !== void 0) c = resolveBackupNamespace(t.namespace); const r = await withCommandProcessScope(async (n) => { a = n; const r = { ...t, log: t.log ?? (t.json ? void 0 : (t) => e.log(terminalText`${t}`)) }; if (t.to !== void 0) { const { createOffsiteBackupArchive: e } = await import("./backup-remote-rWD_Ythx.mjs"); return await e({ ...r, to: t.to, namespace: c }); } return await createBackupArchive(r); }); n = r.archivePath; if (t.verify && !t.dryRun && !r.verified) { const { verifyBackupArchive: e } = await import("./backup-verify-CyW6XuB4.mjs"); await e(r.archivePath); r.verified = true; } if (!t.dryRun) await recordBackupOutcomeBestEffort(e, { kind: "archive", archivePath: n, status: "ok", ...t.to !== void 0 ? { target: t.to, namespace: c, location: r.location, retention: r.retention, bytes: r.location?.plaintextBytes } : {} }); if (t.json) writeRuntimeJson(e, r); else { const t = [terminalText`Backup archive: ${r.archivePath}`]; t.push(terminalText`Included ${r.assets.length} path${r.assets.length === 1 ? "" : "s"}:`); for (const e of r.assets) t.push(terminalText`- ${e.kind}: ${e.displayPath}`); if (r.skipped.length > 0) { t.push(terminalText`Skipped ${r.skipped.length} path${r.skipped.length === 1 ? "" : "s"}:`); for (const e of r.skipped) { const n = e.reason === "covered" && e.coveredBy ? ` by ${e.coveredBy}` : ""; t.push(terminalText`- ${e.kind}: ${e.displayPath} (${e.reason}${n})`); } } for (const e of r.externalSymbolicLinks ?? []) t.push(terminalText`External link preserved (target not copied through link): ${JSON.stringify(e.entryPath)} -> ${JSON.stringify(e.linkpath)}`); if (r.dryRun) t.push("Dry run only; archive was not written."); else { t.push(terminalText`Created ${r.archivePath}`); if (r.skippedVolatileCount > 0) t.push(terminalText`Skipped ${r.skippedVolatileCount} volatile file${r.skippedVolatileCount === 1 ? "" : "s"} (live sessions, cron logs, queues, managed runtime paths, sockets, pid/tmp).`); if (r.verified) t.push("Archive verification: passed"); } t.push(...(r.warnings ?? []).map((e) => terminalText`${e}`)); e.log(t.join("\n")); if (r.location) e.log(terminalText`Uploaded to ${r.location.name}/backups/${r.location.namespace}/${r.location.key} (${r.location.storedBytes} stored bytes).${r.localArchiveRetained ? " Local archive retained." : ""}`); if (r.retention) e.log(`Retention: ${r.retention.kept} kept, ${r.retention.deleted} deleted.`); } return r; } catch (r) { s = r; if (!t.dryRun) await recordBackupOutcomeBestEffort(e, { kind: "archive", archivePath: n, status: "failed", error: formatErrorMessage(r), ...t.to !== void 0 ? { target: t.to, namespace: c } : {} }); throw r; } finally { r?.(s); i.resolve(); o(); } } //#endregion export { backupCreateCommand as t };