2013-07-16 196 views
5

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

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

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

任何想法?

回答

4

rsync的不支持这一(至少在手册页并没有提及任何东西),但你可以做的两个步骤:

  1. 运行find找到.rsync-exclude文件
  2. 管这个名单--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. 
4

老问题,但我有同样的..

您可以添加以下过滤器:

--filter="dir-merge,n- .rsync-exclude" 

现在,您可以在任何文件夹中放置.rsync-exclude文件,并逐行写入要排除的文件和文件夹的名称。例如:

#.rsync-exclude file 

folderYouWantToExclude 
allFilesThatStartWithXY* 
someSpecialImage.png 

所以你也可以在那里使用模式。

什么,你不能做的是:

#.rsync-exclude file 

folder/someFileYouWantToExlude 

希望它能帮助!欢呼声

相关问题