UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

4 lines • 3.95 kB
import{o as writeRuntimeJson}from"./runtime-DIcLIHcp.mjs";import{t as createDeferredCore}from"./deferred-QsZCoVH-.mjs";import{r as terminalText}from"./safe-text-B_QTgn0s.mjs";import{t as formatErrorMessage}from"./errors-D37BJTfI.mjs";import{c as registerSignalExitGate}from"./signal-exit-barrier-DoATIAtq.mjs";import{p as withCommandProcessScope}from"./exec-spawn-DNCbDcyJ.mjs";import{t as beginLifecycleWriteCustody}from"./lifecycle-write-custody-DT29oSqg.mjs";import{n as throwExpectedCliError}from"./expected-cli-error-oDVmXYil.mjs";import{a as recordBackupOutcomeBestEffort}from"./backup-shared-CVcoDGTC.mjs";import{n as createBackupArchive}from"./backup-create-DR5LC2qR.mjs";import{t as createBackupProgressLogger}from"./backup-progress-D6RlLyBn.mjs";import{i as resolveBackupNamespace}from"./backup-retention-CCINX3jT.mjs"; //!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))throwExpectedCliError(`--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;const l=createBackupProgressLogger(n=>t.json?e.error(n):e.log(n));const u=t.onProgress??l;try{if(t.to!==void 0)c=resolveBackupNamespace(t.namespace);const r=await withCommandProcessScope(async n=>{a=n;const r={...t,onProgress:u,log:t.log??(t.json?void 0:t=>e.log(terminalText`${t}`))};if(t.to!==void 0){const{createOffsiteBackupArchive:e}=await import(`./backup-remote-4bujVbE3.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-BAkqlnU1.mjs`);await e(r.archivePath,[],u);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(` `));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{l.finish();r?.(s);i.resolve();o()}}export{backupCreateCommand as t};