Sync:多环境文件与云同步 - Openclaw Skills

作者:互联网

2026-03-27

AI教程

什么是 Sync?

Sync 技能专为需要精确控制数据分发的开发人员和系统管理员设计。通过封装 rsync 和 rclone 等行业标准工具的功能,该技能可以实现镜像目录、部署代码和管理备份的自动化工作流。它是 Openclaw Skills 库中维护跨多样化基础设施数据一致性的核心组件。

无论您是通过 SSH 将本地更新推送到生产服务器,还是将资产存档到兼容 S3 的云存储,此技能都能确保权限、时间戳和目录结构保持不变。它通过空运行(dry-run)功能强调安全性,并通过压缩和增量传输逻辑强调效率。

下载入口:https://github.com/openclaw/skills/tree/main/skills/ivangdavila/sync

安装与下载

1. ClawHub CLI

从源直接安装技能的最快方式。

npx clawhub@latest install sync

2. 手动安装

将技能文件夹复制到以下位置之一

全局模式 ~/.openclaw/skills/ 工作区 /skills/

优先级:工作区 > 本地 > 内置

3. 提示词安装

将此提示词复制到 OpenClaw 即可自动安装。

请帮我使用 Clawhub 安装 sync。如果尚未安装 Clawhub,请先安装(npm i -g clawhub)。

Sync 应用场景

  • 将 Web 应用程序部署到远程服务器,同时排除版本控制和依赖项文件夹。
  • 自动化从本地工作站到云存储提供商的定期备份。
  • 在分布式团队之间同步大型数据集,并进行校验和验证。
  • 将本地开发环境镜像到远程暂存容器。
  • 在高延迟连接上恢复中断的大型媒体文件传输。
Sync 工作原理
  1. 该技能评估源路径和目标路径,对结尾斜杠应用特定逻辑,以确定是移动目录本身还是仅移动其内容。
  2. 它使用归档模式初始化基准配置,以保留所有文件元数据,包括权限和修改时间。
  3. 从 .syncignore 文件加载用户定义的排除模式,以过滤掉 node_modules 或系统日志等不需要的文件。
  4. 对于远程目标,它通过 SSH 建立安全连接,支持自定义端口和基于密钥的身份验证。
  5. 对于云目标,它利用 rclone remotes 与 S3、Drive 或其他云 API 接口,并优化块大小。
  6. 使用校验和执行可选的验证步骤,以确保源和目标之间的位级精确度。

Sync 配置指南

要在 Openclaw Skills 中使用 Sync 技能,请确保您的主机上安装了必要的二进制文件。

# 在 Ubuntu/Debian 上安装 rsync 和 rclone
sudo apt update && sudo apt install rsync rclone

# 在 macOS 上安装 rsync 和 rclone
brew install rsync rclone

对于云同步,请初始化您的远程配置:

rclone config

Sync 数据架构与分类体系

Sync 技能基于路径逻辑和配置文件运行,以组织数据移动。

特性 描述
源路径 数据的本地或远程起点。
目标路径 数据将被镜像到的目标位置。
排除列表 相对于源根目录的 .syncignore 文件,包含跳过模式。
校验和日志 在验证阶段生成的可选审计日志。
远程配置 存储在 rclone.conf 中的配置,用于云提供商身份验证。
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 src copies the folder itself — this is the #1 cause of wrong directory structures
  • Always use -avz baseline: archive mode preserves permissions/timestamps, verbose shows progress, compress speeds transfers
  • Add --delete only when you want destination to mirror source exactly — without it, deleted source files remain on destination
  • Use --dry-run before any destructive sync — shows what would change without modifying anything

Exclusions

  • Create an exclude file instead of multiple --exclude flags: 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 sync deletes destination files not in source; rclone copy only adds — use copy when unsure
  • Configure remotes interactively: rclone config — never hardcode cloud credentials in scripts
  • Test with --dry-run first, then --progress for visual feedback during actual sync
  • For S3-compatible storage, set --s3-chunk-size 64M for large files to avoid timeouts

Verification

  • After critical syncs, verify with checksums: rsync -avzc uses 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 --progress for 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 --delete repeatedly causes destination to accumulate deleted files forever
  • Time-based sync fails across machines with clock skew — use --checksum for accuracy or sync NTP first