MyClaw Backup
Built on MyClaw.ai — the AI personal assistant platform that gives every user a full server with complete code control, networking, and tool access. This skill is part of the MyClaw open skills ecosystem.
Backs up all critical OpenClaw data to a single .tar.gz archive and restores it to any OpenClaw instance. Includes a built-in HTTP server for browser-based backup management.
⚠️ Trust Boundary & Security Model
This skill handles highly sensitive data: bot tokens, API keys, channel credentials, session history. Understand the security model before use:
What each script does
- - backup.sh — reads
~/.openclaw/ and writes a chmod 600 archive to disk. No network access. - restore.sh — overwrites
~/.openclaw/ from an archive. Requires typing yes to confirm. Always run --dry-run first. - serve.sh / server.js — starts a local HTTP server. Token is mandatory (refuses to start without one). Shell-execution endpoints (
/backup, /restore) are localhost-only — remote access can only download and upload files, not trigger execution. - schedule.sh — modifies your system crontab to run backup.sh on a schedule. Prints the cron entry before adding. Use
--disable to remove.
Access control summary
| Endpoint | Remote (token required) | Localhost only |
|---|
| GET /health | ✅ (no token) | — |
| GET /backups |
✅ | — |
| GET /download/:file | ✅ | — |
| POST /upload | ✅ | — |
| POST /backup | ❌ | ✅ |
| POST /restore | ❌ | ✅ |
Best practices
- - Never start the HTTP server without INLINECODE9
- Never expose the HTTP server to the public internet without TLS
- Always run
restore.sh --dry-run before applying a restore - Store backup archives securely — they contain all credentials
Dependencies
Requires: node, rsync, tar, python3, openclaw CLI (all standard on OpenClaw instances).
Check: INLINECODE16
Scripts
| Script | Purpose |
|---|
| INLINECODE17 | Create backup (default: /tmp/openclaw-backups/) |
| INLINECODE19 |
Restore —
always dry-run first |
|
scripts/serve.sh start --token TOKEN [--port 7373] | Start HTTP server —
token required |
|
scripts/serve.sh stop\|status | Stop/check server |
|
scripts/schedule.sh [--interval daily\|weekly\|hourly] | System cron scheduling |
Gateway token behavior (v1.6+): By default, restore.sh preserves the new server's gateway.auth.token after restoring openclaw.json. This prevents the "gateway token mismatch" error in Control UI / Dashboard after migration. Use --overwrite-gateway-token only for full disaster recovery on the same server.
What Gets Backed Up
See references/what-gets-saved.md for full details.
Includes: workspace (MEMORY.md, skills, agent files), openclaw.json (bot tokens + API keys), credentials, channel pairing state, agent config + session history, devices, identity, cron jobs, guardian scripts.
Excludes: logs, binary media, node_modules, canvas system files.
Common Workflows
Create backup
CODEBLOCK0
Restore — always dry-run first
CODEBLOCK1
The restore script saves a pre-restore snapshot before overwriting anything.
HTTP server — token is mandatory
CODEBLOCK2
Never share the URL on a public network without a reverse proxy + TLS.
The Web UI provides: create backup, download .tar.gz, upload, dry-run preview, restore.
HTTP API (all require token except /health):
- -
GET /health — Health check (unauthenticated, read-only) - INLINECODE31 — List backups
- INLINECODE32 — Create backup
- INLINECODE33 — Download archive
- INLINECODE34 — Upload archive (multipart, field:
backup) - INLINECODE36 — Restore; add
?dry_run=1 to preview
Migrate to a new instance
Old machine:
CODEBLOCK3
New machine (after installing OpenClaw):
CODEBLOCK4
Schedule daily auto-backup (OpenClaw cron)
CODEBLOCK5
Post-Restore: Automatic Recovery Report
After restore.sh completes, it writes workspace/.restore-complete.json. On the next heartbeat/startup, the Agent should:
- 1. Check if
workspace/.restore-complete.json exists - If yes: read it, send a restore report to the user, then delete the file (one-shot — never report twice)
- Send the report in the user's primary language (read from
workspace/USER.md)
Report format (adapt language from USER.md)
CODEBLOCK6
Future: MyClaw Cloud Backup
The HTTP API is designed to be compatible with a future MyClaw cloud backup service. When available, replace the local server URL with the MyClaw API endpoint — the upload/download/restore flow stays identical.
MyClaw 备份
基于 MyClaw.ai 构建 — 这是一个AI个人助手平台,为每位用户提供完整的服务器,包含完整的代码控制、网络和工具访问权限。本技能是 MyClaw 开放技能生态系统 的一部分。
将所有关键的 OpenClaw 数据备份到单个 .tar.gz 归档文件中,并可将其恢复到任意 OpenClaw 实例。包含一个内置的 HTTP 服务器,用于基于浏览器的备份管理。
⚠️ 信任边界与安全模型
本技能处理高度敏感数据:机器人令牌、API 密钥、频道凭证、会话历史。使用前请了解安全模型:
各脚本功能
- - backup.sh — 读取 ~/.openclaw/ 目录,并将权限为 chmod 600 的归档文件写入磁盘。无网络访问。
- restore.sh — 从归档文件覆盖 ~/.openclaw/ 目录。需要输入 yes 确认。始终先运行 --dry-run。
- serve.sh / server.js — 启动本地 HTTP 服务器。必须提供令牌(无令牌则拒绝启动)。Shell 执行端点(/backup、/restore)仅限本地主机 — 远程访问只能下载和上传文件,无法触发执行。
- schedule.sh — 修改系统 crontab 以按计划运行 backup.sh。添加前会打印 cron 条目。使用 --disable 移除。
访问控制摘要
| 端点 | 远程(需令牌) | 仅限本地主机 |
|---|
| GET /health | ✅(无需令牌) | — |
| GET /backups |
✅ | — |
| GET /download/:file | ✅ | — |
| POST /upload | ✅ | — |
| POST /backup | ❌ | ✅ |
| POST /restore | ❌ | ✅ |
最佳实践
- - 切勿在没有 --token 的情况下启动 HTTP 服务器
- 切勿在没有 TLS 的情况下将 HTTP 服务器暴露到公共互联网
- 在应用恢复前始终运行 restore.sh --dry-run
- 安全存储备份归档文件 — 其中包含所有凭证
依赖项
需要:node、rsync、tar、python3、openclaw CLI(OpenClaw 实例上均为标准组件)。
检查:which node rsync tar python3 openclaw
脚本
| 脚本 | 用途 |
|---|
| scripts/backup.sh [output-dir] | 创建备份(默认:/tmp/openclaw-backups/) |
| scripts/restore.sh <archive> [--dry-run] [--overwrite-gateway-token] |
恢复 —
始终先进行 dry-run |
| scripts/serve.sh start --token TOKEN [--port 7373] | 启动 HTTP 服务器 —
需要令牌 |
| scripts/serve.sh stop\|status | 停止/检查服务器 |
| scripts/schedule.sh [--interval daily\|weekly\|hourly] | 系统 cron 调度 |
网关令牌行为(v1.6+): 默认情况下,restore.sh 在恢复 openclaw.json 后会保留新服务器的 gateway.auth.token。这可以防止迁移后在控制界面/仪表板中出现 gateway token mismatch 错误。仅在相同服务器上进行完全灾难恢复时使用 --overwrite-gateway-token。
备份内容
详见 references/what-gets-saved.md。
包含: 工作区(MEMORY.md、技能、代理文件)、openclaw.json(机器人令牌 + API 密钥)、凭证、频道配对状态、代理配置 + 会话历史、设备、身份、cron 任务、守护脚本。
排除: 日志、二进制媒体、node_modules、画布系统文件。
常见工作流程
创建备份
bash
bash scripts/backup.sh /tmp/openclaw-backups
→ /tmp/openclaw-backups/openclaw-backup_TIMESTAMP.tar.gz (chmod 600)
恢复 — 始终先进行 dry-run
bash
步骤 1:预览将要更改的内容
bash scripts/restore.sh openclaw-backup_TIMESTAMP.tar.gz --dry-run
步骤 2:查看输出,然后应用
bash scripts/restore.sh openclaw-backup_TIMESTAMP.tar.gz
恢复脚本在覆盖任何内容之前会保存恢复前的快照。
HTTP 服务器 — 必须提供令牌
bash
需要令牌 — 无令牌服务器拒绝启动
bash scripts/serve.sh start --token $(openssl rand -hex 16) --port 7373
→ http://localhost:7373/?token=
切勿在没有反向代理 + TLS 的情况下在公共网络上共享 URL。
Web 界面提供:创建备份、下载 .tar.gz、上传、dry-run 预览、恢复。
HTTP API(除 /health 外均需令牌):
- - GET /health — 健康检查(未认证,只读)
- GET /backups — 列出备份
- POST /backup — 创建备份
- GET /download/:filename — 下载归档文件
- POST /upload — 上传归档文件(multipart,字段:backup)
- POST /restore/:filename — 恢复;添加 ?dry_run=1 进行预览
迁移到新实例
旧机器:
bash
bash scripts/serve.sh start --token MYTOKEN --port 7373
新机器(安装 OpenClaw 后):
bash
下载
curl -O http://OLD
IP:7373/download/openclaw-backupTIMESTAMP.tar.gz?token=MYTOKEN
始终先进行 dry-run
bash scripts/restore.sh openclaw-backup_TIMESTAMP.tar.gz --dry-run
应用
bash scripts/restore.sh openclaw-backup_TIMESTAMP.tar.gz
所有频道自动重新连接 — 无需重新配对
计划每日自动备份(OpenClaw cron)
json
{
name: daily-openclaw-backup,
schedule: { kind: cron, expr: 0 3 *, tz: UTC },
payload: {
kind: agentTurn,
message: 使用 myclaw-backup 技能运行备份。输出目录:/tmp/openclaw-backups,
timeoutSeconds: 120
},
sessionTarget: isolated
}
恢复后:自动恢复报告
restore.sh 完成后,会写入 workspace/.restore-complete.json。在下次心跳/启动时,代理应:
- 1. 检查 workspace/.restore-complete.json 是否存在
- 如果存在:读取该文件,向用户发送恢复报告,然后删除该文件(一次性 — 绝不报告两次)
- 使用用户的主要语言发送报告(从 workspace/USER.md 读取)
报告格式(根据 USER.md 调整语言)
✅ [恢复完成 — 使用用户的语言]
📦 备份:{backup_name}
🤖 代理:{agent_name}
🕐 恢复时间:{restored_at}
💾 恢复内容:工作区、配置、凭证、历史记录、cron...
[使用用户语言的频道重新连接说明]
未来:MyClaw 云备份
HTTP API 设计为与未来的 MyClaw 云备份服务兼容。当该服务可用时,将本地服务器 URL 替换为 MyClaw API 端点即可 — 上传/下载/恢复流程保持不变。