我试图排除一个目录树作为一个embedded在bash脚本中的rsync命令的一部分,大概是这样的:
$OPTIONS="-rl --exclude 'Some Parent Directory/Another Directory'" rsync $OPTIONS $SOURCEDIR [email protected]:/SomeTargetDir
我的目标是将所有$SOURCEDIR同步到目标机器上的/SomeTargetDir ,除了Some Parent Directory/Another Directory下的所有内容。 但是,我不断看到这种forms的错误:
rsync: link_stat "/Users/myusername/Parent\" failed: No such file or directory (2)
我认为这是与逃避排除path有关,但我似乎无法做到正确:我尝试的\\ , \等等的每个组合似乎都不正确。 如何正确编写排除规则?
除非我绝对必须,否则我不想使用--exclude-from 。
我在OS X 10.8上使用rsync 3.0.9,通过SSH同步到Ubuntu 12.04。
使用--exclude-from 。 排除文件将在新行中包含所有模式,您可以忘记引号,转义和空间问题。
我有一个类似你的脚本,这就是我所做的。 请注意,使用此解决scheme,我在脚本中生成排除文件,因此我仍然必须确保引号是正确的。 如果你可以有一个静态排除文件,那将更加简单。
# create a temporary file RSYNC_EXCLUDES=$( mktemp -t rsync-excludes ) # remove the temp file when the script exits trap "rm -f $RSYNC_EXCLUDES" EXIT # populate the exclusion file echo 'Some Parent Directory/Another Directory' > "$RSYNC_EXCLUDES" # have your options point to your exclusion file $OPTIONS="-rl --exclude-from='$RSYNC_EXCLUDES'" # profit rsync $OPTIONS $SOURCEDIR [email protected]:/SomeTargetDir
排除匹配模式。 所以试试像这样:
$OPTIONS="-rl --exclude '*/Another Directory'" rsync $OPTIONS $SOURCEDIR [email protected]:/SomeTargetDir
请参阅本教程以获取更多详细信
另一个build议是尝试转义双引号而不是使用单引号:
$OPTIONS="-rl --exclude \"Some Parent\ Directory/Another\ Directory\""
OP尝试了这个select,但在他的情况下,他仍然没有为他工作。 它使用rsync “3.0.8协议版本30”在Linux上工作。