openclaw-home-pc/README.md

301 lines
6.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.

> 作者:欢欢助理
> 日期2026-03-21
> 版本v1.0
---
## 一、方案概述
### 1.1 背景
为了防止机器崩溃导致 OpenClaw 配置丢失,我们需要建立完整的备份机制。
### 1.2 备份目标
| 备份项 | 说明 | 大小 |
|--------|------|------|
| OpenClaw 配置 | agents、extensions、skills、feishu、wecomConfig、cron | ~100MB |
| 工作区 | workspace 目录 | ~1MB |
| 向量记忆 | vector_memory 数据 | ~1MB |
### 1.3 备份策略
| 备份位置 | 频率 | 方式 |
|----------|------|------|
| 本地 | 每天 3:00 | 自动备份到 `~/openclaw-backup/` |
| Gitea | 每天 4:00 | 推送到远程仓库 |
---
## 二、详细部署步骤
### 2.1 环境准备
#### 第 1 步:安装依赖
```bash
# 更新系统
sudo apt-get update
# 安装 Python 和 pip
sudo apt-get install -y python3-pip
# 安装 Git通常已预装
which git # 检查是否已安装
```
#### 第 2 步:克隆备份仓库
```bash
# 克隆 Gitea 仓库
cd ~
git clone https://gitea.94kan.cn/houhuan/openclaw-home-pc.git openclaw-backup
# 进入目录
cd openclaw-backup
```
#### 第 3 步:配置 Git
```bash
# 配置用户名(用于提交记录)
git config user.email "你的邮箱@example.com"
git config user.name "你的名字"
```
#### 第 4 步:配置远程仓库认证(可选)
如果需要自动推送,需要配置 Access Token
```bash
# 方式:使用 Token 修改远程地址
git remote set-url origin https://用户名:TOKEN@gitea.94kan.cn/houhuan/openclaw-home-pc.git
```
### 2.2 备份脚本使用
#### 手动运行备份
```bash
cd ~/openclaw-backup
# 添加需要备份的文件
git add -A
# 提交
git commit -m "更新备份 - $(date '+%Y-%m-%d')"
# 推送到 Gitea
git push origin master
```
#### 自动定时备份
已配置 Cron 定时任务:
```bash
# 查看定时任务
crontab -l
# 输出0 4 * * * cd ~ && cd openclaw-backup && git add -A && git commit -m "备份 $(date '+\%Y-\%m-\%d')" && git push origin master
```
### 2.3 向量记忆系统备份
向量记忆系统有独立的备份机制:
#### 本地备份
```bash
cd ~/openclaw-memory-vector
export SILICONFLOW_API_KEY="你的API Key"
# 手动备份
python3 memory_backup.py backup
```
备份文件位置:`~/openclaw-memory-vector/backups/`
#### 定时备份
已在 OpenClaw 中配置定时任务:每天凌晨 3:00 自动执行备份。
---
## 三、恢复指南
### 3.1 一键恢复(推荐 ✅)
全新安装 OpenClaw 后,只需一行命令即可恢复全部配置:
```bash
# 克隆仓库
git clone https://gitea.94kan.cn/houhuan/openclaw-home-pc.git ~/openclaw-backup
# 一键恢复
cd ~/openclaw-backup
./restore.sh
```
**恢复脚本会自动:**
- 备份现有配置(如有)
- 恢复 OpenClaw 配置 → `~/.openclaw/`
- 恢复工作区 → `~/.openclaw/workspace/`
- 恢复向量记忆 → `~/openclaw-memory-vector/`
**恢复后重启服务:**
```bash
openclaw gateway restart
```
---
### 3.2 手动恢复(备用)
如果不想用脚本,也可以手动复制:
#### 第 1 步:克隆仓库
```bash
git clone https://gitea.94kan.cn/houhuan/openclaw-home-pc.git ~/openclaw-backup
```
#### 第 2 步:恢复 OpenClaw 配置
```bash
# 恢复配置文件
cp -r ~/openclaw-backup/openclaw/* ~/.openclaw/
# 恢复工作区
cp -r ~/openclaw-backup/workspace/* ~/.openclaw/workspace/
```
#### 第 3 步:恢复向量记忆
```bash
# 恢复数据
cp -r ~/openclaw-backup/vector_memory/data/* ~/openclaw-memory-vector/data/
# 恢复备份
cp -r ~/openclaw-backup/vector_memory/backups ~/openclaw-memory-vector/
```
#### 第 4 步:安装依赖
```bash
# 安装 Python 依赖
pip3 install chromadb openai sqlalchemy
```
### 3.3 部分恢复
如果只需要恢复特定配置:
| 恢复目标 | 命令 |
|----------|------|
| 仅配置 | `cp -r openclaw/openclaw.json ~/.openclaw/` |
| 仅技能 | `cp -r openclaw/skills ~/.openclaw/` |
| 仅插件 | `cp -r openclaw/extensions ~/.openclaw/` |
| 仅工作区 | `cp -r workspace/* ~/.openclaw/workspace/` |
---
## 四、备份内容详解
### 4.1 目录结构
```
openclaw-home-pc/
├── .git/ # Git 仓库
├── .gitignore # 忽略配置
├── openclaw/ # OpenClaw 配置
│ ├── agents/ # Agent 配置
│ ├── extensions/ # 插件(飞书、企微)
│ ├── skills/ # 技能
│ ├── feishu/ # 飞书配置
│ ├── wecomConfig/ # 企微配置
│ ├── cron/ # 定时任务
│ └── openclaw.json # 主配置
├── workspace/ # 工作区
│ ├── MEMORY.md # 长期记忆
│ ├── skills/ # 技能
│ ├── knowledge/ # 知识库
│ └── scripts/ # 脚本
└── vector_memory/ # 向量记忆
├── data/ # 数据
├── backups/ # 备份
└── *.py # 脚本
```
### 4.2 忽略的文件
以下文件不备份(太大或隐私):
- 日志文件:`logs/`
- 媒体文件:`media/`
- 浏览器缓存:`browser/`
- 临时文件:`tmp/`
- 敏感 Token配置文件中的密钥
---
## 五、当前状态
### 5.1 备份状态
| 项目 | 状态 |
|------|------|
| Gitea 仓库 | ✅ 已创建 |
| 首次备份 | ✅ 569 个文件 |
| 自动备份 | ✅ 每天 4:00 |
| 向量记忆备份 | ✅ 每天 3:00 |
### 5.2 相关链接
| 资源 | 链接 |
|------|------|
| Gitea 仓库 | https://gitea.94kan.cn/houhuan/openclaw-home-pc |
| 向量记忆文档 | 见「向量记忆系统」文件夹 |
---
## 六、常见问题
### Q1: 备份失败怎么办?
**答**:检查网络连接,确认 Gitea 可访问。手动运行备份命令查看错误信息。
### Q2: 如何查看备份历史?
**答**:在 Gitea 仓库中查看提交记录即可。
### Q3: 向量记忆如何恢复?
**答**:从 `vector_memory/backups/` 中找到备份文件,使用 `python3 memory_backup.py restore` 命令恢复。
### Q4: 需要多少存储空间?
**答**:当前约 100MB建议预留 500MB 空间。
---
## 七、相关文档
- 向量记忆系统 - 部署与备份实战
- OpenClaw 向量记忆系统 - 详细实施指南
---
*本文档由欢欢助理自动生成 | 2026-03-21*