Files
AI-document/学习笔记/同步脚本问题总结.md
2026-05-07 12:30:26 +08:00

89 lines
2.3 KiB
Markdown
Raw Permalink 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.
# rclone bisync 同步脚本问题总结
*记录日期:2026-05-07*
---
## 问题一:锁文件僵死导致任务被跳过
### 现象
日志持续出现:
```
⚠️ 另一个同步任务正在运行,跳过本次。
```
手动运行脚本也无法执行,所有 cron 触发的任务全部跳过。
### 原因
rclone bisync 在上一次同步过程中因网络超时异常退出,但锁文件 `/tmp/gdrive_sync.lock` 没有被正常清除,导致后续所有任务误判为"有实例正在运行"而跳过。
### 临时解决方法
```bash
rm -f /tmp/gdrive_sync.lock
~/gdrive_sync.sh
```
### 长期修复方案
在脚本中加入锁文件超时检测:锁文件存在超过 600 秒(10 分钟)自动视为僵死并清除,不再需要手动干预。
---
## 问题二:网络超时连接失败
### 现象
日志出现:
```
CRITICAL: Failed to create file system for destination "gdrive:学习笔记":
couldn't find root directory ID: dial tcp 142.250.204.42:443: i/o timeout
```
### 原因
访问 Google API 服务器(googleapis.com)网络不通,导致 rclone 无法建立连接,同步直接失败退出。
### 临时解决方法
确保网络可以访问 Google 服务,或配置代理:
```bash
export HTTPS_PROXY=http://127.0.0.1:代理端口
~/gdrive_sync.sh
```
### 长期修复方案
脚本中加入同步前网络检测 + 重试机制:
- 连不上时每 30 秒重试一次,最多重试 3 次
- rclone 参数加入 `--timeout 60s``--contimeout 30s``--retries 3`
- 超过重试次数则记录日志,等待下一个 cron 周期,不阻塞进程
---
## 改进前后对比
| 问题 | 旧版本 | 新版本 |
|------|--------|--------|
| 锁文件卡死 | 永久阻塞,需手动删除 | 超过 10 分钟自动清理 |
| 网络超时 | 直接失败退出 | 重试 3 次,间隔 30 秒 |
| 连接参数 | 无超时设置 | 60s 超时 + 自动重连 |
| 状态损坏 | 需手动 --resync | 失败后自动 --resync |
---
## 同步配置概览
- **同步工具**rclone bisync(双向同步)
- **本机目录**`/home/chen/AI-document/学习笔记`
- **Google Drive 目录**`gdrive:学习笔记`
- **自动同步频率**:每 15 分钟(cron 任务)
- **日志位置**`~/.gdrive_sync.log`
- **锁文件位置**`/tmp/gdrive_sync.lock`