OpenClaw 自动备份配置指南
配置时间 : 2026-03-14备份目标 : GitHub Private Repository备份频率 : 每日凌晨 3:00备份内容 : Workspace + 脱敏配置
📋 目录
备份架构
准备工作
配置步骤
备份脚本
定时任务
恢复指南
安全说明
一、备份架构 {#备份架构} 1.1 备份内容
内容
说明
脱敏处理
workspace/
工作目录(记忆、技能、项目)
❌ 无需脱敏
openclaw.json
配置文件
✅ 敏感信息替换为 [REDACTED]
README.md
备份说明文档
❌ 无需脱敏
1.2 不备份的内容
内容
原因
credentials/
包含敏感凭证,需单独安全存储
logs/
日志文件过大,无备份价值
extensions/
插件可通过配置重新安装
.git/
工作目录可能有独立 Git 历史
1.3 备份流程 1 2 3 4 5 6 7 8 9 10 ┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐ │ 源数据目录 │ │ 备份脚本 │ │ GitHub 仓库 │ │ ~/.openclaw/ │ -> │ auto-backup.sh │ -> │ quanoc/ │ │ │ │ │ │ clawbackup │ └─────────────────┘ └──────────────────┘ └─────────────────┘ ↓ ┌──────────────────┐ │ Cron 定时任务 │ │ 每天 03:00 │ └──────────────────┘
二、准备工作 {#准备工作} 2.1 创建 GitHub 仓库
2.2 生成 SSH Key 1 2 3 4 5 ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_backup -C "backup@openclaw" cat ~/.ssh/id_ed25519_backup.pub
2.3 配置 Deploy Key
打开仓库:https://github.com/quanoc/clawbackup/settings/keys
点击 Add deploy key
粘贴公钥
✅ 勾选 Allow write access
点击 Add key
三、配置步骤 {#配置步骤} 3.1 创建备份目录 1 2 3 4 5 6 mkdir -p /tmp/clawbackupcd /tmp/clawbackupgit init git config user.email "backup@openclaw.local" git config user.name "OpenClaw Backup" git remote add origin git@github.com:quanoc/clawbackup.git
3.2 首次备份 1 2 3 4 5 6 7 8 9 10 11 cp -r ~/.openclaw/workspace/* /tmp/clawbackup/workspace/rm -rf /tmp/clawbackup/workspace/.gitgit add -A git commit -m "Initial backup: $(date +%Y-%m-%d) " git push -u origin main
四、备份脚本 {#备份脚本} 4.1 完整脚本 位置:/home/admin/.openclaw/workspace/scripts/auto-backup.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 #!/bin/bash set -eBACKUP_DIR="/tmp/clawbackup" WORKSPACE_SRC="/home/admin/.openclaw/workspace" CONFIG_SRC="/home/admin/.openclaw/openclaw.json" log () { echo "[$(date '+%Y-%m-%d %H:%M:%S') ] $1 " } log "开始 OpenClaw 自动备份..." mkdir -p "$BACKUP_DIR " log "同步 workspace..." rm -rf "$BACKUP_DIR /workspace" mkdir -p "$BACKUP_DIR /workspace" cp -r "$WORKSPACE_SRC " /* "$BACKUP_DIR /workspace/" rm -rf "$BACKUP_DIR /workspace/.git" 2>/dev/null || true log "生成脱敏配置文件..." cat > "$BACKUP_DIR /openclaw.json.sanitized.json" << 'EOF' { "_meta_info" : "脱敏配置文件" , "_sensitive_fields_removed" : [ "API Keys" , "Gateway Token" , "Client Secrets" , "IP Addresses" ] } EOF cd "$BACKUP_DIR " if [ -z "$(git status --porcelain) " ]; then log "无变化,跳过提交" else log "提交变更..." git add -A git commit -m "Auto backup: $(date '+%Y-%m-%d %H:%M') " log "推送到 GitHub..." git push origin main fi log "备份完成!"
4.2 配置脱敏规则 敏感字段替换表:
原字段
替换为
apiKey: "sk-xxx"
apiKey: "[REDACTED]"
token: "abc123"
token: "[REDACTED]"
clientSecret: "xyz"
clientSecret: "[REDACTED]"
allowedOrigins: ["http://1.2.3.4:port"]
allowedOrigins: ["[REDACTED_IP]"]
sourcePath: "/home/admin/xxx"
sourcePath: "[REDACTED_PATH]"
五、定时任务 {#定时任务} 5.1 配置 Crontab
添加以下内容:
1 2 # OpenClaw Auto Backup - Daily at 3:00 AM 0 3 * * * /home/admin/.openclaw/workspace/scripts/auto-backup.sh >> /home/admin/.openclaw/workspace/data/backup-cron.log 2>&1
5.2 验证 Cron 1 2 3 4 5 crontab -l tail -f /var/log/cron 2>/dev/null || journalctl -u cron -f
5.3 手动测试 1 2 3 4 5 /home/admin/.openclaw/workspace/scripts/auto-backup.sh tail /home/admin/.openclaw/workspace/data/backup-cron.log
六、恢复指南 {#恢复指南} 6.1 从备份恢复 1 2 3 4 5 6 7 8 9 10 11 12 git clone git@github.com:quanoc/clawbackup.git ~/clawbackup-restore cp -r ~/clawbackup-restore/workspace/* ~/.openclaw/workspace/cp ~/clawbackup-restore/openclaw.json.sanitized.json ~/.openclaw/openclaw.jsonopenclaw doctor
6.2 恢复敏感信息 从安全存储中恢复以下信息:
API Keys (DashScope 等)
Gateway Token
Channel Credentials (DingTalk, QQ, WeCom)
其他敏感配置
1 2 3 4 vim ~/.openclaw/openclaw.json
6.3 恢复插件 1 2 3 4 openclaw plugins install qqbot openclaw plugins install dingtalk openclaw plugins install wecom
七、安全说明 {#安全说明} 7.1 敏感信息存储 推荐方式 :
方式
说明
密码管理器
1Password, Bitwarden 等
加密文件
使用 GPG 加密敏感配置
环境变量
通过环境变量注入 API Keys
7.2 SSH Key 管理
7.3 备份验证 1 2 3 4 5 6 7 cd /tmp/clawbackupgit pull origin main ls -la workspace/du -sh workspace/
八、监控与告警 {#监控告警} 8.1 备份日志监控 1 2 3 4 5 tail -20 /home/admin/.openclaw/workspace/data/backup-cron.loggrep -i "error\|fail" /home/admin/.openclaw/workspace/data/backup-cron.log
8.2 备份失败告警 可以在脚本中添加告警逻辑:
1 2 3 4 if [ $? -ne 0 ]; then echo "备份失败!" | mail -s "OpenClaw Backup Alert" admin@example.com fi
九、最佳实践 {#最佳实践} 9.1 备份策略
类型
频率
保留
完整备份
每天
最近 30 天
配置变更
实时
永久
重要文档
实时
永久
9.2 Git 分支管理 1 2 main - 最新备份 backup-YYYY-MM-DD - 历史快照(按需创建)
9.3 定期演练
每月 :验证备份可恢复性
每季度 :更新 SSH Key
每半年 :审查备份策略
参考资料 :
本配置已应用于生产环境 最后更新:2026-03-14