OpenClaw Daily Backup
Backup and restore OpenClaw workspace SOUL files (SOUL.md, USER.md, AGENTS.md, IDENTITY.md, TOOLS.md, HEARTBEAT.md, BOOTSTRAP.md) with versioning, validation, and rollback capabilities.
Purpose
Protect critical workspace configuration files from accidental deletion, corruption, or misconfiguration. Enable quick recovery and version history tracking.
What Gets Backed Up
Core SOUL files from workspace root:
- -
SOUL.md — agent personality and mission - INLINECODE1 — user profile and preferences
- INLINECODE2 — agent instructions and workflows
- INLINECODE3 — agent identity configuration
- INLINECODE4 — local tool configuration
- INLINECODE5 — periodic task configuration
- INLINECODE6 — initialization instructions
Usage
Backup Current SOUL Files
CODEBLOCK0
List Backups
CODEBLOCK1
Restore from Backup
CODEBLOCK2
Validate Backup Integrity
CODEBLOCK3
Backup Structure
CODEBLOCK4
Manifest Format
Each backup includes a manifest.json:
CODEBLOCK5
Recovery Workflow
Standard Recovery
- 1. List available backups: INLINECODE8
- Preview restore: INLINECODE9
- Apply restore: INLINECODE10
- Verify: Check workspace files manually
Emergency Recovery
If workspace is corrupted and scripts won't run:
CODEBLOCK6
Rollback After Bad Restore
Every restore creates an automatic pre-restore backup:
CODEBLOCK7
Automation
Cron Schedule (Recommended)
Add to OpenClaw heartbeat or system cron:
CODEBLOCK8
Pre-Deployment Hook
CODEBLOCK9
Validation Checks
The validate script checks:
- - Manifest integrity (valid JSON, required fields)
- File existence (all files listed in manifest exist)
- Hash verification (SHA-256 checksums match)
- Workspace path consistency
- Timestamp format validity
Failure Scenarios & Recovery
Scenario 1: Accidental SOUL.md Deletion
CODEBLOCK10
Scenario 2: Bad Configuration Change
CODEBLOCK11
Scenario 3: Corrupted Backup
CODEBLOCK12
Scenario 4: Complete Workspace Loss
CODEBLOCK13
Best Practices
- 1. Backup before major changes: Always create a named backup before refactoring SOUL files
- Validate regularly: Run
validate.mjs weekly to catch corruption early - Keep 30 days of backups: Prune old backups monthly
- Test restore process: Practice recovery quarterly
- Document custom changes: Use
--desc flag to explain why backup was created - Version control: Consider committing backup directory to git for off-machine redundancy
Security Notes
- - Backups contain sensitive configuration (API keys in TOOLS.md, user info in USER.md)
- Store backup directory with same permissions as workspace
- Do not commit backups to public repositories
- Consider encrypting backup directory if workspace contains secrets
Dependencies
- - Node.js 18+
- No external npm packages (uses built-in crypto, fs, path)
Troubleshooting
"Backup directory not found"
- - Run
mkdir -p backups in skill directory
"Permission denied"
- - Check workspace directory permissions: INLINECODE14
- Ensure backup script has execute permissions: INLINECODE15
"Hash mismatch during validation"
- - File was modified after backup creation
- Backup may be corrupted — use previous backup
"Restore failed: file conflicts"
- - Use
--force flag to overwrite existing files - Or manually move conflicting files before restore
Future Enhancements
- - [ ] Compression (gzip backups to save space)
- [ ] Remote backup sync (S3, Dropbox, rsync)
- [ ] Differential backups (only changed files)
- [ ] Backup retention policy (auto-prune old backups)
- [ ] Encrypted backups (GPG encryption)
- [ ] Web UI for backup management
- [ ] Slack/Telegram notifications on backup/restore
OpenClaw 每日备份
对 OpenClaw 工作区 SOUL 文件(SOUL.md、USER.md、AGENTS.md、IDENTITY.md、TOOLS.md、HEARTBEAT.md、BOOTSTRAP.md)进行备份和恢复,支持版本控制、验证和回滚功能。
目的
保护关键工作区配置文件免遭意外删除、损坏或错误配置。实现快速恢复和版本历史追踪。
备份内容
来自工作区根目录的核心 SOUL 文件:
- - SOUL.md — 智能体人格与使命
- USER.md — 用户档案与偏好
- AGENTS.md — 智能体指令与工作流
- IDENTITY.md — 智能体身份配置
- TOOLS.md — 本地工具配置
- HEARTBEAT.md — 周期性任务配置
- BOOTSTRAP.md — 初始化指令
使用方法
备份当前 SOUL 文件
bash
创建带时间戳的备份
node scripts/backup.mjs
创建命名备份
node scripts/backup.mjs --name pre-migration
创建带描述的备份
node scripts/backup.mjs --desc Before major refactor
列出备份
bash
列出所有备份
node scripts/list.mjs
显示详细信息
node scripts/list.mjs --verbose
从备份恢复
bash
恢复最新备份
node scripts/restore.mjs
按时间戳恢复特定备份
node scripts/restore.mjs --timestamp 2026-03-05T00-51-30
按名称恢复特定备份
node scripts/restore.mjs --name pre-migration
试运行(预览但不执行)
node scripts/restore.mjs --dry-run
验证备份完整性
bash
验证所有备份
node scripts/validate.mjs
验证特定备份
node scripts/validate.mjs --timestamp 2026-03-05T00-51-30
备份结构
backups/
├── 2026-03-05T00-51-30/
│ ├── manifest.json # 备份元数据
│ ├── SOUL.md
│ ├── USER.md
│ ├── AGENTS.md
│ ├── IDENTITY.md
│ ├── TOOLS.md
│ ├── HEARTBEAT.md
│ └── BOOTSTRAP.md
├── 2026-03-05T01-15-42/
│ └── ...
└── named/
├── pre-migration/
│ └── ...
└── stable-v1/
└── ...
清单格式
每个备份包含一个 manifest.json:
json
{
timestamp: 2026-03-05T00:51:30.123Z,
name: pre-migration,
description: Before major refactor,
workspace: /Users/m1/.openclaw/workspace-hunter,
files: {
SOUL.md: {
size: 1234,
hash: sha256:abc123...,
exists: true
},
USER.md: {
size: 567,
hash: sha256:def456...,
exists: true
}
},
created_by: hunter,
openclaw_version: 1.0.0
}
恢复工作流
标准恢复
- 1. 列出可用备份:node scripts/list.mjs
- 预览恢复:node scripts/restore.mjs --timestamp --dry-run
- 执行恢复:node scripts/restore.mjs --timestamp
- 验证:手动检查工作区文件
紧急恢复
如果工作区损坏且脚本无法运行:
bash
从备份目录手动恢复
cd /Users/m1/.openclaw/workspace-hunter
cp -r soul-backup-skill/backups/LATEST_TIMESTAMP/* .
恢复后回滚
每次恢复都会自动创建一个恢复前备份:
bash
恢复创建:backups/pre-restore-2026-03-05T01-20-00/
回滚操作:
node scripts/restore.mjs --timestamp pre-restore-2026-03-05T01-20-00
自动化
Cron 计划(推荐)
添加到 OpenClaw 心跳或系统 cron:
bash
每天凌晨 2 点备份
0 2
* cd /Users/m1/.openclaw/workspace-hunter/soul-backup-skill && node scripts/backup.mjs --name daily-$(date +\%Y-\%m-\%d)
每周日凌晨 3 点备份
0 3
0 cd /Users/m1/.openclaw/workspace-hunter/soul-backup-skill && node scripts/backup.mjs --name weekly-$(date +\%Y-W\%V)
部署前钩子
bash
部署更改前
cd /Users/m1/.openclaw/workspace-hunter/soul-backup-skill
node scripts/backup.mjs --name pre-deploy-$(git rev-parse --short HEAD)
验证检查
验证脚本检查:
- - 清单完整性(有效 JSON、必填字段)
- 文件存在性(清单中列出的所有文件都存在)
- 哈希验证(SHA-256 校验和匹配)
- 工作区路径一致性
- 时间戳格式有效性
故障场景与恢复
场景 1:意外删除 SOUL.md
bash
立即恢复
node scripts/restore.mjs --file SOUL.md
或完全恢复
node scripts/restore.mjs
场景 2:错误配置更改
bash
预览将要恢复的内容
node scripts/restore.mjs --dry-run
恢复先前版本
node scripts/restore.mjs --timestamp
场景 3:备份损坏
bash
验证所有备份
node scripts/validate.mjs
查找最后一个完好备份
node scripts/list.mjs --verbose
从最后一个完好备份恢复
node scripts/restore.mjs --timestamp
场景 4:工作区完全丢失
bash
重新创建工作区目录
mkdir -p /Users/m1/.openclaw/workspace-hunter
克隆备份技能
cd /Users/m1/.openclaw/workspace-hunter
git clone soul-backup-skill
恢复最新备份
cd soul-backup-skill
node scripts/restore.mjs
最佳实践
- 1. 重大更改前备份:重构 SOUL 文件前始终创建命名备份
- 定期验证:每周运行 validate.mjs 及早发现损坏
- 保留 30 天备份:每月清理旧备份
- 测试恢复流程:每季度练习恢复操作
- 记录自定义更改:使用 --desc 标志说明创建备份的原因
- 版本控制:考虑将备份目录提交到 git 以实现异地冗余
安全说明
- - 备份包含敏感配置(TOOLS.md 中的 API 密钥、USER.md 中的用户信息)
- 备份目录的权限设置应与工作区相同
- 不要将备份提交到公共仓库
- 如果工作区包含机密信息,考虑加密备份目录
依赖项
- - Node.js 18+
- 无外部 npm 包(使用内置的 crypto、fs、path)
故障排除
备份目录未找到
- - 在技能目录中运行 mkdir -p backups
权限被拒绝
- - 检查工作区目录权限:ls -la ..
- 确保备份脚本具有执行权限:chmod +x scripts/*.mjs
验证时哈希不匹配
- - 文件在备份创建后被修改
- 备份可能已损坏 — 使用之前的备份
恢复失败:文件冲突
- - 使用 --force 标志覆盖现有文件
- 或在恢复前手动移动冲突文件
未来增强
- - [ ] 压缩(gzip 备份以节省空间)
- [ ] 远程备份同步(S3、Dropbox、rsync)
- [ ] 差异备份(仅更改的文件)
- [ ] 备份保留策略(自动清理旧备份)
- [ ] 加密备份(GPG 加密)
- [ ] 备份管理 Web 界面
- [ ] 备份/恢复的 Slack/Telegram 通知