简体   繁体   English

rsync 仅存在的目录?

[英]rsync only directories that exist?

On my local machine I have several plugins, and on the server I have a few.在我的本地机器上我有几个插件,在服务器上我有几个。

Local Machine:本地机器:

~/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

Remote Machine:远程机器:

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

What rsync command can I use to update all the files in the remote directories, but only if they exist?我可以使用什么 rsync 命令来更新远程目录中的所有文件,但前提是它们存在? For this I would like to have plugin1, plugin1/includes, plugin3, and plugin5 synced - with all files and directories inside - but not plugin2 or plugin4.为此,我想让 plugin1、plugin1/includes、plugin3 和 plugin5 同步——其中包含所有文件和目录——但不是 plugin2 或 plugin4。 Basically, update all of the plugins if they exist with a single rsync command.基本上,使用单个 rsync 命令更新所有插件(如果它们存在)。

This is not completely possible with only one rsync command.仅使用一个 rsync 命令并不完全可以做到这一点。 If you only want to update the remote files, but do not want to add new files, you can use this command:如果您只想更新远程文件,但不想添加文件,可以使用以下命令:

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

This will not create new files or directories at all, but update differing ones.这根本不会创建新文件或目录,而是更新不同的文件或目录。

Edit : Maybe you could do something like this (assuming GNU find, if BSD/OS X: replace maxdepth with depth):编辑:也许你可以做这样的事情(假设 GNU 找到,如果 BSD/OS X:用深度替换 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

Warning : I have not tested this, you might want to add a "-n" to rsync (dry run) to see what happens.警告:我没有对此进行测试,您可能想在 rsync(试运行)中添加“-n”以查看会发生什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM