无法获取 rsync 排除选项来排除目录
rsync 出现问题。我使用 rsync 作为一个美化的 cp 命令。我在脚本中有以下代码。
rsync -aL --exclude /path/to/exclude/ --exclude='.*' /source/ /destination
我可以让 rsync 排除任何隐藏文件。因此 '.*'
我无法获取要排除的排除目录。我尝试过使用 '='
符号,用双引号和单引号将目录括起来。任何帮助将不胜感激。提前致谢。
Having an issues with rsync. I'm using rsync as a glorified cp command. I have in a script the following code.
rsync -aL --exclude /path/to/exclude/ --exclude='.*' /source/ /destination
I can get the rsync to exclude any hidden files. Hence the '.*'
I cannot get the exclude dir to exclude. I've tried using an '='
sign, surrounding the dir with double quotes, with single quotes. Any help would be greatly appreciated. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
实际上,既不是 Erik 的,也不是 Antoni 的答案是完全准确的。
埃里克说对了一半
排除模式的 root 确实是
test/a
(即模式/some/path
绑定到test/a/some/path
),但这还不是全部。从手册页:
我们可以忽略
per-directory
位,因为它在这里不适用于我们。因此,rsync -nvraL test/a test/dest --exclude=a/b/c/d 肯定会排除 test/a/b/c/d(和孩子),但它也会排除
test/a/other/place/a/b/c/d
。另一方面,
rsync -nvraL test/a test/dest --exclude=/b/c/d
将仅排除test/a/b /c/d
(和子级)(test/a
是/
锚定的点)。这就是为什么如果您想从备份中排除该特定路径,您仍然需要锚定首斜杠。这可能看起来像一个小细节,并且您的排除模式变得越具体(例如
Pictures
与home/daniel/Pictures
),但它可能会出现到处咬你屁股。Actually, neither Erik's nor Antoni's answer is fully accurate.
Erik is halfway right in saying that
It is true that the exclude pattern's root is
test/a
(i.e. the pattern/some/path
binds totest/a/some/path
), but that's not the whole story.From the man page:
We can ignore the
per-directory
bit as it doesn't apply to us here.Therefore,
rsync -nvraL test/a test/dest --exclude=a/b/c/d
will most definitely excludetest/a/b/c/d
(and children), but it'll also excludetest/a/other/place/a/b/c/d
.rsync -nvraL test/a test/dest --exclude=/b/c/d
, on the other hand, will exclude onlytest/a/b/c/d
(and children) (test/a
being the point to which/
is anchored).This is why you still need the anchoring inital slash if you want to exclude that specific path from being backed up. This might seem like a minor detail, and it will be so the more specific your exclude pattern becomes (e.g.
Pictures
vs.home/daniel/Pictures
) but it might just come around to bite you in the butt.这有效。由于
test/a
是同步的基本目录,因此排除模式是通过以a/
开头指定的。如果这没有帮助,请向我们显示真实的路径/排除。
使用 -vn 运行 rsync 将列出目录/文件 - 该模式与 rsync 打印的格式匹配。
This works. As
test/a
is the base directory synced from, the exclude pattern is specified by starting witha/
Show us the real paths/excludes if this doesn't help.
Running rsync with -vn will list dirs/files - the pattern is matched against the format that rsync prints.
按照埃里克的例子,你想这样做:
Following Erik's example you want to do this:
其中任何一个都可以工作:
请注意,源路径中的结尾
/
对指定--exclude
的方式有重要影响。这假设我们有:当排除路径以
/
开头时,原始帖子会遇到困难。 Daniel 的答案是正确的,排除路径中的初始/
可能需要排除特定路径,并且这个初始的/
应该被理解为正则表达式中的前导^
。然而,他的答案对于源路径中的结尾/
有一个严重的拼写错误。Either of these would work:
Note the ending
/
in source path makes a critical difference to how--exclude
should be specified. This assumes we have:Original Post has difficulty when exclude path starts with a
/
. Daniel’s answer is correct that this initial/
in exclude path might be desirable to exclude a specific path, and that this initial/
should be understood like leading^
in regular expressions. However, his answer has a critical typo about the ending/
in source path.如果要指定绝对路径,可以使用 realpath 将它们转换为相对路径:
If you want to specify absolute paths you can convert them to relative paths using realpath: