OpenClaw 迁移记录
OpenClaw 的所有状态都在 ~/.openclaw 目录里——配置、会话、记忆、插件。换机器就是把这个目录搬过去,关键是停服务再打包,不然文件处于写入状态会损坏。
相关文档:OpenClaw (opens new window)
# 迁移步骤
# ① 旧机器:停 gateway
打包前必须停服务,保证文件一致性:
openclaw gateway stop
不停直接打包的风险:会话数据库、记忆文件正在写入,打包出来的可能是半成品,恢复后数据丢失。
# ② 打包
排除 logs 目录,减小体积:
cd ~ && tar -czf openclaw-state.tgz --exclude='.openclaw/logs' .openclaw
要看下包的大小是否正常:
ls -lh openclaw-state.tgz
# ③ 传输
rsync 或 scp 都行:
# scp
scp openclaw-state.tgz root@xx.xx.xx.xx:~/
# rsync(支持断点续传,大文件推荐)
rsync -avzP openclaw-state.tgz root@xx.xx.xx.xx:~/
# ④ 新机器:解压覆盖
先装好 openclaw,再解压:
cd ~ && tar -xzf openclaw-state.tgz
# ⑤ 修复权限(关键)
root 传输过来的文件属主可能不对,不修权限服务起不来:
chown -R $(whoami):$(whoami) ~/.openclaw
用 root 登录新机器时尤其注意这步——解压出来的文件属主是 root,但 openclaw 服务通常以普通用户跑。
# ⑥ 体检 + 重启
# 检查配置和依赖是否完整
openclaw doctor
# 重启 gateway
openclaw gateway restart
# 确认状态
openclaw status
doctor 报错就按提示修,别跳过直接启动。
# 一键脚本
把上面的步骤串起来,新机器装好 openclaw 后跑一次:
#!/bin/bash
# 新机器恢复脚本:解压 + 权限 + 体检 + 启动
set -e
cd ~
tar -xzf openclaw-state.tgz
chown -R $(whoami):$(whoami) ~/.openclaw
openclaw doctor
openclaw gateway restart
openclaw status
# 迁移后检查清单
# 配置完整
openclaw doctor
# 服务运行中
openclaw status
# 会话/记忆还在
ls ~/.openclaw/
# 日志无报错
tail -50 ~/.openclaw/logs/gateway.log
上次更新: 2026/08/18, 01:07:41