Sync: 云同步文件 - Openclaw Skills
什么是 Sync?
Sync 技能是一个全面的工具集,专为 AI 代理设计,旨在以高可靠性处理复杂的数据迁移任务。通过利用 rsync 和 rclone 等行业标准工具,它为镜像目录、执行备份以及在异构环境之间迁移数据提供了一个安全的框架。该技能是 Openclaw Skills 库的核心组件,专注于保持文件完整性、通过压缩最小化带宽并维护精确的目录结构。
无论您是管理简单的本地备份还是复杂的多云架构,该技能都实现了诸如 dry-run 测试和校验和验证等最佳实践。它确保开发人员可以自动化重复的传输任务,而无需担心意外数据丢失风险,使其成为 Openclaw Skills 生态系统中现代 DevOps 和系统管理工作流的必备工具。
下载入口:https://github.com/openclaw/skills/tree/main/skills/macdesire/sync-backup
安装与下载
1. ClawHub CLI
从源直接安装技能的最快方式。
npx clawhub@latest install sync-backup
2. 手动安装
将技能文件夹复制到以下位置之一
全局模式~/.openclaw/skills/
工作区
<project>/skills/
优先级:工作区 > 本地 > 内置
3. 提示词安装
将此提示词复制到 OpenClaw 即可自动安装。
请帮我使用 Clawhub 安装 sync-backup。如果尚未安装 Clawhub,请先安装(npm i -g clawhub)。
Sync 应用场景
- 通过 SSH 将本地代码更新部署到远程暂存或生产服务器。
- 自动化从本地存储到兼容 S3 的云存储桶的每日备份。
- 保持项目文件夹的精确镜像,同时排除像 node_modules 这样繁重的构建产物。
- 使用部分传输恢复在不可靠的网络连接上同步数据。
- 使用基于校验和的对比审计不同存储区域之间的文件一致性。
- 识别源和目标类型,以在本地/SSH 使用 rsync 或云存储使用 rclone 之间做出选择。
- 评估目录路径结构,应用尾部斜杠逻辑来确定是移动文件夹还是其内容。
- 从 .syncignore 或命令行标志加载排除模式,以过滤掉不必要的元数据和临时文件。
- 启动 dry-run 操作以模拟传输并提供修改预览。
- 使用归档模式执行同步,以保留原始权限、所有权和时间戳。
- 使用校验和或对比工具进行传输后验证,以确保数据一致性。
Sync 配置指南
要利用此技能,请确保您的系统上安装了底层实用程序。此技能兼容 Linux、macOS 和 Windows。
# 在 Debian/Ubuntu 上安装 rsync 和 rclone
sudo apt update && sudo apt install rsync rclone
# 使用 Homebrew 在 macOS 上安装
brew install rsync rclone
# 为 rclone 配置云远程
rclone config
建议妥善配置您的 SSH 密钥,以允许 Openclaw Skills 在无需手动输入密码的情况下执行远程操作。
Sync 数据架构与分类体系
Sync 技能通过元数据和排除项的结构化方法来管理数据移动。
| 组件 | 描述 |
|---|---|
| 源/目标 | 支持本地路径、user@host:path 和 rclone 远程别名。 |
| 排除逻辑 | 在 .syncignore 中使用相对模式跳过如 .git/ 或 __pycache__/ 的文件。 |
| 日志审计 | 使用 --verbose 并将输出重定向到日志文件来捕获同步历史。 |
| 校验和注册表 | 可选的 MD5/SHA-1 验证,用于通过内容而非仅大小/时间验证文件。 |
name: Sync
description: Synchronize files and directories between local, remote, and cloud storage reliably.
metadata: {"clawdbot":{"emoji":"??","requires":{"anyBins":["rsync","rclone"]},"os":["linux","darwin","win32"]}}
File Synchronization Rules
rsync Fundamentals
- Trailing slash matters:
rsync src/copies contents,rsync srccopies the folder itself — this is the #1 cause of wrong directory structures - Always use
-avzbaseline: archive mode preserves permissions/timestamps, verbose shows progress, compress speeds transfers - Add
--deleteonly when you want destination to mirror source exactly — without it, deleted source files remain on destination - Use
--dry-runbefore any destructive sync — shows what would change without modifying anything
Exclusions
- Create an exclude file instead of multiple
--excludeflags:rsync -avz --exclude-from=.syncignore src/ dest/ - Standard excludes for code projects:
.git/,node_modules/,__pycache__/,.venv/,*.pyc,.DS_Store,Thumbs.db - Exclude patterns are relative to source root —
/logs/excludes only top-level logs,logs/excludes logs/ anywhere
Cloud Storage (rclone)
rclone syncdeletes destination files not in source;rclone copyonly adds — use copy when unsure- Configure remotes interactively:
rclone config— never hardcode cloud credentials in scripts - Test with
--dry-runfirst, then--progressfor visual feedback during actual sync - For S3-compatible storage, set
--s3-chunk-size 64Mfor large files to avoid timeouts
Verification
- After critical syncs, verify with checksums:
rsync -avzcuses checksums instead of size/time (slower but certain) - For rclone, use
rclone check source: dest:to compare without transferring - Log sync operations to file for audit:
rsync -avz src/ dest/ | tee sync.log
Bidirectional Sync
- rsync is one-way only — for true bidirectional sync, use unison:
unison dir1 dir2 - Unison detects conflicts when both sides change — resolve manually or set prefer rules
- Cloud services like Dropbox/Syncthing handle bidirectional automatically — don't reinvent with rsync
Remote Sync
- For SSH remotes, use key-based auth:
rsync -avz -e "ssh -i ~/.ssh/key" src/ user@host:dest/ - Specify non-standard SSH port:
-e "ssh -p 2222" - Use
--partial --progressfor large files over unreliable connections — allows resume on failure
Common Pitfalls
- Syncing to mounted drives that unmount silently creates a local folder with the mount name — verify mount before sync
- Running sync without
--deleterepeatedly causes destination to accumulate deleted files forever - Time-based sync fails across machines with clock skew — use
--checksumfor accuracy or sync NTP first