• rsync --include-from --exclude-from的理解


    rsync --include-from --exclude-from的理解:
    1、同时添加--include-from --exclude-from时。后者是对前者的结果进行排除
    如:“--include-from include.txt --include-from exclude.txt” #也就是说绝对不会超过--include-from声明的范围
    2、--include-from 文件前面的符号是有效的有意义的
    3、--exclude-from 文件前面不管是什么符号、有没有符号都是排除的意思

    4、每一个目录、子目录、文件都会与这个过滤规则列表进行匹配,直到找到一个命中的(命中的规则说要过滤就过滤,要包含那就包含),

    5、最重要的一个原则:只找第一个匹配的规则

     以下是原文,我把关键词标出来方便阅读:

    FILTER RULES

    The filter rules allow for flexible selection of which files to transfer (include) and which files to skip (exclude). The rules either directly specify include/exclude patterns or they specify a way to acquire more include/exclude patterns (e.g. to read them from a file).

    As the list of files/directories to transfer is built, rsync checks each name to be transferred against the list of include/exclude patterns in turn, and 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 pattern is found, then the filename is not skipped.

    Rsync builds an ordered list of filter rules as specified on the command-line.

    以下是一个实例后面添加对相关过滤规则的说明和理解

    #############################################################################
    ### include.txt:
    # CompanyAttachment Files
    # 限制所有目录只包含2019开头的
    - ETest/20191/ #如果非要排除 ETest/20191下的文件 这个排除规则应该放前面。每个路径只找第一个匹配的规则 (只找第一个、只找第一个、只找第一个 这很重要,理解了这个原则,才能理解所有的规则)
    + 2019*/ #这个只是包含了目录,目录下的文件不会同步
    + 2019*/** #这个只包含了目录下的文件,如果没有上面的这个也无效
    + ETest/ #这个只是包含了目录 但是子目录如果符合上面的其它条件也会被同步(如ETest目录下有2019开头的文件夹,也会同步)
    - * #排除其它文件
    - *.tmp #排除所有的.tmp文件。这是个错误的示例,这个不一定会排除所有目录的.tmp文件。因为有些路径会命中前面的规则就直接返回了。这个排除规则要么写到最前面,要么写到exclude.txt里去
    #############################################################################
    #############################################################################
    # exclude.txt
    *.tmp #exclude-from文件里不管前面加不加+、-号都是排除(测试+号、-号、不要符号结果是一样的,很奇怪,但测试结果是这样,不知道我是不是理解错误)
    #* #exclude-from 是对include-from的结果进行排除,所以不能加这个。这个相当于禁用同步了。
    #############################################################################

     总结一下:

    1、顺序很重要,重要的、命中范围小的写前面

    2、最重要的还是理解它的过滤逻辑:每一个目录、子目录、文件都会与这个过滤规则列表进行匹配,直到找到一个命中的(命中的规则说要过滤就过滤,要包含那就包含),

  • 相关阅读:
    redis--列表
    redis ——字符串
    redis 第一节 redis安装、PHP扩展 、主从
    Python--day7
    Python--day6
    Python爬虫
    JSON基础
    Python--day5
    Python—day3
    Windows10 安装QT问题
  • 原文地址:https://www.cnblogs.com/heys/p/10335359.html
Copyright © 2020-2023  润新知