clawon 0.1.9 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -1
- package/dist/index.js +280 -33
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,6 +22,7 @@ Local backups are stored in `~/.clawon/backups/` as standard `.tar.gz` archives.
|
|
|
22
22
|
npx clawon local backup
|
|
23
23
|
npx clawon local backup --tag "before migration"
|
|
24
24
|
npx clawon local backup --include-memory-db # Include SQLite memory index
|
|
25
|
+
npx clawon local backup --max-snapshots 10 # Keep only 10 most recent
|
|
25
26
|
|
|
26
27
|
# List all local backups
|
|
27
28
|
npx clawon local list
|
|
@@ -32,6 +33,27 @@ npx clawon local restore --pick 2 # Backup #2 from list
|
|
|
32
33
|
npx clawon local restore --file path.tar.gz # External file
|
|
33
34
|
```
|
|
34
35
|
|
|
36
|
+
### Scheduled Backups
|
|
37
|
+
|
|
38
|
+
Set up automatic backups via cron (macOS/Linux only).
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
# Schedule local backups every 12 hours (default)
|
|
42
|
+
npx clawon local schedule on
|
|
43
|
+
npx clawon local schedule on --every 6h --max-snapshots 10
|
|
44
|
+
npx clawon local schedule on --include-memory-db
|
|
45
|
+
|
|
46
|
+
# Disable local schedule
|
|
47
|
+
npx clawon local schedule off
|
|
48
|
+
|
|
49
|
+
# Schedule cloud backups (requires Hobby or Pro account)
|
|
50
|
+
npx clawon schedule on
|
|
51
|
+
npx clawon schedule off
|
|
52
|
+
|
|
53
|
+
# Check schedule status
|
|
54
|
+
npx clawon schedule status
|
|
55
|
+
```
|
|
56
|
+
|
|
35
57
|
### Cloud Backups (requires account)
|
|
36
58
|
|
|
37
59
|
Cloud backups sync your workspace to Clawon's servers for cross-machine access.
|
|
@@ -66,6 +88,7 @@ npx clawon activity # Recent events
|
|
|
66
88
|
```bash
|
|
67
89
|
npx clawon discover # Show exactly which files would be backed up
|
|
68
90
|
npx clawon discover --include-memory-db # Include SQLite memory index
|
|
91
|
+
npx clawon schedule status # Show active schedules
|
|
69
92
|
npx clawon status # Connection status and file count
|
|
70
93
|
npx clawon logout # Remove local credentials
|
|
71
94
|
```
|
|
@@ -83,6 +106,9 @@ Clawon uses an **allowlist** — only files matching these patterns are included
|
|
|
83
106
|
| `workspace/canvas/**` | Canvas data |
|
|
84
107
|
| `skills/**` | Top-level skills |
|
|
85
108
|
| `agents/*/config.json` | Agent configurations |
|
|
109
|
+
| `agents/*/models.json` | Model preferences |
|
|
110
|
+
| `agents/*/agent/**` | Agent config data |
|
|
111
|
+
| `cron/runs/*.jsonl` | Cron run logs |
|
|
86
112
|
|
|
87
113
|
Run `npx clawon discover` to see the exact file list for your instance.
|
|
88
114
|
|
|
@@ -94,7 +120,9 @@ These are **always excluded**, even if they match an include pattern:
|
|
|
94
120
|
|---------|-----|
|
|
95
121
|
| `credentials/**` | API keys, tokens, auth files |
|
|
96
122
|
| `openclaw.json` | May contain credentials |
|
|
97
|
-
| `agents/*/
|
|
123
|
+
| `agents/*/auth.json` | Authentication data |
|
|
124
|
+
| `agents/*/auth-profiles.json` | Auth profiles |
|
|
125
|
+
| `agents/*/sessions/**` | Chat history (large, use future `--include-sessions`) |
|
|
98
126
|
| `memory/lancedb/**` | Vector database (binary, large) |
|
|
99
127
|
| `memory/*.sqlite` | SQLite databases (use `--include-memory-db` to include) |
|
|
100
128
|
| `*.lock`, `*.wal`, `*.shm` | Database lock files |
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import { Command } from "commander";
|
|
|
5
5
|
import fs from "fs";
|
|
6
6
|
import path from "path";
|
|
7
7
|
import os from "os";
|
|
8
|
+
import { execSync } from "child_process";
|
|
8
9
|
import * as tar from "tar";
|
|
9
10
|
var CONFIG_DIR = path.join(os.homedir(), ".clawon");
|
|
10
11
|
var CONFIG_PATH = path.join(CONFIG_DIR, "config.json");
|
|
@@ -21,6 +22,15 @@ function writeConfig(cfg) {
|
|
|
21
22
|
ensureDir(CONFIG_DIR);
|
|
22
23
|
fs.writeFileSync(CONFIG_PATH, JSON.stringify(cfg, null, 2));
|
|
23
24
|
}
|
|
25
|
+
function updateConfig(partial) {
|
|
26
|
+
const existing = readConfig() || {};
|
|
27
|
+
const merged = { ...existing, ...partial };
|
|
28
|
+
if (partial.schedule) {
|
|
29
|
+
merged.schedule = { ...existing.schedule, ...partial.schedule };
|
|
30
|
+
}
|
|
31
|
+
ensureDir(CONFIG_DIR);
|
|
32
|
+
fs.writeFileSync(CONFIG_PATH, JSON.stringify(merged, null, 2));
|
|
33
|
+
}
|
|
24
34
|
async function api(baseUrl, endpoint, method, apiKey, body) {
|
|
25
35
|
const res = await fetch(`${baseUrl}${endpoint}`, {
|
|
26
36
|
method,
|
|
@@ -41,11 +51,16 @@ var INCLUDE_PATTERNS = [
|
|
|
41
51
|
"workspace/skills/**",
|
|
42
52
|
"workspace/canvas/**",
|
|
43
53
|
"skills/**",
|
|
44
|
-
"agents/*/config.json"
|
|
54
|
+
"agents/*/config.json",
|
|
55
|
+
"agents/*/models.json",
|
|
56
|
+
"agents/*/agent/**",
|
|
57
|
+
"cron/runs/*.jsonl"
|
|
45
58
|
];
|
|
46
59
|
var EXCLUDE_PATTERNS = [
|
|
47
60
|
"credentials/**",
|
|
48
61
|
"openclaw.json",
|
|
62
|
+
"agents/*/auth.json",
|
|
63
|
+
"agents/*/auth-profiles.json",
|
|
49
64
|
"agents/*/sessions/**",
|
|
50
65
|
"memory/lancedb/**",
|
|
51
66
|
"memory/*.sqlite",
|
|
@@ -97,13 +112,14 @@ function discoverFiles(baseDir, includeMemoryDb = false) {
|
|
|
97
112
|
walk(baseDir);
|
|
98
113
|
return files;
|
|
99
114
|
}
|
|
100
|
-
async function createLocalArchive(files, openclawDir, outputPath, tag, includeMemoryDb) {
|
|
115
|
+
async function createLocalArchive(files, openclawDir, outputPath, tag, includeMemoryDb, trigger) {
|
|
101
116
|
const meta = {
|
|
102
117
|
version: 2,
|
|
103
118
|
created: (/* @__PURE__ */ new Date()).toISOString(),
|
|
104
119
|
...tag ? { tag } : {},
|
|
105
120
|
file_count: files.length,
|
|
106
|
-
...includeMemoryDb ? { include_memory_db: true } : {}
|
|
121
|
+
...includeMemoryDb ? { include_memory_db: true } : {},
|
|
122
|
+
...trigger ? { trigger } : {}
|
|
107
123
|
};
|
|
108
124
|
const metaPath = path.join(openclawDir, "_clawon_meta.json");
|
|
109
125
|
fs.writeFileSync(metaPath, JSON.stringify(meta, null, 2));
|
|
@@ -157,6 +173,67 @@ function trackCliEvent(distinctId, event, properties = {}) {
|
|
|
157
173
|
}).catch(() => {
|
|
158
174
|
});
|
|
159
175
|
}
|
|
176
|
+
var CRON_MARKER_LOCAL = "# clawon-schedule-local";
|
|
177
|
+
var CRON_MARKER_CLOUD = "# clawon-schedule-cloud";
|
|
178
|
+
var SCHEDULE_LOG = path.join(CONFIG_DIR, "schedule.log");
|
|
179
|
+
var INTERVAL_CRON = {
|
|
180
|
+
"1h": "0 * * * *",
|
|
181
|
+
"6h": "0 */6 * * *",
|
|
182
|
+
"12h": "0 */12 * * *",
|
|
183
|
+
"24h": "0 0 * * *"
|
|
184
|
+
};
|
|
185
|
+
var VALID_INTERVALS = Object.keys(INTERVAL_CRON);
|
|
186
|
+
function resolveCliCommand(args) {
|
|
187
|
+
const nodePath = process.execPath;
|
|
188
|
+
const cliEntry = path.resolve(import.meta.dirname, "index.js");
|
|
189
|
+
return `${nodePath} ${cliEntry} ${args}`;
|
|
190
|
+
}
|
|
191
|
+
function getCurrentCrontab() {
|
|
192
|
+
try {
|
|
193
|
+
return execSync("crontab -l 2>/dev/null", { encoding: "utf8" });
|
|
194
|
+
} catch {
|
|
195
|
+
return "";
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function setCrontab(content) {
|
|
199
|
+
const tmpFile = path.join(CONFIG_DIR, ".crontab-tmp");
|
|
200
|
+
ensureDir(CONFIG_DIR);
|
|
201
|
+
fs.writeFileSync(tmpFile, content);
|
|
202
|
+
try {
|
|
203
|
+
execSync(`crontab ${tmpFile}`, { encoding: "utf8" });
|
|
204
|
+
} finally {
|
|
205
|
+
fs.unlinkSync(tmpFile);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
function addCronEntry(marker, cronExpr, command) {
|
|
209
|
+
const current = getCurrentCrontab();
|
|
210
|
+
const filtered = current.split("\n").filter((line) => !line.includes(marker)).join("\n");
|
|
211
|
+
const entry = `${cronExpr} ${command} >> ${SCHEDULE_LOG} 2>&1 ${marker}`;
|
|
212
|
+
const updated = filtered.trim() ? `${filtered.trim()}
|
|
213
|
+
${entry}
|
|
214
|
+
` : `${entry}
|
|
215
|
+
`;
|
|
216
|
+
setCrontab(updated);
|
|
217
|
+
}
|
|
218
|
+
function removeCronEntry(marker) {
|
|
219
|
+
const current = getCurrentCrontab();
|
|
220
|
+
const lines = current.split("\n");
|
|
221
|
+
const filtered = lines.filter((line) => !line.includes(marker));
|
|
222
|
+
if (filtered.length === lines.length) return false;
|
|
223
|
+
setCrontab(filtered.join("\n"));
|
|
224
|
+
return true;
|
|
225
|
+
}
|
|
226
|
+
function getCronEntry(marker) {
|
|
227
|
+
const current = getCurrentCrontab();
|
|
228
|
+
const line = current.split("\n").find((l) => l.includes(marker));
|
|
229
|
+
return line || null;
|
|
230
|
+
}
|
|
231
|
+
function assertNotWindows() {
|
|
232
|
+
if (process.platform === "win32") {
|
|
233
|
+
console.error("\u2717 Scheduled backups require cron (macOS/Linux). Windows is not supported yet.");
|
|
234
|
+
process.exit(1);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
160
237
|
var program = new Command();
|
|
161
238
|
program.name("clawon").description("Backup and restore your OpenClaw workspace").version("0.1.1");
|
|
162
239
|
program.command("login").description("Connect to Clawon with your API key").requiredOption("--api-key <key>", "Your Clawon API key").option("--api-url <url>", "API base URL", "https://clawon.io").action(async (opts) => {
|
|
@@ -180,9 +257,9 @@ program.command("login").description("Connect to Clawon with your API key").requ
|
|
|
180
257
|
process.exit(1);
|
|
181
258
|
}
|
|
182
259
|
});
|
|
183
|
-
program.command("backup").description("Backup your OpenClaw workspace to the cloud").option("--dry-run", "Show what would be backed up without uploading").option("--tag <label>", "Add a label to this backup").option("--include-memory-db", "Include SQLite memory index").action(async (opts) => {
|
|
260
|
+
program.command("backup").description("Backup your OpenClaw workspace to the cloud").option("--dry-run", "Show what would be backed up without uploading").option("--tag <label>", "Add a label to this backup").option("--include-memory-db", "Include SQLite memory index").option("--scheduled", "Internal: triggered by cron (suppresses interactive output)").action(async (opts) => {
|
|
184
261
|
if (opts.includeMemoryDb) {
|
|
185
|
-
console.error("\u2717 Memory DB backup requires a Pro account. Use `clawon local backup --include-memory-db` for local backups.");
|
|
262
|
+
console.error("\u2717 Memory DB cloud backup requires a Pro account. Use `clawon local backup --include-memory-db` for local backups.");
|
|
186
263
|
process.exit(1);
|
|
187
264
|
}
|
|
188
265
|
const cfg = readConfig();
|
|
@@ -254,13 +331,18 @@ program.command("backup").description("Backup your OpenClaw workspace to the clo
|
|
|
254
331
|
console.log(` Snapshot ID: ${snapshotId}`);
|
|
255
332
|
console.log(` Files: ${files.length}`);
|
|
256
333
|
console.log(` Size: ${(totalSize / 1024).toFixed(1)} KB`);
|
|
257
|
-
trackCliEvent(cfg.profileId, "cloud_backup_created", {
|
|
334
|
+
trackCliEvent(cfg.profileId, opts.scheduled ? "scheduled_backup_created" : "cloud_backup_created", {
|
|
258
335
|
file_count: files.length,
|
|
259
336
|
total_bytes: totalSize,
|
|
260
|
-
include_memory_db: !!opts.includeMemoryDb
|
|
337
|
+
include_memory_db: !!opts.includeMemoryDb,
|
|
338
|
+
type: "cloud",
|
|
339
|
+
trigger: opts.scheduled ? "scheduled" : "manual"
|
|
261
340
|
});
|
|
262
341
|
} catch (e) {
|
|
263
342
|
const msg = e.message;
|
|
343
|
+
if (opts.scheduled) {
|
|
344
|
+
trackCliEvent(cfg.profileId, "scheduled_backup_failed", { type: "cloud", error: msg });
|
|
345
|
+
}
|
|
264
346
|
if (msg.includes("Snapshot limit")) {
|
|
265
347
|
console.error("\n\u2717 Snapshot limit reached (2).");
|
|
266
348
|
console.error(" Delete one first: clawon delete <id>");
|
|
@@ -496,6 +578,69 @@ Total: ${files.length} files (${(totalSize / 1024).toFixed(1)} KB)`);
|
|
|
496
578
|
const cfg = readConfig();
|
|
497
579
|
trackCliEvent(cfg?.profileId || "anonymous", "cli_discover", { file_count: files.length, include_memory_db: !!opts.includeMemoryDb });
|
|
498
580
|
});
|
|
581
|
+
var schedule = program.command("schedule").description("Manage scheduled cloud backups");
|
|
582
|
+
schedule.command("on").description("Enable scheduled cloud backups via cron").option("--every <interval>", "Backup interval: 1h, 6h, 12h, 24h", "12h").action(async (opts) => {
|
|
583
|
+
assertNotWindows();
|
|
584
|
+
const cfg = readConfig();
|
|
585
|
+
trackCliEvent(cfg?.profileId || "anonymous", "schedule_enabled_attempted", {
|
|
586
|
+
type: "cloud",
|
|
587
|
+
interval_hours: parseInt(opts.every),
|
|
588
|
+
gated: true
|
|
589
|
+
});
|
|
590
|
+
console.error("\u2717 Scheduled cloud backups require a Hobby or Pro account. Use `clawon local schedule on` for local scheduled backups.");
|
|
591
|
+
process.exit(1);
|
|
592
|
+
});
|
|
593
|
+
schedule.command("off").description("Disable scheduled cloud backups").action(async () => {
|
|
594
|
+
assertNotWindows();
|
|
595
|
+
const removed = removeCronEntry(CRON_MARKER_CLOUD);
|
|
596
|
+
if (!removed) {
|
|
597
|
+
console.log("No cloud schedule was active.");
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
updateConfig({
|
|
601
|
+
schedule: {
|
|
602
|
+
cloud: { enabled: false, intervalHours: 0 }
|
|
603
|
+
}
|
|
604
|
+
});
|
|
605
|
+
console.log("\u2713 Scheduled cloud backup disabled");
|
|
606
|
+
const cfg = readConfig();
|
|
607
|
+
trackCliEvent(cfg?.profileId || "anonymous", "schedule_disabled", { type: "cloud" });
|
|
608
|
+
});
|
|
609
|
+
schedule.command("status").description("Show schedule status").action(async () => {
|
|
610
|
+
const cfg = readConfig();
|
|
611
|
+
const localEntry = getCronEntry(CRON_MARKER_LOCAL);
|
|
612
|
+
const cloudEntry = getCronEntry(CRON_MARKER_CLOUD);
|
|
613
|
+
console.log("Schedule Status\n");
|
|
614
|
+
if (localEntry) {
|
|
615
|
+
const localCfg = cfg?.schedule?.local;
|
|
616
|
+
console.log("\u2713 Local schedule: active");
|
|
617
|
+
if (localCfg?.intervalHours) console.log(` Interval: every ${localCfg.intervalHours}h`);
|
|
618
|
+
if (localCfg?.maxSnapshots) console.log(` Max snapshots: ${localCfg.maxSnapshots}`);
|
|
619
|
+
if (localCfg?.includeMemoryDb) console.log(` Memory DB: included`);
|
|
620
|
+
console.log(` Cron: ${localEntry.trim()}`);
|
|
621
|
+
} else {
|
|
622
|
+
console.log("\u2717 Local schedule: inactive");
|
|
623
|
+
console.log(" Enable: clawon local schedule on");
|
|
624
|
+
}
|
|
625
|
+
console.log("");
|
|
626
|
+
if (cloudEntry) {
|
|
627
|
+
const cloudCfg = cfg?.schedule?.cloud;
|
|
628
|
+
console.log("\u2713 Cloud schedule: active");
|
|
629
|
+
if (cloudCfg?.intervalHours) console.log(` Interval: every ${cloudCfg.intervalHours}h`);
|
|
630
|
+
console.log(` Cron: ${cloudEntry.trim()}`);
|
|
631
|
+
} else {
|
|
632
|
+
console.log("\u2717 Cloud schedule: inactive");
|
|
633
|
+
console.log(" Enable: clawon schedule on (requires Hobby or Pro)");
|
|
634
|
+
}
|
|
635
|
+
console.log(`
|
|
636
|
+
Log: ${SCHEDULE_LOG}`);
|
|
637
|
+
trackCliEvent(cfg?.profileId || "anonymous", "schedule_status_viewed", {
|
|
638
|
+
local_enabled: !!localEntry,
|
|
639
|
+
cloud_enabled: !!cloudEntry,
|
|
640
|
+
local_interval_hours: cfg?.schedule?.local?.intervalHours || null,
|
|
641
|
+
cloud_interval_hours: cfg?.schedule?.cloud?.intervalHours || null
|
|
642
|
+
});
|
|
643
|
+
});
|
|
499
644
|
program.command("files").description("List files in a backup").option("--snapshot <id>", "Snapshot ID (default: latest)").action(async (opts) => {
|
|
500
645
|
const cfg = readConfig();
|
|
501
646
|
if (!cfg) {
|
|
@@ -538,38 +683,129 @@ Total: ${files.length} files`);
|
|
|
538
683
|
}
|
|
539
684
|
});
|
|
540
685
|
var local = program.command("local").description("Local backup and restore (no cloud required)");
|
|
541
|
-
local.command("
|
|
686
|
+
var localSchedule = local.command("schedule").description("Manage scheduled local backups");
|
|
687
|
+
localSchedule.command("on").description("Enable scheduled local backups via cron").option("--every <interval>", "Backup interval: 1h, 6h, 12h, 24h", "12h").option("--max-snapshots <n>", "Keep only the N most recent local backups").option("--include-memory-db", "Include SQLite memory index").action(async (opts) => {
|
|
688
|
+
assertNotWindows();
|
|
689
|
+
const interval = opts.every;
|
|
690
|
+
if (!VALID_INTERVALS.includes(interval)) {
|
|
691
|
+
console.error(`\u2717 Invalid interval: ${interval}. Valid options: ${VALID_INTERVALS.join(", ")}`);
|
|
692
|
+
process.exit(1);
|
|
693
|
+
}
|
|
694
|
+
const cfg = readConfig();
|
|
695
|
+
const wasEnabled = cfg?.schedule?.local?.enabled;
|
|
696
|
+
const cronExpr = INTERVAL_CRON[interval];
|
|
697
|
+
const args = "local backup --scheduled" + (opts.includeMemoryDb ? " --include-memory-db" : "") + (opts.maxSnapshots ? ` --max-snapshots ${opts.maxSnapshots}` : "");
|
|
698
|
+
const command = resolveCliCommand(args);
|
|
699
|
+
addCronEntry(CRON_MARKER_LOCAL, cronExpr, command);
|
|
700
|
+
const maxSnapshots = opts.maxSnapshots ? parseInt(opts.maxSnapshots, 10) : null;
|
|
701
|
+
updateConfig({
|
|
702
|
+
schedule: {
|
|
703
|
+
local: {
|
|
704
|
+
enabled: true,
|
|
705
|
+
intervalHours: parseInt(interval),
|
|
706
|
+
...maxSnapshots ? { maxSnapshots } : {},
|
|
707
|
+
...opts.includeMemoryDb ? { includeMemoryDb: true } : {}
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
});
|
|
711
|
+
console.log(`\u2713 Scheduled local backup enabled`);
|
|
712
|
+
console.log(` Interval: every ${interval}`);
|
|
713
|
+
if (maxSnapshots) console.log(` Max snapshots: ${maxSnapshots}`);
|
|
714
|
+
if (opts.includeMemoryDb) console.log(` Memory DB: included`);
|
|
715
|
+
console.log(` Log: ${SCHEDULE_LOG}`);
|
|
716
|
+
const firstRunArgs = "local backup" + (opts.includeMemoryDb ? " --include-memory-db" : "") + (opts.maxSnapshots ? ` --max-snapshots ${opts.maxSnapshots}` : "");
|
|
717
|
+
console.log("\nRunning first backup now...\n");
|
|
718
|
+
try {
|
|
719
|
+
execSync(resolveCliCommand(firstRunArgs), { stdio: "inherit" });
|
|
720
|
+
} catch {
|
|
721
|
+
console.error("\u26A0 First backup failed \u2014 schedule is still active and will retry at next interval.");
|
|
722
|
+
}
|
|
723
|
+
trackCliEvent(cfg?.profileId || "anonymous", wasEnabled ? "schedule_updated" : "schedule_enabled", {
|
|
724
|
+
type: "local",
|
|
725
|
+
interval_hours: parseInt(interval),
|
|
726
|
+
max_snapshots: maxSnapshots,
|
|
727
|
+
include_memory_db: !!opts.includeMemoryDb
|
|
728
|
+
});
|
|
729
|
+
});
|
|
730
|
+
localSchedule.command("off").description("Disable scheduled local backups").action(async () => {
|
|
731
|
+
assertNotWindows();
|
|
732
|
+
const removed = removeCronEntry(CRON_MARKER_LOCAL);
|
|
733
|
+
if (!removed) {
|
|
734
|
+
console.log("No local schedule was active.");
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
737
|
+
updateConfig({
|
|
738
|
+
schedule: {
|
|
739
|
+
local: { enabled: false, intervalHours: 0 }
|
|
740
|
+
}
|
|
741
|
+
});
|
|
742
|
+
console.log("\u2713 Scheduled local backup disabled");
|
|
743
|
+
const cfg = readConfig();
|
|
744
|
+
trackCliEvent(cfg?.profileId || "anonymous", "schedule_disabled", { type: "local" });
|
|
745
|
+
});
|
|
746
|
+
local.command("backup").description("Save a local backup of your OpenClaw workspace").option("--tag <label>", "Add a label to this backup").option("--include-memory-db", "Include SQLite memory index").option("--scheduled", "Internal: triggered by cron (suppresses interactive output)").option("--max-snapshots <n>", "Keep only the N most recent local backups").action(async (opts) => {
|
|
542
747
|
if (!fs.existsSync(OPENCLAW_DIR)) {
|
|
543
748
|
console.error(`\u2717 OpenClaw directory not found: ${OPENCLAW_DIR}`);
|
|
544
749
|
process.exit(1);
|
|
545
750
|
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
751
|
+
try {
|
|
752
|
+
if (!opts.scheduled) console.log("Discovering files...");
|
|
753
|
+
const files = discoverFiles(OPENCLAW_DIR, !!opts.includeMemoryDb);
|
|
754
|
+
if (files.length === 0) {
|
|
755
|
+
console.error("\u2717 No files found to backup");
|
|
756
|
+
process.exit(1);
|
|
757
|
+
}
|
|
758
|
+
const totalSize = files.reduce((sum, f) => sum + f.size, 0);
|
|
759
|
+
if (!opts.scheduled) console.log(`Found ${files.length} files (${(totalSize / 1024).toFixed(1)} KB)`);
|
|
760
|
+
ensureDir(BACKUPS_DIR);
|
|
761
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "").replace("T", "T").slice(0, 15);
|
|
762
|
+
const filename = `backup-${timestamp}.tar.gz`;
|
|
763
|
+
const filePath = path.join(BACKUPS_DIR, filename);
|
|
764
|
+
if (!opts.scheduled) console.log("Creating archive...");
|
|
765
|
+
await createLocalArchive(files, OPENCLAW_DIR, filePath, opts.tag, opts.includeMemoryDb, opts.scheduled ? "scheduled" : "manual");
|
|
766
|
+
const archiveSize = fs.statSync(filePath).size;
|
|
767
|
+
if (!opts.scheduled) {
|
|
768
|
+
console.log(`
|
|
769
|
+
\u2713 Local backup saved!`);
|
|
770
|
+
console.log(` File: ${filePath}`);
|
|
771
|
+
console.log(` Files: ${files.length}`);
|
|
772
|
+
console.log(` Size: ${(archiveSize / 1024).toFixed(1)} KB (compressed)`);
|
|
773
|
+
if (opts.tag) console.log(` Tag: ${opts.tag}`);
|
|
774
|
+
}
|
|
775
|
+
const maxSnapshots = opts.maxSnapshots ? parseInt(opts.maxSnapshots, 10) : null;
|
|
776
|
+
let rotatedCount = 0;
|
|
777
|
+
if (maxSnapshots && maxSnapshots > 0) {
|
|
778
|
+
const allBackups = fs.readdirSync(BACKUPS_DIR).filter((f) => f.endsWith(".tar.gz")).sort().reverse();
|
|
779
|
+
if (allBackups.length > maxSnapshots) {
|
|
780
|
+
const toDelete = allBackups.slice(maxSnapshots);
|
|
781
|
+
for (const old of toDelete) {
|
|
782
|
+
fs.unlinkSync(path.join(BACKUPS_DIR, old));
|
|
783
|
+
rotatedCount++;
|
|
784
|
+
}
|
|
785
|
+
if (!opts.scheduled) {
|
|
786
|
+
console.log(` Rotated: deleted ${rotatedCount} old backup(s)`);
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
const cfg = readConfig();
|
|
791
|
+
trackCliEvent(cfg?.profileId || "anonymous", opts.scheduled ? "scheduled_backup_created" : "local_backup_created", {
|
|
792
|
+
file_count: files.length,
|
|
793
|
+
total_bytes: totalSize,
|
|
794
|
+
include_memory_db: !!opts.includeMemoryDb,
|
|
795
|
+
type: "local",
|
|
796
|
+
trigger: opts.scheduled ? "scheduled" : "manual",
|
|
797
|
+
rotated_count: rotatedCount
|
|
798
|
+
});
|
|
799
|
+
} catch (e) {
|
|
800
|
+
const msg = e.message;
|
|
801
|
+
if (opts.scheduled) {
|
|
802
|
+
const cfg = readConfig();
|
|
803
|
+
trackCliEvent(cfg?.profileId || "anonymous", "scheduled_backup_failed", { type: "local", error: msg });
|
|
804
|
+
}
|
|
805
|
+
console.error(`
|
|
806
|
+
\u2717 Local backup failed: ${msg}`);
|
|
550
807
|
process.exit(1);
|
|
551
808
|
}
|
|
552
|
-
const totalSize = files.reduce((sum, f) => sum + f.size, 0);
|
|
553
|
-
console.log(`Found ${files.length} files (${(totalSize / 1024).toFixed(1)} KB)`);
|
|
554
|
-
ensureDir(BACKUPS_DIR);
|
|
555
|
-
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "").replace("T", "T").slice(0, 15);
|
|
556
|
-
const filename = `backup-${timestamp}.tar.gz`;
|
|
557
|
-
const filePath = path.join(BACKUPS_DIR, filename);
|
|
558
|
-
console.log("Creating archive...");
|
|
559
|
-
await createLocalArchive(files, OPENCLAW_DIR, filePath, opts.tag, opts.includeMemoryDb);
|
|
560
|
-
const archiveSize = fs.statSync(filePath).size;
|
|
561
|
-
console.log(`
|
|
562
|
-
\u2713 Local backup saved!`);
|
|
563
|
-
console.log(` File: ${filePath}`);
|
|
564
|
-
console.log(` Files: ${files.length}`);
|
|
565
|
-
console.log(` Size: ${(archiveSize / 1024).toFixed(1)} KB (compressed)`);
|
|
566
|
-
if (opts.tag) console.log(` Tag: ${opts.tag}`);
|
|
567
|
-
const cfg = readConfig();
|
|
568
|
-
trackCliEvent(cfg?.profileId || "anonymous", "local_backup_created", {
|
|
569
|
-
file_count: files.length,
|
|
570
|
-
total_bytes: totalSize,
|
|
571
|
-
include_memory_db: !!opts.includeMemoryDb
|
|
572
|
-
});
|
|
573
809
|
});
|
|
574
810
|
local.command("list").description("List local backups").action(async () => {
|
|
575
811
|
if (!fs.existsSync(BACKUPS_DIR)) {
|
|
@@ -681,6 +917,17 @@ program.command("status").description("Show current status").action(async () =>
|
|
|
681
917
|
} else {
|
|
682
918
|
console.log(`\u2717 OpenClaw not found: ${OPENCLAW_DIR}`);
|
|
683
919
|
}
|
|
920
|
+
console.log("");
|
|
921
|
+
const localEntry = getCronEntry(CRON_MARKER_LOCAL);
|
|
922
|
+
const cloudEntry = getCronEntry(CRON_MARKER_CLOUD);
|
|
923
|
+
if (localEntry || cloudEntry) {
|
|
924
|
+
console.log("\u2713 Schedule active");
|
|
925
|
+
if (localEntry) console.log(" Local: " + (cfg?.schedule?.local?.intervalHours || "?") + "h interval");
|
|
926
|
+
if (cloudEntry) console.log(" Cloud: " + (cfg?.schedule?.cloud?.intervalHours || "?") + "h interval");
|
|
927
|
+
} else {
|
|
928
|
+
console.log("\u2717 No schedule configured");
|
|
929
|
+
console.log(" Run: clawon local schedule on");
|
|
930
|
+
}
|
|
684
931
|
trackCliEvent(cfg?.profileId || "anonymous", "cli_status_viewed");
|
|
685
932
|
});
|
|
686
933
|
program.command("logout").description("Remove local credentials").action(() => {
|