rsync - 使 rsync 排除包含具有特定名称的文件的所有目录

标签 rsync data-synchronization

我希望 rsync 排除所有包含具有特定名称的文件的目录,比如“.rsync-exclude”,独立于“.rsync-exclude”文件的内容。

如果文件“.rsync-exclude”只包含“*”,我可以使用 rsync -r SRC DEST --filter='dir-merge,- .rsync-exclude' .

但是,应该独立于“.rsync-exclude”文件的内容排除该目录(至少应该可以将“.rsync-exclude”文件留空)。

有任何想法吗?

最佳答案

rsync 不支持这一点(至少手册页没有提到任何内容),但您可以分两步完成:

  • 运行 find找到 .rsync-exclude文件
  • 将此列表通过管道发送至 --exclude-from (或使用临时文件)
       --exclude-from=FILE
          This option is related to the --exclude option, but it specifies a FILE that contains exclude  patterns
          (one per line).  Blank lines in the file and lines starting with ';' or '#' are ignored.  If FILE is -,
          the list will be read from standard input.
    

  • 或者,如果您不介意在文件中放一些东西,您可以使用:
           -F     The -F option is a shorthand for adding two --filter rules to your command.  The first time it is  used
              is a shorthand for this rule:
    
                 --filter='dir-merge /.rsync-filter'
    
              This  tells  rsync  to  look for per-directory .rsync-filter files that have been sprinkled through the
              hierarchy and use their rules to filter the files in the transfer.  If -F is repeated, it is  a  short-
              hand for this rule:
    
                 --filter='exclude .rsync-filter'
    
              This filters out the .rsync-filter files themselves from the transfer.
    
              See the FILTER RULES section for detailed information on how these options work.
    

    关于rsync - 使 rsync 排除包含具有特定名称的文件的所有目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17681976/

    相关文章:

    rsync - 当 uid/gid 不同时,rsync 如何保留所有权?

    linux - rsync 无法将文件从服务器 A 同步到服务器 B。服务器 B 正在运行 rsync 守护进程

    ubuntu - 什么用户在启动新的 ubuntu EC2 实例时运行用户数据脚本?

    iphone - 移动端和网络服务器之间的数据同步

    docker - 如何在不增加存储空间的情况下复制具有overlayfs目录结构的数据*原样*的/var/lib/docker

    macos - 为什么我的 rsync 脚本每次都会进行完整备份?

    algorithm - 在面向消费者的应用程序中同步数据时如何处理冲突?

    python - 将外部源的数据同步到 django 项目中使用的数据库?

    sql-server - 单向数据库同步

    database - CAP 定理 - 异步写入和一致性