openclaw-home-pc/workspace/docs/openclaw-backup-guide.md

250 lines
5.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 🔄 OpenClaw 自动备份系统
## 📋 系统概述
自动备份 OpenClaw 核心配置和工作区数据,每天凌晨 3 点执行,保留最近 7 天的备份。
---
## 🎯 备份内容
### 核心配置
- `openclaw.json` - 主配置文件(含 API 密钥)
- `cron/jobs.json` - 定时任务配置
- `identity/device.json` - 设备身份密钥
- `wecomConfig/config.json` - 企业微信 MCP 配置
- `credentials/` - 凭证文件
- `devices/` - 设备配对信息
### 工作区(最重要)
- `MEMORY.md` - 长期记忆
- `SOUL.md` - 核心身份
- `IDENTITY.md` - 人设定义
- `USER.md` - 用户档案
- `HEARTBEAT.md` - 心跳任务
- `skills/` - 自定义技能5 个)
- `memory/` - 短期记忆文件
---
## ⏰ 执行时间
- **频率**: 每天一次
- **时间**: 凌晨 03:00北京时间
- **时区**: Asia/Shanghai
- **任务 ID**: `6a0ae369-7c2f-423f-b973-739e999f85c4`
---
## 📂 存储位置
- **备份目录**: `/home/ubuntu/backups/openclaw/`
- **备份格式**: `openclaw_YYYYMMDD_HHMMSS.tar.gz`
- **报告文件**: `/tmp/openclaw_backup_report_YYYYMMDD_HHMMSS.txt`
---
## 📤 通知方式
每次备份完成后,通过企业微信自动发送详细报告:
```
🦐 OpenClaw 备份完成报告
📅 备份时间2026-03-17 14:29:49
📦 备份文件openclaw_20260317_142949.tar.gz
💾 压缩包大小200K
📊 备份内容:
✅ 核心配置 (openclaw.json)
✅ 定时任务 (cron/)
✅ 设备身份 (identity/)
✅ 企业微信配置 (wecomConfig/)
✅ 凭证文件 (credentials/)
✅ 工作区 (workspace/)
- 记忆文件10 个
- 自定义技能5 个
📋 备份统计:
• 总备份数1 个
• 总占用204K
• 保留策略7 天
✅ 备份状态:成功
🧹 旧备份已清理
```
---
## 🛠️ 脚本文件
### 备份脚本
**路径**: `~/.openclaw/workspace/scripts/openclaw-backup.sh`
**功能**:
- 备份所有核心配置文件
- 备份工作区(记忆、技能等)
- 创建压缩备份tar.gz
- 清理 7 天前的旧备份
- 生成详细报告
**手动执行**:
```bash
bash ~/.openclaw/workspace/scripts/openclaw-backup.sh
```
### 通知脚本
**路径**: `~/.openclaw/workspace/scripts/openclaw-backup-notify.sh`
**功能**:
- 读取备份报告
- 通过 OpenClaw 发送企业微信通知
---
## 🧹 保留策略
- **保留时间**: 7 天
- **清理方式**: 自动删除 7 天前的备份
- **执行时间**: 每次备份完成后
**清理逻辑**:
```bash
find ~/backups/openclaw -name "openclaw_*.tar.gz" -mtime +7 -delete
```
---
## 📊 备份统计
| 项目 | 大小 | 说明 |
|------|------|------|
| openclaw.json | ~12K | 主配置 |
| cron/ | ~60K | 定时任务 |
| identity/ | ~12K | 设备密钥 |
| wecomConfig/ | ~8K | 企微配置 |
| credentials/ | ~16K | 凭证 |
| devices/ | ~12K | 配对信息 |
| workspace/ | ~1.2M | 工作区 |
| **压缩包** | **~200K** | 压缩后 |
---
## 🔒 安全建议
### 1. 加密备份
```bash
# 使用 GPG 加密
gpg --symmetric --cipher-algo AES256 openclaw_20260317_030000.tar.gz
```
### 2. 远程备份
```bash
# 同步到远程服务器
rsync -avz ~/backups/openclaw/ user@remote:/backups/openclaw/
```
### 3. 权限控制
```bash
# 设置备份目录权限
chmod 700 ~/backups/openclaw/
```
---
## 🔧 管理命令
### 查看备份列表
```bash
ls -lh ~/backups/openclaw/
```
### 查看最近备份
```bash
ls -lt ~/backups/openclaw/ | head -5
```
### 手动备份
```bash
bash ~/.openclaw/workspace/scripts/openclaw-backup.sh
```
### 查看备份报告
```bash
cat /tmp/openclaw_backup_report_*.txt
```
### 恢复备份
```bash
# 1. 停止 OpenClaw
openclaw gateway stop
# 2. 解压备份
cd ~/backups/openclaw/
tar -xzf openclaw_20260317_030000.tar.gz
# 3. 恢复配置
cp openclaw_20260317_030000/openclaw.json ~/.openclaw/
cp -r openclaw_20260317_030000/cron ~/.openclaw/
cp -r openclaw_20260317_030000/identity ~/.openclaw/
cp -r openclaw_20260317_030000/wecomConfig ~/.openclaw/
cp -r openclaw_20260317_030000/credentials ~/.openclaw/
cp -r openclaw_20260317_030000/devices ~/.openclaw/
cp -r openclaw_20260317_030000/workspace ~/.openclaw/
# 4. 重启 OpenClaw
openclaw gateway start
```
---
## ⚠️ 故障排查
### 备份失败
1. 检查磁盘空间:`df -h`
2. 检查脚本权限:`chmod +x ~/.openclaw/workspace/scripts/*.sh`
3. 查看错误日志:`cat /tmp/openclaw_backup_report_*.txt`
### 通知未发送
1. 检查 OpenClaw 是否运行:`openclaw gateway status`
2. 检查企业微信配置:`cat ~/.openclaw/openclaw.json | grep wecom`
3. 手动发送测试:使用 `openclaw sessions send`
### 备份文件过大
1. 排除不必要文件extensions/、node_modules/
2. 检查 workspace/是否有大文件
3. 考虑使用增量备份
---
## 📅 维护计划
### 每日(自动)
- 03:00 执行备份
- 发送备份报告
- 清理 7 天前备份
### 每周(建议)
- 检查备份文件大小是否正常
- 验证备份文件完整性
- 审查备份日志
### 每月(建议)
- 测试备份恢复流程
- 清理本地备份(保留最近 30 天)
- 同步到远程存储
---
## 📝 更新日志
| 日期 | 版本 | 更新内容 |
|------|------|----------|
| 2026-03-17 | v1.0 | 初始版本,部署自动备份系统 |
---
**部署日期**: 2026-03-17
**下次备份**: 2026-03-18 03:00
**任务状态**: ✅ 正常运行