我有一个 rsync 命令,多年来一直用它来备份智能手机中的照片。它运行正常,除非我切换--exclude *2021*
到--exclude *2020*
在我的真实场景中,错误消息是
意外的本地 arg:/media/sciuro/BCKP_WD4T/Fotos/2021/CELULAR/ 如果 arg 是远程文件/目录,请在其前面加上冒号 (:)。 rsync 错误:main.c(1375) 处的语法或使用错误(代码 1)[Receiver=3.1.2]
在我的测试场景中,错误消息是
rsync:change_dir“/home/sciuro//home/sciuro/2021”失败:没有这样的文件或目录(2)错误:复制多个文件时目标必须是目录rsync错误:选择输入/输出文件、目录时出错(代码 3)位于 main.c(641) [Receiver=3.1.2]
这些错误仅在--exclude *2020*
独立于源和目标文件/目录的情况下发生。请看下面我的测试场景。
任何人都可以向我解释一下这里到底有什么问题吗?
解决方法是在以下之间插入模式'
:--exclude '*2020*'
我猜测 rsync 有一些内部2020
或20
编码正在被解释并导致此错误。
真实场景
这样运行没有报错
rsync -rtpogvlHbis --ignore-existing --progress --size-only --stats rsync://localhost:6010/root/sdcard/DCIM/Camera/ /media/sciuro/BCKP_WD4T/Fotos/2020/CELULAR/ -n --exclude *2021*
receiving incremental file list
.d...p..... ./
>f+++++++++ IMG_20201228_114334605.jpg
(...)
Number of files: 78 (reg: 77, dir: 1)
Number of created files: 77 (reg: 77)
Number of deleted files: 0
Number of regular files transferred: 77
Total file size: 4,191,721,673 bytes
Total transferred file size: 4,191,721,673 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 1,898
File list generation time: 0.013 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 270
Total bytes received: 2,147
sent 270 bytes received 2,147 bytes 4,834.00 bytes/sec
total size is 4,191,721,673 speedup is 1,734,266.31 (DRY RUN)
这不
rsync -rtpogvlHbis --ignore-existing --progress --size-only --stats rsync://localhost:6010/root/sdcard/DCIM/Camera/ /media/sciuro/BCKP_WD4T/Fotos/2021/CELULAR/ -n --exclude *2020*
Unexpected local arg: /media/sciuro/BCKP_WD4T/Fotos/2021/CELULAR/
If arg is a remote file/dir, prefix it with a colon (:).
rsync error: syntax or usage error (code 1) at main.c(1375) [Receiver=3.1.2]
测试场景
这是一个最小的测试。
源目录和文件(目标目录为空)
sciuro@toca:~$ ls test/origin/
Captura de tela de 2020-02-10 21-48-32.png
Captura de tela de 2020-04-02 21-14-44.png
Captura de tela de 2021-01-16 13-48-26.png
Captura de tela de 2021-01-16 13-48-27.png
1°测试:目的地home/sciuro/2020/
+--exclude *2021*
sciuro@toca:~$ rsync -rv /home/sciuro/test/origin/ home/sciuro/2020/ --exclude *2021* -n
sending incremental file list
created directory home/sciuro/2020
./
Captura de tela de 2020-02-10 21-48-32.png
Captura de tela de 2020-04-02 21-14-44.png
sent 144 bytes received 64 bytes 416.00 bytes/sec
total size is 2,443,343 speedup is 11,746.84 (DRY RUN)
2° 测试 [失败]:目的地home/sciuro/2021/
+--exclude *2020*
sciuro@toca:~$ rsync -rv /home/sciuro/test/origin/ home/sciuro/2021/ --exclude *2020* -n
sending incremental file list
rsync: change_dir "/home/sciuro//home/sciuro/2021" failed: No such file or directory (2)
ERROR: destination must be a directory when copying more than 1 file
rsync error: errors selecting input/output files, dirs (code 3) at main.c(641) [Receiver=3.1.2]
3°测试:目的地home/sciuro/2021/
+--exclude *2021*
sciuro@toca:~$ rsync -rv /home/sciuro/test/origin/ home/sciuro/2021/ --exclude *2021* -n
sending incremental file list
created directory home/sciuro/2021
./
Captura de tela de 2020-02-10 21-48-32.png
Captura de tela de 2020-04-02 21-14-44.png
sent 144 bytes received 64 bytes 416.00 bytes/sec
total size is 2,443,343 speedup is 11,746.84 (DRY RUN)
4° 测试 [失败]:目的地home/sciuro/2020/
+--exclude *2020*
sciuro@toca:~$ rsync -rv /home/sciuro/test/origin/ home/sciuro/2020/ --exclude *2020* -n
sending incremental file list
rsync: change_dir "/home/sciuro//home/sciuro/2020" failed: No such file or directory (2)
ERROR: destination must be a directory when copying more than 1 file
rsync error: errors selecting input/output files, dirs (code 3) at main.c(641) [Receiver=3.1.2]
解决方法
sciuro@toca:~$ rsync -rv /home/sciuro/test/origin/ home/sciuro/2021/ --exclude '*2020*' -n
sending incremental file list
created directory home/sciuro/2021
./
Captura de tela de 2021-01-16 13-48-26.png
Captura de tela de 2021-01-16 13-48-27.png
sent 133 bytes received 64 bytes 394.00 bytes/sec
total size is 2,057,301 speedup is 10,443.15 (DRY RUN)
答案1
您需要引用 的参数--exclude
,否则它将在发出主机上扩展,从而导致传递与相对于工作目录的 glob 匹配的本地文件(例如,/media/sciuro/BCKP_WD4T/Fotos/2021/CELULAR/
在您的“真实”场景中)。
rsync -rtpogvlHbis --ignore-existing --progress --size-only --stats rsync://localhost:6010/root/sdcard/DCIM/Camera/ /media/sciuro/BCKP_WD4T/Fotos/2020/CELULAR/ -n --exclude '*2021*'