Rsync

rsync exclude 2021 有效,但不是 2020

  • February 5, 2021

我有這個 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)錯誤:複製超過1個文件時目標必須是目錄rsync錯誤:選擇輸入/輸出文件時出錯,目錄(程式碼 3)在 main.c(641)

$$ Receiver=3.1.2 $$

這些錯誤僅發生在--exclude *2020*獨立於源文件和目標文件/目錄的情況下。請在下面查看我的測試場景。

任何人都可以向我解釋這裡到底是什麼問題?

解決方法是在 之間插入模式'--exclude '*2020*'

我猜 rsync 有一些內部202020編碼正在被解釋並導致此錯誤。


真實場景

這個執行沒有錯誤

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°測試

$$ 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]

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°測試

$$ 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]

解決方法

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)

您需要將參數引用到--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*'

引用自:https://unix.stackexchange.com/questions/632734