Having an issues with rsync. I'm using rsync as a glorified cp command. I have in a script the following code.
遇到rsync问题。我正在使用rsync作为一个美化的cp命令。我在脚本中有以下代码。
rsync -aL --exclude /path/to/exclude/ --exclude='.*' /source/ /destination
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.
我可以让rsync排除任何隐藏文件。因此'。*'我无法排除排除目录。我尝试使用'='符号,用双引号围绕dir,用单引号。任何帮助将不胜感激。提前致谢。
3 个解决方案
#1
10
mkdir -p test/a/b/c/d/e
mkdir -p test/dest
rsync -nvraL test/a test/dest --exclude=a/b/c/d
This works. As test/a
is the base directory synced from, the exclude pattern is specified by starting with a/
这很有效。由于test / a是同步的基本目录,因此以/开头指定排除模式
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.
使用-vn运行rsync将列出目录/文件 - 模式与rsync打印的格式匹配。
#2
12
Actually, neither of these are fully accurate.
实际上,这些都不是完全准确的。
Erik is halfway right in saying that
Erik对此说得对
As test/a is the base directory synced from, the exclude pattern is specified by starting with a/
由于test / a是同步的基本目录,因此以/开头指定排除模式
It is true that the exclude pattern's root is test/a
(i.e. the pattern /some/path
binds to test/a/some/path
), but that's not the whole story.
确实,排除模式的根是test / a(即模式/ some / path绑定到test / a / some / path),但这不是整个故事。
From the man page:
从手册页:
if the pattern starts with a / then it is anchored to a particular spot in the hierarchy of files, otherwise it is matched against the end of the pathname. This is similar to a leading ^ in regular expressions. Thus "/foo" would match a file named "foo" at either the "root of the transfer" (for a global rule) or in the merge-file's directory (for a per-directory rule).
如果模式以/开头,则它将锚定到文件层次结构中的特定位置,否则将与路径名的末尾匹配。这类似于正则表达式中的前导^。因此,“/ foo”将匹配“传输的根”(对于全局规则)或在合并文件的目录(对于每个目录规则)中名为“foo”的文件。
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 exclude test/a/b/c/d
(and children), but it'll also exclude test/a/other/place/a/b/c/d
.
因此,rsync -nvraL test / a test / dest --exclude = a / b / c / d绝对会排除test / a / b / c / d(和孩子们),但它也会排除test / a /其它/地点/ A / b / C / d。
rsync -nvraL test/a test/dest --exclude=/b/c/d
, on the other hand, will exclude only test/a/b/c/d
(and children) (test/a
being the point to which /
is anchored).
rsync -nvraL test / a test / dest --exclude = / b / c / d,另一方面,只排除test / a / b / c / d(和孩子)(test / a是指向哪个/是锚定的)。
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.
这就是为什么如果要从备份中排除特定路径,仍需要锚定初始斜杠。这可能看起来像一个小细节,它会更加具体你的排除模式(例如图片与家庭/丹尼尔/图片),但它可能只是来咬你的屁股。
#3
2
Following Erik's example you want to do this:
按照Erik的例子,你想要这样做:
rsync -nvraL test/a/ test/dest --exclude=/b/c/d
#1
10
mkdir -p test/a/b/c/d/e
mkdir -p test/dest
rsync -nvraL test/a test/dest --exclude=a/b/c/d
This works. As test/a
is the base directory synced from, the exclude pattern is specified by starting with a/
这很有效。由于test / a是同步的基本目录,因此以/开头指定排除模式
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.
使用-vn运行rsync将列出目录/文件 - 模式与rsync打印的格式匹配。
#2
12
Actually, neither of these are fully accurate.
实际上,这些都不是完全准确的。
Erik is halfway right in saying that
Erik对此说得对
As test/a is the base directory synced from, the exclude pattern is specified by starting with a/
由于test / a是同步的基本目录,因此以/开头指定排除模式
It is true that the exclude pattern's root is test/a
(i.e. the pattern /some/path
binds to test/a/some/path
), but that's not the whole story.
确实,排除模式的根是test / a(即模式/ some / path绑定到test / a / some / path),但这不是整个故事。
From the man page:
从手册页:
if the pattern starts with a / then it is anchored to a particular spot in the hierarchy of files, otherwise it is matched against the end of the pathname. This is similar to a leading ^ in regular expressions. Thus "/foo" would match a file named "foo" at either the "root of the transfer" (for a global rule) or in the merge-file's directory (for a per-directory rule).
如果模式以/开头,则它将锚定到文件层次结构中的特定位置,否则将与路径名的末尾匹配。这类似于正则表达式中的前导^。因此,“/ foo”将匹配“传输的根”(对于全局规则)或在合并文件的目录(对于每个目录规则)中名为“foo”的文件。
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 exclude test/a/b/c/d
(and children), but it'll also exclude test/a/other/place/a/b/c/d
.
因此,rsync -nvraL test / a test / dest --exclude = a / b / c / d绝对会排除test / a / b / c / d(和孩子们),但它也会排除test / a /其它/地点/ A / b / C / d。
rsync -nvraL test/a test/dest --exclude=/b/c/d
, on the other hand, will exclude only test/a/b/c/d
(and children) (test/a
being the point to which /
is anchored).
rsync -nvraL test / a test / dest --exclude = / b / c / d,另一方面,只排除test / a / b / c / d(和孩子)(test / a是指向哪个/是锚定的)。
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.
这就是为什么如果要从备份中排除特定路径,仍需要锚定初始斜杠。这可能看起来像一个小细节,它会更加具体你的排除模式(例如图片与家庭/丹尼尔/图片),但它可能只是来咬你的屁股。
#3
2
Following Erik's example you want to do this:
按照Erik的例子,你想要这样做:
rsync -nvraL test/a/ test/dest --exclude=/b/c/d