Files
sanguo_quant_live/AUTO-SYNC-MANAGEMENT.md
T
2026-03-26 00:41:05 +08:00

135 lines
3.5 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.
# 自动同步监控系统管理指南
## 系统概述
这是一个基于文件变化监控的自动Git同步系统,监听 `/Users/chufeng/.openclaw/sanguo_projects/sanguo_quant_live` 目录,当任何文件变化时自动执行双向git同步。
## 核心组件
1. **监控器** (`simple-file-watcher.py`) - Python脚本,每2秒检查文件变化
2. **启动脚本** (`start-simple-watcher.sh`) - 启动监控器为后台守护进程
3. **停止脚本** (`stop-simple-watcher.sh`) - 停止监控器
4. **状态脚本** (`status-simple-watcher.sh`) - 检查监控器状态
5. **同步脚本** (`auto-sync.sh`) - 执行git拉取、添加、提交、推送
## 使用方法
### 启动监控器
```bash
./start-simple-watcher.sh
```
### 停止监控器
```bash
./stop-simple-watcher.sh
```
### 检查状态
```bash
./status-simple-watcher.sh
```
### 查看监控日志
```bash
tail -f simple-watcher.log
```
### 查看同步日志
```bash
tail -f auto-sync.log
```
## 文件变化触发流程
```
文件创建/修改/删除
监控器检测到变化 (2秒内)
执行 auto-sync.sh
1. git pull origin main (拉取远程变更)
2. git add . (添加所有变更)
3. git commit -m "auto-sync: ..." (提交)
4. git push origin main (推送)
完成同步,等待下次变化
```
## 技术细节
### 监控器特性
- 轮询间隔:2秒
- 忽略文件:.log, .tmp, ~ (临时文件)
- 忽略目录:.git
- 防重复执行:使用锁文件 `/tmp/sanguo_sync.lock`
- 日志记录:`simple-watcher.log`
### 同步脚本特性
- 自动处理未跟踪文件
- 错误处理:失败重试2次
- 日志记录:`auto-sync.log`
- 防冲突:先pull再push
### PID管理
### PID管理
- PID文件:`simple-watcher.pid`
- 自动清理:停止时删除PID文件
- 状态检查:通过PID验证进程运行状态
## 故障排除
### 监控器没有启动
1. 检查Python3是否安装:`python3 --version`
2. 检查脚本权限:`chmod +x simple-file-watcher.py`
3. 检查日志:`tail -f simple-watcher.log`
### 同步失败
1. 检查网络连接
2. 检查Git配置:`git remote -v`
3. 检查Git权限:确保有推送权限
4. 查看错误日志:`tail -f auto-sync.log`
### 文件变化未触发同步
1. 检查监控器是否运行:`./status-simple-watcher.sh`
2. 检查文件是否被忽略(如.log文件)
3. 检查监控间隔:默认2秒,可能需要等待
## 系统集成
### 开机自启动
可以将以下命令添加到crontab或launchd以实现开机自启动:
```bash
cd "/Users/chufeng/.openclaw/sanguo_projects/sanguo_quant_live" && nohup python3 simple-file-watcher.py > /dev/null 2>&1 &
```
### 与其他系统集成
- 可以与CI/CD系统集成
- 可以扩展为多目录监控
- 可以添加通知功能(邮件、Slack等)
## 性能考虑
- 轮询间隔2秒,对系统负载影响小
- 监控整个目录树,但忽略.git目录
- 同步脚本有防重复执行机制,避免频繁触发
## 安全注意事项
1. 确保.gitignore正确配置,不提交敏感信息
2. 监控器在后台运行,确保有适当权限
3. 同步脚本会推送所有变更,确保不推送机密数据
## 扩展功能
如需扩展功能,可以修改 `simple-file-watcher.py`
1. 添加文件类型过滤
2. 添加事件类型区分(创建/修改/删除)
3. 添加批量处理(多个变化一次同步)
4. 添加通知机制
## 维护
- 定期清理日志文件
- 监控磁盘空间
- 检查Git仓库健康状态
- 更新Python依赖(如有)