代码之家  ›  专栏  ›  技术社区  ›  Nick Bull

rSyc忽略以斜线结尾的文件夹。

  •  1
  • Nick Bull  · 技术社区  · 8 年前

    我在一个名为“/rsync/include.txt”的文件中有以下内容

    + /home/**
    + /opt**
    - *
    

    然后我打电话给 rsync 命令如下:

    rsync -avr --include-from="/rsync/include.txt" . ../backup
    

    这将产生以下输出:

    sending incremental file list
    created directory ../archive
    ./
    opt/
    opt/some-file
    opt/include-me/
    opt/include-me/me-too
    opt/include-me/and-me/
    
    sent 299 bytes  received 106 bytes  810.00 bytes/sec
    total size is 0  speedup is 0.00
    

    这个 /home 目录存在,并包含文件。

    为什么 + /home/** 模式不起作用?我不想使用 + /home** 模式,因为它可以匹配其他文件夹名称,例如, /homeopathy 是的。

    有谁能帮我理解为什么这个命令不起作用,并指出我的方向的工作命令?

    编辑 :虽然我还想回答这个问题,但我真诚地建议使用 rdiff-backup 因为它使用相似的过滤文件和模式,但实际上更容易使用。我今天花了很多时间在这个问题上 远程同步 ,在几分钟内使用 RDIFF备份 .

    1 回复  |  直到 8 年前
        1
  •  1
  •   rkta    8 年前

    一般调试信息

    最简单的方法是使用 -vv (将详细程度增加两次)与 -n (干运行)。

    使用double verbosity,您将看到哪个模式导致忽略哪个文件。 你可以 grep 输出只能看到相关部分。

    例子

    %  rsync -avv --include 'opt/1' --exclude 'opt/*' -n ./ /tmp  \
        | grep '\[sender\]'
    [sender] showing directory opt/1 because of pattern opt/1
    [sender] hiding directory opt/2 because of pattern opt/*
    [sender] hiding directory opt/3 because of pattern opt/*
    

    具体答案

    你的例子失败了,因为 + /home/** 被排除在外 - * 是的。

    man rsync 国家:

    注意,当使用--recursive(-r)选项(由-a暗示)时,从左到右访问每个路径的每个subdir组件,每个目录在其内容之前都有机会被排除。

    所以模式 /home/** 后评价 /home 被穿越,但这永远不会发生,因为 -* 排除 /家 是的。

    包括 /home/ 你只需要插入之前 /家/** ,因此排除文件变为:

    + /home/
    + /home/**
    + /opt/
    + /opt/**
    - *