我希望 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.
老问题,但我也有同样的问题..
您可以添加以下过滤器:
--filter="dir-merge,n- .rsync-exclude"
现在您可以将 .rsync-exclude 文件放置在任何文件夹中,并逐行写入要排除的文件和文件夹的名称。例如:
#.rsync-exclude file
folderYouWantToExclude
allFilesThatStartWithXY*
someSpecialImage.png
所以你也可以在那里使用模式。
你不能做的是:
#.rsync-exclude file
folder/someFileYouWantToExlude
希望有帮助!干杯
如果您不介意使用
tar
而不是纯粹的 rsync
,那么您可以使用 tar --exclude-tag=FILE
选项。这显然无法获得 rsync 的增量备份优势,因此它可能不完全是您正在寻找的。
tar cv --exclude-tag=.rsync-exclude ...
rsync -avz --exclude 'dir' /source /destination