Files
2026-05-14 16:56:48 +08:00

75 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.
---
name: "remote-sync"
description: "将本地项目目录通过 rsync 增量同步到远端服务器 39.100.114.100:/data。自动排除 node_modules/.git 等文件。Invoke when user asks to sync/deploy files to remote server."
---
# 远程同步技能
## 使用说明
通过 `/remote-sync` 调用,将当前项目目录增量同步到远端服务器。**本技能为项目级技能,仅对当前项目目录生效。**
## 远端目标
- 服务器: `39.100.114.100`
- 用户: `root`
- 密码: `QQmm3721`
- 远端路径: `/data/projects/招标投标AI推广应用政策解读`
## 操作流程
1. **确认本地目录**:询问用户要上传的本地目录路径。如果用户未指定,默认使用当前工作目录。
2. **确认远端子目录**:询问文件上传到 `/data` 下的哪个子目录。用户可直接回车表示上传到 `/data` 根下,也可指定子路径(如 `my-project` 则目标为 `/data/my-project`)。
3. **执行同步**:使用 `rsync` 通过 SSH 增量同步。
4. **输出结果**:显示同步完成的文件数量和远端路径。
## 同步命令
```bash
sshpass -p 'QQmm3721' rsync -avz --delete \
--exclude 'node_modules' \
--exclude '.git' \
--exclude '.next' \
--exclude '.nuxt' \
--exclude '.cache' \
--exclude 'dist' \
--exclude '*.log' \
--exclude '.env' \
--exclude '.env.*' \
--exclude 'coverage' \
--exclude '.DS_Store' \
--exclude 'Thumbs.db' \
-e "ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10" \
<本地目录>/ \
root@39.100.114.100:/data/<远端子目录>/
```
**说明**
- `--delete`:远端删除本地已不存在的文件,保持镜像一致
- `-avz`:归档模式 + 显示详情 + 压缩传输
- `StrictHostKeyChecking=no`:避免首次连接交互确认
- 末尾 `/` 不可省略,表示同步目录内容而非目录本身
## 依赖检查
首次执行前检查 `sshpass` 是否已安装:
```bash
which sshpass
```
如未安装,提示用户执行:
```bash
sudo apt install -y sshpass # Debian/Ubuntu
# 或
sudo yum install -y sshpass # CentOS/RHEL
```
## 无 sshpass 降级方案
若无法安装 sshpass,退回到交互式 SSH 密钥认证:
1. 提示用户执行 `ssh-copy-id root@39.100.114.100` 配置免密登录
2. 或使用 `rsync` 不带 sshpass,让用户手动输入密码