1

I have this rsync command that I use for years to backup photos from my smartphone. It runs normally except if I swap --exclude *2021* to --exclude *2020*

In my real scenario, the error message is

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]

And in my test scenario, the error message is

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]

These errors only happens with --exclude *2020* independently of source and destination files/directories. Please have a look at my test scenario bellow.

Anybody can explain me what's exactly is the problem here?

The workaround was to insert the pattern between ': --exclude '*2020*'

I'm guessing that rsync has some internal 2020 or 20 encode that is being interpreted and leding to this error.


Real scenario

This run without error

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)

This doesn't

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]

Test scenario

Here is a minimal test.

Origin dir and files (destination dir are empty)

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° test: destination 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° test [FAIL]: destination 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° test: destination 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° test [FAIL]: destination 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]

The workaround

 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)
9

You need to quote the argument to --exclude, otherwise it will be expanded on the issuing host, resulting in passing local files which match that glob relative to the working directory (eg. /media/sciuro/BCKP_WD4T/Fotos/2021/CELULAR/ in your "real" scenario).

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*'
3
  • Hi Chris! I think I understood what you explained, but it's not clear to me why --exclude *2021* with dir/2020/dir/` and dir/2021/dir/ runs without error, while --exclude *2020* with dir/2020/dir/` and dir/2021/dir/ fails ? In both case with files named with 2020 and 2021 in origin directory. – Camilla Feb 5 at 22:53
  • @Camilla show the output of echo *2020* and echo *2021* as without the quotes, that is what is being sent to rsync. Probably there are multiple matches for 2020 and they are being interpreted as (unknown) rsync options. – BowlOfRed Feb 6 at 0:45
  • @Camilla If *2020* doesn't match anything in your local working directly, it will be sent literally. More than likely either that's happening, or it's expanding to something that happens to coincidentally have the effect you're looking for. – Chris Down Feb 6 at 3:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.