OpenClaw State Backup
Create and restore versioned, restorable snapshots of mutable OpenClaw state.
What changes over time
Treat these as mutable state and include them in backups when they exist:
- -
~/.openclaw/openclaw.json — runtime config - INLINECODE1 — session metadata
- INLINECODE2 — recent restart delivery state
- INLINECODE3 — vector index / memory DBs
- INLINECODE4 — per-agent runtime/session state
- INLINECODE5
- INLINECODE6
- INLINECODE7
- INLINECODE8
- INLINECODE9
- INLINECODE10 — user-authored skills and local skill state
Treat these as mostly static/user-maintained bootstrap files and back them up when you want a full environment restore, but do not rely on them as fast-changing runtime state:
- - INLINECODE11
- INLINECODE12
- INLINECODE13
- INLINECODE14
- INLINECODE15 (if still present)
Backup strategy
Use the bundled scripts for deterministic behavior.
Create backup
Run scripts/backup_state.py with:
- - INLINECODE17
- INLINECODE18 (usually
~/.openclaw) - INLINECODE20 for generated snapshots
- optional INLINECODE21
- optional
--mode mutable|full (default: mutable) - optional repeated INLINECODE24
- optional repeated INLINECODE25
INLINECODE26 captures changing state only.
full adds mostly-static workspace identity/bootstrap files too.
The script writes:
- - a timestamped INLINECODE28
- a INLINECODE29
- checksums for every stored file
- compatibility metadata (
formatVersion, OpenClaw version, host/platform) - applied include/exclude filter metadata
Restore backup
Run scripts/restore_state.py with:
- - INLINECODE32
- INLINECODE33
- INLINECODE34
- optional INLINECODE35
- optional INLINECODE36
- optional INLINECODE37
- optional INLINECODE38
- optional repeated INLINECODE39
- optional repeated INLINECODE40
Restore behavior:
- 1. verify archive structure + checksums
- compare compatibility metadata
- optionally narrow restore scope with include/exclude prefixes
- build a restore plan (
create / update / unchanged / missingFromArchive) - always write a JSON restore/dry-run report to disk
- if
--dry-run, stop after writing the diff-style report - otherwise create a pre-restore rollback backup automatically
- restore files into place
- write a final restore report showing what changed and where rollback lives
Safety rules
- - Always prefer
--verify-only first when archive provenance is uncertain. - Never overwrite from an archive that fails checksum verification.
- Never delete unrelated files outside the managed backup manifest.
- If compatibility check fails, stop unless the user explicitly wants
--allow-version-mismatch. - Before reporting restore success, mention the generated rollback archive path.
File model
The scripts split backup contents into:
- -
mutable/ — runtime-changing state - INLINECODE49 — mostly-stable workspace identity/configuration files
- INLINECODE50 — archive manifest
Read the manifest if you need to inspect contents without restoring.
When to use which mode
- - Use mutable for routine safety snapshots and frequent backups.
- Use full before machine migration, risky reconfiguration, or major cleanup.
Recovery guidance
If a restore causes problems, immediately restore the auto-generated pre-restore rollback archive created by restore_state.py.
OpenClaw 状态备份
创建和恢复可变 OpenClaw 状态的带版本、可恢复的快照。
随时间变化的内容
将这些视为可变状态,并在存在时将其包含在备份中:
- - ~/.openclaw/openclaw.json — 运行时配置
- ~/.openclaw/sessions.json — 会话元数据
- ~/.openclaw/restart-sentinel.json — 最近的重启交付状态
- ~/.openclaw/memory/ — 向量索引/记忆数据库
- ~/.openclaw/agents/ — 每个代理的运行时/会话状态
- workspace/MEMORY.md
- workspace/memory/
- workspace/SESSION-STATE.md
- workspace/HEARTBEAT.md
- workspace/TOOLS.md
- workspace/skills/ — 用户编写的技能和本地技能状态
将这些视为基本静态/用户维护的引导文件,在需要完整环境恢复时进行备份,但不要依赖它们作为快速变化的运行时状态:
- - workspace/SOUL.md
- workspace/USER.md
- workspace/IDENTITY.md
- workspace/AGENTS.md
- workspace/BOOTSTRAP.md(如果仍然存在)
备份策略
使用捆绑脚本以获得确定性行为。
创建备份
运行 scripts/backup_state.py,参数如下:
- - --workspace <路径>
- --state-dir <路径>(通常为 ~/.openclaw)
- --output-dir <路径> 用于生成的快照
- 可选 --label <名称>
- 可选 --mode mutable|full(默认:mutable)
- 可选重复 --include-prefix <相对路径前缀>
- 可选重复 --exclude-prefix <相对路径前缀>
mutable 仅捕获变化的状态。
full 额外包含基本静态的工作区身份/引导文件。
脚本会写入:
- - 一个带时间戳的 .tar.gz
- 一个 manifest.json
- 每个存储文件的校验和
- 兼容性元数据(formatVersion、OpenClaw 版本、主机/平台)
- 应用的包含/排除过滤器元数据
恢复备份
运行 scripts/restore_state.py,参数如下:
- - --archive
- --workspace <路径>
- --state-dir <路径>
- 可选 --verify-only
- 可选 --dry-run
- 可选 --allow-version-mismatch
- 可选 --report-dir <路径>
- 可选重复 --include-prefix <相对路径前缀>
- 可选重复 --exclude-prefix <相对路径前缀>
恢复行为:
- 1. 验证归档结构 + 校验和
- 比较兼容性元数据
- 可选地使用包含/排除前缀缩小恢复范围
- 构建恢复计划(create / update / unchanged / missingFromArchive)
- 始终将 JSON 恢复/模拟运行报告写入磁盘
- 如果使用 --dry-run,则在写入差异风格报告后停止
- 否则自动创建恢复前回滚备份
- 将文件恢复到目标位置
- 写入最终恢复报告,显示更改内容及回滚位置
安全规则
- - 当归档来源不确定时,始终优先使用 --verify-only。
- 切勿从未通过校验和验证的归档中覆盖文件。
- 切勿删除受管理备份清单之外的不相关文件。
- 如果兼容性检查失败,除非用户明确要求 --allow-version-mismatch,否则停止。
- 在报告恢复成功之前,提及生成的回滚归档路径。
文件模型
脚本将备份内容分为:
- - mutable/ — 运行时变化的状态
- static/ — 基本稳定的工作区身份/配置文件
- meta/manifest.json — 归档清单
如需检查内容而不进行恢复,请阅读清单。
何时使用哪种模式
- - 使用 mutable 进行常规安全快照和频繁备份。
- 使用 full 进行机器迁移、风险重新配置或重大清理之前。
恢复指南
如果恢复导致问题,请立即恢复由 restore_state.py 自动生成的恢复前回滚归档。