💾 RPi 冷备恢复指南¶
备份架构¶
/home/pi/
├── .hermes/ ← Hermes Agent 配置、skills、scripts、memories
├── cbrain/ ← 文档仓库
├── hermes-workspace/ ← 工作目录
├── podmate/ ← PodMate 项目代码
└── ...
↓ restic backup(增量、去重、AES-256 加密)
rclone:aliyun (WebDAV → localhost:8090 → 阿里云盘)
↓
阿里云盘 /restic-repo/
├── keys/ ← 加密密钥
├── data/ ← 加密数据块
├── snapshots/ ← 快照索引
├── index/ ← 数据块索引
└── locks/ ← 锁
restic 仓库是一个目录。备份内容是加密的数据块 + 快照元数据。 不要手动编辑阿里云盘上的 restic 目录,否则数据损坏。所有操作通过 restic 命令行。
快照管理¶
当前保留策略(在 cold-backup.sh 中):
| 频率 | 保留 |
|---|---|
| 每日 | 60 天 |
| 每周 | 12 周 |
| 每月 | 12 个月 |
场景一:在现有 RPi 上恢复某个历史版本¶
典型场景: - 改坏了某个文件,想回到昨天的版本 - 想看看某个文件的旧版本内容
1. 查看有哪些快照¶
restic -r rclone:aliyun:restic-repo --password-file /home/pi/.restic-pw snapshots
输出示例:
ID Time Host Tags Paths
--------------------------------------------------------------------------
30f7d30b 2026-07-12 18:57:08 pi /home/pi
a1b2c3d4 2026-07-11 03:00:02 pi /home/pi
e5f6g7h8 2026-07-10 03:00:05 pi /home/pi
2. 查看某个快照里有什么文件¶
# 查看快照 a1b2c3d4 中 /home/pi/cbrain/ 目录下的文件
restic -r rclone:aliyun:restic-repo --password-file /home/pi/.restic-pw \
ls a1b2c3d4 /home/pi/cbrain/ | head -30
3. 恢复整个 home 目录到某个时间点¶
# 恢复到快照 a1b2c3d4(会覆盖当前文件!)
restic -r rclone:aliyun:restic-repo --password-file /home/pi/.restic-pw \
restore a1b2c3d4 --target /
这会在 /home/pi/ 下还原所有文件(target 是 /,因为快照里路径是 /home/pi/)。
4. 只恢复单个文件或目录¶
# 只恢复 cbrain(到 /tmp 先检查,确认没问题再覆盖)
restic -r rclone:aliyun:restic-repo --password-file /home/pi/.restic-pw \
restore a1b2c3d4 --target /tmp/restore --path /home/pi/cbrain
# 确认后再 cp 回原位
cp -a /tmp/restore/home/pi/cbrain ~/cbrain
5. 恢复最近 3 天的快照(--latest N)¶
restic -r rclone:aliyun:restic-repo --password-file /home/pi/.restic-pw \
restore --latest 3 --target /
6. 比较两个快照之间的差异¶
restic -r rclone:aliyun:restic-repo --password-file /home/pi/.restic-pw \
diff 30f7d30b a1b2c3d4
场景二:在新 RPi 上完整恢复(机器坏了/换卡)¶
前提:新 RPi 需要有阿里云盘 API 访问权限。
恢复流程分三步: 1. 搭建 WebDAV 链路(让新 RPi 能访问阿里云盘) 2. 装 restic + rclone(恢复工具) 3. 从远端的 restic 仓库恢复数据
第 1 步:安装基础工具¶
# 装 restic 和 rclone
sudo apt update && sudo apt install -y restic rclone curl
# 验证
restic version
rclone version
第 2 步:搭建 WebDAV 链路¶
备份数据在阿里云盘的 /restic-repo/ 目录下,需要通过 rclone 的 WebDAV 协议访问。
这一步是在新机器上重新建立通往阿里云盘的隧道。
2a. 获取阿里云盘 refresh_token¶
- 浏览器打开:https://www.aliyundrive.com/sign/in
- 登录后按 F12 → Application → Local Storage
- 找
token键,复制refresh_token的值
或者用抓包工具从阿里云盘网页版获取。
2b. 运行 aliyundrive-webdav¶
从源码编译(推荐,因为 musl 静态二进制在老 glibc 上会 segfault):
# 装 Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"
# 编译 aliyundrive-webdav
git clone https://github.com/ messense/aliyundrive-webdav.git ~/aliyundrive-webdav-src
cd ~/aliyundrive-webdav-src
cargo build --release
# 启动 WebDAV(端口 8090)
cd ~/aliyundrive-webdav-src
ALL_PROXY="" HTTP_PROXY="" HTTPS_PROXY="" no_proxy="*" \
./target/release/aliyundrive-webdav \
--refresh-token "你的refresh_token" \
--port 8090 &
💡 省力方案:也可以直接从
cold-backup.sh启动,它会自动读取/home/pi/.aliyun-token并启动 WebDAV:恢复不需要备份,只需要 WebDAV 活着。可以手动跑~/.hermes/scripts/cold-backup.sh # 会自动拉 WebDAV 然后备份cd ~/aliyundrive-webdav-src && nohup ./target/release/aliyundrive-webdav --refresh-token "xxx" --port 8090 &
2c. 配置 rclone WebDAV remote¶
rclone config
# 交互式配置:
# n) New remote
# name: aliyun(与备份脚本一致)
# Type: webdav
# url: http://localhost:8090
# vendor: other
# user: (留空)
# pass: (留空)
# y) Yes this is OK
# q) Quit config
# 验证:
rclone lsd aliyun:
# 应该能看到 restic-repo/
第 3 步:创建 restic 密码文件¶
备份时用的密码是冷备链路的核心密钥,没有密码无法解密任何数据。
# 记住备份时设置的密码
echo "你的restic密码" > /home/pi/.restic-pw
chmod 600 /home/pi/.restic-pw
⚠️ 如果忘了密码,数据无法恢复。 restic 的加密没有后门。 密码存于
/home/pi/.restic-pw(已备份的 home 里也有一份)。
第 4 步:验证仓库可访问¶
restic -r rclone:aliyun:restic-repo --password-file /home/pi/.restic-pw snapshots
能看到快照列表说明访问通了。
第 5 步:完整恢复¶
# 恢复到最新的快照(覆盖 /home/pi/)
restic -r rclone:aliyun:restic-repo --password-file /home/pi/.restic-pw \
restore latest --target /
restore latest会自动选择最新快照。 也可以指定restore 30f7d30b恢复某个特定时间点。
恢复后检查数据完整性:
restic -r rclone:aliyun:restic-repo --password-file /home/pi/.restic-pw check
第 6 步:重新部署冷备链路(可选)¶
数据恢复后,在新机器上重新布署备份链路:
# 1. 写密码和 token 文件
echo "你的refresh_token" > /home/pi/.aliyun-token
# 2. 设 cron
crontab -e
添加到 crontab:
*/5 * * * * /home/pi/.hermes/scripts/webdav-watchdog.sh > /dev/null 2>&1
0 3 * * * /home/pi/.hermes/scripts/cold-backup.sh > /tmp/cold-backup-last.log 2>&1
@reboot sleep 10 && /home/pi/.hermes/scripts/cold-backup.sh > /tmp/reboot-backup.log 2>&1
Hermes cron 的健康检查(8AM / 8PM)在前一个会话里配过了,需要用 hermes cron list 查看并重新创建。
快速参考卡¶
# 查看快照
restic -r rclone:aliyun:restic-repo --password-file ~/.restic-pw snapshots
# 查看快照里的文件
restic -r rclone:aliyun:restic-repo --password-file ~/.restic-pw ls <snapshot-id> <path>
# 恢复整个 home 到最新版本
restic -r rclone:aliyun:restic-repo --password-file ~/.restic-pw restore latest --target /
# 恢复某个目录到指定时间点(先到 /tmp 检查)
restic -r rclone:aliyun:restic-repo --password-file ~/.restic-pw restore <id> --target /tmp/restore --path /home/pi/cbrain
# 备份完整性验证
restic -r rclone:aliyun:restic-repo --password-file ~/.restic-pw check
# 查看仓库统计
restic -r rclone:aliyun:restic-repo --password-file ~/.restic-pw stats --mode raw-data
# 比较两个快照
restic -r rclone:aliyun:restic-repo --password-file ~/.restic-pw diff <id1> <id2>
安全提醒¶
| 不能做的事 | 为什么 |
|---|---|
❌ 手动删除阿里云盘 restic-repo/ 下的文件 |
restic 仓库一致性会坏 |
| ❌ 把密码存在不安全的地方 | 没有密码 = 数据永远无法恢复 |
❌ 用 sed/grep 修改 restic-repo/ 里的文件 |
加密数据块,改了就读不了 |
| ❌ 同一仓库供两台机器同时备份 | restic 不允许多写(locks 机制) |