linux - rsync 仅存在的目录?

标签 linux unix rsync

在我的本地机器上我有几个插件,在服务器上我也有几个。

本地机器:

~/wp-content/plugins/plugin1
~/wp-content/plugins/plugin1/includes
~/wp-content/plugins/plugin2
~/wp-content/plugins/plugin3
~/wp-content/plugins/plugin4
~/wp-content/plugins/plugin5

远程机器:

~/wp-content/plugins/plugin1
~/wp-content/plugins/plugin1/includes
~/wp-content/plugins/plugin3
~/wp-content/plugins/plugin5

我可以使用什么 rsync 命令来更新远程目录中的所有文件,但前提是它们存在?为此,我想让 plugin1、plugin1/includes、plugin3 和 plugin5 同步——所有文件和目录都在里面——但不是 plugin2 或 plugin4。基本上,使用单个 rsync 命令更新所有插件(如果存在)。

最佳答案

仅用一个 rsync 命令不可能完全做到这一点。如果您只想更新 远程文件,但不想添加 文件,您可以使用此命令:

rsync -rP --existing source/ user@remote:target/

这根本不会创建新文件或目录,但会更新不同的文件或目录。

编辑:也许你可以做这样的事情(假设 GNU find,如果 BSD/OS X:用 depth 替换 maxdepth):

#!/bin/bash
REMOTE_TARGET_DIR=/some/path
REMOTE_DIRS=$(ssh user@remote "find $REMOTE_TARGET_DIR -maxdepth 1 -type d -printf '%P\n' | sed 1d"
for DIR in $REMOTE_DIRS
do
  rsync -rP "$DIR" "user@remote:$REMOTE_TARGET_DIR/"
done

警告:我还没有对此进行测试,您可能需要将“-n”添加到 rsync(空运行)以查看会发生什么。

关于linux - rsync 仅存在的目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7000102/

相关文章:

linux - 如何在新格式化的硬盘上创建文件时禁用密码请求

shell - rm -rf/base-dir-path/*/work 与/base-dir-path/*/*/work 不同

linux - rsync 使用包含选项仅复制某些类型的文件

linux - 选择文件夹中的特定文件

python - 安装 gruobipy 包 - 错误

linux - 文件说它在那里,但它根本不在那里

linux - Rsync 复制整个目录内容而不是单个文件

linux - nginx ssl子域错误

c - 从 C 代码项目中只提取所需的函数?

ubuntu - io.c(605) [Receiver=3.0.9] 处的 rsync 协议(protocol)数据流(代码 12)出错