1 rsync
我有这个 rsync 命令,多年来我一直使用它来备份智能手机中的照片。它运行正常,除非我切换--exclude *2021*
到--exclude *2020*
在我的真实场景中,错误消息是
意外的本地 arg:/media/sciuro/BCKP_WD4T/Fotos/2021/CELULAR/ 如果 arg 是远程文件/目录,请在其前面加上冒号 (:)。rsync 错误:main.c(1375) [Receiver=3.1.2] 处的语法或使用错误(代码 1)
在我的测试场景中,错误消息是
rsync: change_dir "/home/sciuro//home/sciuro/2021" failed: No such file or directory (2) 错误:复制超过 1 个文件时目标必须是目录 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)
Run Code Online (Sandbox Code Playgroud)
这不
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]
Run Code Online (Sandbox Code Playgroud)
这是一个最小的测试。
源目录和文件(目标目录为空)
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
Run Code Online (Sandbox Code Playgroud)
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)
Run Code Online (Sandbox Code Playgroud)
2° 测试 [FAIL]:目的地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]
Run Code Online (Sandbox Code Playgroud)
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)
Run Code Online (Sandbox Code Playgroud)
4° 测试 [FAIL]:目的地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]
Run Code Online (Sandbox Code Playgroud)
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)
Run Code Online (Sandbox Code Playgroud)
Chr*_*own 10
您需要将参数引用到--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*'
Run Code Online (Sandbox Code Playgroud)