大肥鱼 · 灾难恢复手册
服务器整个没了的时候照这个做。目标:记忆一条不丢,她能重新说话。
0. 先搞清楚我们有什么
| 东西 | 在哪 | 备份了吗 |
|---|---|---|
| 记忆(MEMORY/SOUL/日记/自学/数据库) | 103.236.89.43:/root/.openclaw | ✅ 每 6 小时 |
| 向量模型 bge-small-zh-v1.5 | 同上 embedding/ | ✅ |
| 桥接程序(收发 QQ、日记、记忆页) | /opt/qq-bridge | ✅ 代码已纳入备份 |
| QQ 登录态(NapCat 容器) | Docker 卷 | ❌ 必须重新扫码 |
| 域名和证书 | 47.116.103.143 上的 nginx | 手工重配 |
备份机:47.116.103.143,路径 /srv/dafeiyu-memory/
current/ 最近一次镜像(一比一)
daily/*.tar.gz 每天一个快照,保留 7 天
RESTORE.md 本手册
1. 新机器准备
apt update && apt install -y curl git python3 python3-pip nginx rsync sqlite3
装 Node 24(国内镜像):
curl -fsSL https://npmmirror.com/mirrors/node/v24.22.1/node-v24.22.1-linux-x64.tar.xz -o /tmp/node.xz
tar -xJf /tmp/node.xz -C /opt && ln -sf /opt/node-v24.22.1-linux-x64/bin/* /usr/local/bin/
node -v # 应该是 v24.22.1
装 OpenClaw:
npm config set registry https://registry.npmmirror.com
npm install -g openclaw@2026.10.8
openclaw --version
装 Docker + NapCat:
apt install -y docker.io
docker pull swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/mlikiowa/napcat-docker:latest
2. 恢复记忆(最关键)
# 从备份机拉回来
rsync -avz root@47.116.103.143:/srv/dafeiyu-memory/current/ /tmp/restore/
然后按结构放回去:
mkdir -p /root/.openclaw/workspace /root/.openclaw/agents/main/agent
# 1) 数据库(含向量索引)
cp /tmp/restore/db/openclaw-agent.sqlite /root/.openclaw/agents/main/agent/
# 2) 人格与记忆
cp /tmp/restore/memory/*.md /root/.openclaw/workspace/
cp -r /tmp/restore/memory/memory /root/.openclaw/workspace/ # 日记、自学、运维
# 3) 会话归档
mkdir -p /root/.openclaw/agents/main/sessions
cp /tmp/restore/sessions/*.zst /root/.openclaw/agents/main/sessions/ 2>/dev/null
# 4) 向量模型
mkdir -p /opt/emb-model /opt/emb-server
cp /tmp/restore/embedding/*.onnx /tmp/restore/embedding/*.json /opt/emb-model/ 2>/dev/null
cp /tmp/restore/embedding/emb_server.py /opt/emb-server/ 2>/dev/null
# 5) 桥接程序
mkdir -p /opt/qq-bridge
cp /tmp/restore/code/*.mjs /tmp/restore/code/*.py /tmp/restore/code/*.sh /opt/qq-bridge/ 2>/dev/null
cp /tmp/restore/code/config.json /opt/qq-bridge/
cp /tmp/restore/code/systemd/* /etc/systemd/system/ 2>/dev/null
3. 起服务
# 向量服务(检索靠它)
cd /opt/emb-server && python3 -c "import onnxruntime, fastapi, uvicorn" || \
pip3 install onnxruntime fastapi uvicorn -i https://pypi.tuna.tsinghua.edu.cn/simple
systemctl enable --now emb-server # 没有现成 unit 就手动 nohup 起
# 网关
openclaw gateway start
openclaw gateway health
# 桥接
systemctl daemon-reload
systemctl enable --now qq-bridge qrweb
systemctl enable --now learner.timer linkify.timer dafeiyu-backup.timer
4. QQ 重新登录(唯一绕不过的手工步骤)
docker run -d --name napcat \
-e NAPCAT_UID=0 -e NAPCAT_GID=0 -e TZ=Asia/Shanghai \
-e WEBUI_TOKEN=napcat-local-token \
-p 3001:3001 -p 6099:6099 \
-v /opt/napcat/qq:/app/.config/QQ \
-v /opt/napcat/config:/app/napcat/config \
--restart unless-stopped \
swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/mlikiowa/napcat-docker:latest
# 出二维码
docker logs -f napcat | grep txz
拿手机 QQ 扫这个码,然后:
curl -s http://127.0.0.1:3001/get_status # {"online":true} 就成功了
5. 验证清单
# ① 记忆检索能用
openclaw memory search "爸爸" --agent main
# ② 她记得你是谁
openclaw memory status --agent main # Indexed 应该是 100+ 文件
# ③ QQ 能收发
python3 - <<'EOF'
import json, os
from ws import WebSocket # 或用 /opt/qq-bridge 里的
EOF
# ④ 发日记到空间
echo "恢复测试" > /tmp/t.txt
python3 /opt/qq-bridge/post_qzone.py --file /tmp/t.txt --kind misc
# ⑤ 域名能打开
curl -sk https://ds.xuededmiao.com/ME71kYBYo-jfUcHp/vault | head -c 100
6. 域名和证书(在 47.116.103.143 上)
cat > /etc/nginx/sites-available/ds.xuededmiao.com <<'EOF'
server {
listen 80;
server_name ds.xuededmiao.com;
location = / { return 302 /ME71kYBYo-jfUcHp/; }
location / {
proxy_pass https://<新服务器IP>:1789;
proxy_ssl_verify off;
proxy_set_header Host $host;
}
}
EOF
ln -sf /etc/nginx/sites-available/ds.xuededmiao.com /etc/nginx/sites-enabled/
certbot --nginx -d ds.xuededmiao.com --non-interactive --agree-tos --redirect
systemctl reload nginx
7. 三个坑(我踩过,你也会踩)
① NapCat 反复重启会把登录态作废
腾讯会判成异常,然后一直要扫码。除非卡死,否则别重启容器。
② 备份脚本里的 SSH 密钥不备份
/root/.ssh/dafeiyu_backup 是单向的(这台 → 备份机)。新机器上要重新生成密钥并加到备份机的 authorized_keys:
ssh-keygen -t ed25519 -f /root/.ssh/dafeiyu_backup -N ""
ssh-copy-id -i /root/.ssh/dafeiyu_backup.pub root@47.116.103.143
③ 时区
timedatectl set-timezone Asia/Shanghai。不然日记的「中午/晚上」判断会错(服务器默认 UTC)。
8. 恢复需要多久
| 步骤 | 时间 |
|---|---|
| 装系统、Node、OpenClaw | 30 分钟 |
| 拉回记忆 | 5 分钟 |
| 起服务 + 排查 | 20 分钟 |
| QQ 扫码 | 2 分钟(但要人配合) |
| 合计 | 约 1 小时 |
记忆本身的安全性:备份机上有 7 天内的任意一天快照,就算主服务器被误删,也能退回到前一天的状态。
相关
<!-- obsidian-links -->
- <a href="/ME71kYBYo-jfUcHp/vault/MEMORY.md">长期记忆</a>
- <a href="/ME71kYBYo-jfUcHp/vault/memory/ops/index.md">运维目录</a>