2

I am trying to exclude the #recycle directory with rsync:

$ rsync -Hauv -h -P --exclude '#recycle/' --exclude @eaDir/ --exclude '.DS_Store*' --exclude desktop.ini  user1@src_server:/volume2/Extension_1 /destination/dir/
receiving incremental file list
Extension_1/#recycle/subDir1/subDir2/
Extension_1/#recycle/subDir1/subDir2/BigVideo.mov
         39.23G  82%   36.40MB/s    0:03:44  ^C
$

(I also tried quoting .DS_Store* and removing the --log-file option, but they made no difference.)

I am using rsync version 3.1.2 protocol version 31 on CentOS 7.9 with bash version 4.2.46(2)-release.

To be more specific, I wrote a very small script with a variable that contains the exclusion list

$ rsyncExclusionOptions=$(printf -- "--exclude %s " "'#recycle/'" @eaDir/ "'.DS_Store*'" desktop.ini)
$ echo $rsyncExclusionOptions
--exclude '*/#recycle/' --exclude @eaDir/ --exclude '.DS_Store*' --exclude desktop.ini
$ rsync -Hauv -h -P --skip-compress=$rsyncSkipCompressList $rsyncExclusionOptions user1@src_server:/volume2/Extension_1 /destination/dir/
receiving incremental file list
Extension_1/#recycle/SERIES/mySerie/SOURCES_HD59iDF/EPISODES_666-709/
Extension_1/#recycle/SERIES/mySerie/SOURCES_HD59iDF/EPISODES_666-709/TOEI_myEpisode.mov
          3.22G   5%  104.35MB/s    0:08:23  ^CKilled by signal 2.

rsync error: unexplained error (code 255) at rsync.c(638) [generator=3.1.2]
rsync: [generator] write error: Broken pipe (32)
rsync error: received SIGUSR1 (code 19) at main.c(1430) [receiver=3.1.2]

EDIT0 : @roaima I also tried putting # between brackets (as suggested in the link you provided here) but it did not work either :

$ rsyncExclusionOptions=$(printf -- "--exclude %s " "'[#]recycle/'" @eaDir/ "'.DS_Store*'" desktop.ini)
$ echo $rsyncExclusionOptions
--exclude '[#]recycle/' --exclude @eaDir/ --exclude '.DS_Store*' --exclude desktop.ini
$ rsync -Hauv -h -P --skip-compress=$rsyncSkipCompressList $rsyncExclusionOptions user1@src_server:/volume2/Extension_1 /destination/dir/
receiving incremental file list
Extension_1/#recycle/SERIES/mySerie/SOURCES_HD59iDF/EPISODES_666-709/
Extension_1/#recycle/SERIES/mySerie/SOURCES_HD59iDF/EPISODES_666-709/TOEI_myEpisode.mov
          4.04G   7%   21.67MB/s    0:39:45  ^CKilled by signal 2.

rsync error: unexplained error (code 255) at rsync.c(638) [generator=3.1.2]
rsync: [generator] write error: Broken pipe (32)
rsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at io.c(504) [receiver=3.1.2]
rsync: [receiver] write error: Broken pipe (32)

A WORKING SOLUTION :

  • The hash had be put between brackets like this : [#] AND
  • The extra ' must not be used for the [#]recycle exclusion inside the rsyncExclusionOptions variable :
$ rsyncExclusionOptions=$(printf -- "--exclude %s " "[#]recycle/" @eaDir/ "'.DS_Store*'" desktop.ini)
$ echo $rsyncExclusionOptions
--exclude [#]recycle/ --exclude @eaDir/ --exclude '.DS_Store*' --exclude desktop.ini
$ rsync -Hauv -h -P --skip-compress=$rsyncSkipCompressList $rsyncExclusionOptions user1@src_server:/volume2/Extension_1 /destination/dir/
receiving incremental file list
Extension_1/SERIES/mySerie/SOURCES_VF/EPISODES_700-765/
5
  • The second part is very much a quoting issue. You can't do that Commented Sep 21, 2022 at 17:17
  • Thanks for the edit, but it's still a bit confusing. If you have rsyncExclusionOptions=$(printf -- "--exclude %s " "'#recycle/'" ...), then why is echo $rsyncExclusionOptions returning --exclude '*/#recycle/'? Where is the */ coming from?
    – terdon
    Commented Sep 21, 2022 at 17:26
  • Notice those single quotes are part of the filename to be matched for exclusion Commented Sep 21, 2022 at 17:57
  • @terdon That's because I was trying something in the meantime. I fixed it in the question.
    – SebMa
    Commented Sep 22, 2022 at 7:36
  • Your final one is using unquoted patterns, which the shell will try to glob match. The previous one didn't work because you put quote characters into the unquoted patterns. Commented Sep 22, 2022 at 10:11

1 Answer 1

2

I'm going to answer this to say that with rsync version 3.1.3 protocol 31 I cannot reproduce the issue as ORIGINALLY described. (Raspbian GNU/Linux 10 "buster".)

The modified question shows that the exclusion list is incorrect and will not match the directory names. You've put single quotes into the pattern names, and these do not match the directory/file names. Consequently they will not be excluded.

Original answer continues below.


However, I see that there is another unresolved instance reported on StackOverflow of file names containing # causing problems - see rsync fails to exclude '#filename#' file names, so you're not alone. Maybe it was fixed with the later version I'm running?

Scenario

mkdir -p /tmp/718113/Extension_1/#recycle/subDir1/subDir2
cd /tmp/718113
mkdir dst
touch Extension_1/#recycle/subDir1/subDir2/BigVideo.mov

Now the command

rsync -Hauv -h -P --exclude '#recycle/' --exclude '@eaDir/' --exclude '.DS_Store*' --exclude 'desktop.ini' localhost:/tmp/718113/Extension_1 /tmp/718113/dst

Output

receiving incremental file list
Extension_1/

sent 85 bytes  received 78 bytes  326.00 bytes/sec
total size is 0  speedup is 0.00

The only significant change is that I have quoted the exclusion patterns so that the shell has no opportunity to expand them (specifically but not exclusively '.DS_Store*'). However, if this had been an issue in this case you would have received error messages from rsync such as Unexpected remote arg: localhost:/tmp/718113/Extension_1 and rsync error: syntax or usage error (code 1) at main.c(1372) [sender=3.1.3].

I would also recommend against using --progress (implied with -P) and then redirecting stdout/stderr to a log file. Either replace -P with --partial or use the --log option to write results to the log file.

8
  • Even without quoting .DS_Store*, your rsync command has the same behaviour. I still don't understand why my command does not work.
    – SebMa
    Commented Sep 21, 2022 at 16:14
  • @SebMa please edit your question and tell us i) your operating system, ii) your rsync version (rsync --version; although I doubt this will be relevant, you never know) and also clarify if it happens with other directory names or only those whose names start with #.
    – terdon
    Commented Sep 21, 2022 at 16:15
  • @roaima I wrote the shell version in my EDIT1.
    – SebMa
    Commented Sep 21, 2022 at 16:35
  • @roaima On the remote, it is bash version 4.4.23(1)-release.
    – SebMa
    Commented Sep 21, 2022 at 16:42
  • @roaima If you take a look at the echo $rsyncExclusionOptions I just added, it seems the value of that variable is fine.
    – SebMa
    Commented Sep 21, 2022 at 16:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .