rsync 失败并出现令人困惑的错误消息

rsync 失败并出现令人困惑的错误消息

在 bash 脚本(Arch Linux)中,我有以下 rsync 命令:

rsync –nvaAHX --inplace --delete-delay --exclude-from="/etc/$path1/exclude-list-$configName.txt" "$new_snap/" "$BACKUPDIR"

rsync 命令失败并出现以下错误:

rsync: --delete does not work without --recursive (-r) or --dirs (-d).

当然,该消息具有误导性,因为“a”意味着“r”。

如果我从 rsync 命令中删除选项“--delete-delay”,则会收到以下不同的错误:

rsync: link_stat "/some/path/–aAHX" failed: No such file or directory (2)

“/some/path”中显示的值是当前工作目录。如果我更改当前目录,错误消息中的值也会更改。然而,为什么选项“-aAHX”会被附加到路径的任何部分是令人困惑的。

该计算机是完全更新的 Arch Linux 系统。我也刚刚重新启动它。

4.13.11-1-ARCH #1 SMP PREEMPT Thu Nov 2 10:25:56 CET 2017 x86_64 GNU/Linux

rsync程序位置:

# which rsync
/usr/bin/rsync

这是测试脚本:

#!/bin/bash

path1=xyz
configName=root
new_snap=/.snapshots/1/snapshot
BACKUPDIR=/backup/$configName

echo "showing exclude file contents:"

cat "/etc/$path1/exclude-list-$configName.txt"

echo

echo rsync –nvaAHX --inplace --delete-delay --exclude-from="/etc/$path1/exclude-list-$configName.txt" "$new_snap/" "$BACKUPDIR"

rsync –nvaAHX --inplace --delete-delay --exclude-from="/etc/$path1/exclude-list-$configName.txt" "$new_snap/" "$BACKUPDIR"

以下是文件“/etc/$path/exclude-list-$configName.txt”的内容:

"dev/*"
"proc/*"
"sys/*"
"tmp/*"
"run/*"
"mnt/*"
"media/*"
"lost+found"
".trash*/*"
".Trash*/*"

这是一些完全没有任何脚本的测试。我觉得这很令人困惑。

# mkdir adir
# mkdir bdir
# touch adir/afile1
# touch adir/afile2

# ls -la adir/
total 0
drwxr-x--x 1 root root           24 Nov 12 02:21 .
drwxr-xr-x 1 user user         2080 Nov 12 02:28 ..
-rw-r----- 1 root root            0 Nov 12 02:21 afile1
-rw-r----- 1 root root            0 Nov 12 02:21 afile2
# ls -la bdir/
total 0
drwxr-x--x 1 root root            0 Nov 12 02:21 .
drwxr-xr-x 1 user user         2080 Nov 12 02:28 ..


# rsync -nva adir/ bdir
sending incremental file list
./
afile1
afile2

sent 93 bytes  received 25 bytes  236.00 bytes/sec
total size is 0  speedup is 0.00 (DRY RUN)

# rsync -nva /home/user/adir/ /home/user/bdir
sending incremental file list
./
afile1
afile2

sent 93 bytes  received 25 bytes  236.00 bytes/sec
total size is 0  speedup is 0.00 (DRY RUN)


# rsync –nvaAHX --inplace --delete-delay --exclude-from=/root/exclude-list-root.txt /home/user/adir/ /home/user/bdir/
rsync: --delete does not work without --recursive (-r) or --dirs (-d).
rsync error: syntax or usage error (code 1) at main.c(1567) [client=3.1.2]
# rsync –nvaAHX --inplace --delete-delay /home/user/adir/ /home/user/bdir/
rsync: --delete does not work without --recursive (-r) or --dirs (-d).
rsync error: syntax or usage error (code 1) at main.c(1567) [client=3.1.2]
# rsync –nvaAHX --inplace /home/user/adir/ /home/user/bdir/
rsync: link_stat "/home/user/–nvaAHX" failed: No such file or directory (2)
skipping directory .
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1178) [sender=3.1.2]
# rsync –nvaAHX /home/user/adir/ /home/user/bdir/
rsync: link_stat "/home/user/–nvaAHX" failed: No such file or directory (2)
skipping directory .
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1178) [sender=3.1.2]
# rsync –nva /home/user/adir/ /home/user/bdir/
rsync: link_stat "/home/user/–nva" failed: No such file or directory (2)
skipping directory .
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1178) [sender=3.1.2]

答案1

nin前面的破折号–nvaHAX不是普通的破折号,而是稍长的长破折号(或连字符)。

如果您从“智能”编辑器或文字处理程序复制并粘贴并用相应的印刷字符替换某些字符,则可能会发生这种情况。

在我的系统上,复制并粘贴命令的第一部分会导致:

$ rsync –nva adir/ bdir/              
rsync: link_stat "/tmp_mfs/shell-ksh.D1Mq1Xht/\#342\#200\#223nva" failed: No such file or directory (2)
skipping directory .
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1178) [sender=3.1.2]

正如您所看到的,我的终端显示的错误消息与您的略有不同,并显示破折号实际上是 Unicode 字符(或类似的字符,我对字符编码不太了解)。

答案2

整个奇怪的问题是由 rsync 选项前面的字符引起的。有问题的角色是这个(我不知道它是如何到达那里的):


# printf – | od -An -vtu1
226 128 147

正确的字符是这个字符,一个标准的破折号(减号):

-
# printf - | od -An -vtu1
45

相关内容