rsync的:--include-从与--exclude-从什么实际的区别呢? [英] rsync: --include-from vs. --exclude-from what is the actual difference?

查看:1155
本文介绍了rsync的:--include-从与--exclude-从什么实际的区别呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在文档中,它提到这些作为是包含两种模式的名单包括或模式,以排除文件。然而,这意味着夹杂物,都被认为是除了那里的东西相匹配模式的排斥。因此,例如,一个包括含有文件:

 的/ opt / **。CFG

应当只包含一个名为的任何文件*一个名为选择任何树,其中目录下的任何地方存在的.cfg。因此,这将匹配以下内容:

  /opt/etc/myfile.cfg
/some/dir/opt/myfile.cfg
/notopt/opt/some/other/dir/myfile.cfg

我因此希望它含蓄地排除别的。但是,这似乎并不如此,因为我看到这逐项输出:

  *删除等/ rc.d的/ init.d中/ somescript

那么,什么是包括地和排除,从这笔交易?他们只是为别名过滤器 - 从


解决方案

的rsync 不喜欢这项工作。与文件名模式的任何文件不匹配任何包含或排除模式被认为是包括在内。换句话说,认为包括图案覆盖排除模式的一种方式。

文档

Rsync的建立包括/命令行上指定排除选项的有序列表。 Rsync的检查,对每个每个文件和目录名排除/包括依次格局。第一个匹配模式采取行动。如果它是一个排除模式,则该文件将被跳过。如果它是一个包括图案,然后该文件名不跳过。 如果没有匹配的包括发现/排除模式则文件名不会被跳过。

(重点煤矿)

所以,如果你希望只包括特定的文件,你首先需要的排除的所有文件,然后的包括的这些文件,如:

   - * CFG包括=* /--include = --exclude =*

东西夫妇这里要注意:


  1. 包含模式要来的前排除,因为第一个匹配的模式是被考虑的之一。如果文件名的排除模式首先匹配,它就会被排除在外。


  2. 您需要或者包括所有子目录,分别,如 - 包括=/选择--include =/选择/ DIR1等。所有子目录,或使用--include =* /包括所有目录(而不是文件)。我去了简洁的第二个选项。


有古怪,不是很直观。所以阅读文档仔细(链接中的排除模式一节),并使用 - 干润 -n 选项,以确保它会做你认为它应该做的。

In the documentation, it mentions these as being files containing lists of either patterns to include or patterns to exclude. However, that implies for inclusions, everything is considered an exclusion except where things match patterns. So for example, an include file containing:

/opt/**.cfg

Should only include any file named *.cfg that exists anywhere under a directory named opt any where in the tree. So it would match the following:

/opt/etc/myfile.cfg
/some/dir/opt/myfile.cfg
/notopt/opt/some/other/dir/myfile.cfg

I'd therefore expect it to implicitly exclude anything else. But that doesn't seem to be the case, since I am seeing this in the itemized output:

*deleting   etc/rc.d/init.d/somescript

So what is the deal with include-from and exclude-from? Are they just aliases for filter-from?

解决方案

rsync doesn't work like that. Any file with a filename pattern that does not match any of the include or exclude patterns are considered to be included. In other words, think of the include pattern as a way of overriding exclude pattern.

From the docs:

Rsync builds an ordered list of include/exclude options as specified on the command line. Rsync checks each file and directory name against each exclude/include pattern in turn. The first matching pattern is acted on. If it is an exclude pattern, then that file is skipped. If it is an include pattern then that filename is not skipped. If no matching include/exclude pattern is found then the filename is not skipped.

(Emphasis mine)

So, if you want to include only specific files, you first need to exclude all files, and then include those files, like:

--include="*/" --include="*.cfg" --exclude="*"

Couple of things to note here:

  1. The include patterns have to come before the excludes, because the first pattern that matches is the one that gets considered. If the file name matches the exclude pattern first, it gets excluded.

  2. You need to either include all subdirectories individually, like --include="/opt" --include="/opt/dir1" etc. for all subdirectories, or use --include="*/" to include all directories (not files). I went with the second option for brevity.

It is quirky and not very intuitive. So read the docs carefully (the "EXCLUDE PATTERNS" section in the link) and use the --dry-run or -n option to make sure it is going to do what you think it should do.

这篇关于rsync的:--include-从与--exclude-从什么实际的区别呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆