• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Question Rsync exclude patterns – required to use wildcards with folder names?

King555

Regular Pleskian
Just a short question, maybe someone has an answer for me. I backup my server using "Rsync".

Why does this command exclude nothing:

Code:
rsync -a  --exclude={"/boot/lost+found/","/dev/"} -e 'ssh -p23' / [email protected]:/backup/

while this excludes the files within the two folders as desired?

Code:
rsync -a  --exclude={"/boot/lost+found/*","/dev/*"} -e 'ssh -p23' / [email protected]:/backup/

(wildcard "*" two times)

Actually I wanted to exclude the whole directories, not only the files. But it did not work. Rsync completely ignored my exclude patterns.
 
If I have to guess it's probably because of the trailing slash since the trailing slash wouldn't match the pattern for the detection if I'm reading up on rsync correctly. Might want to drop off the slash and check so it looks something like this:

Bash:
rsync -a  --exclude={"/boot/lost+found","/dev"} -e 'ssh -p23' / [email protected]:/backup/
 
Thanks for your reply. It sounded logical in the first place, but under "Include/Exclude Pattern Rules" the rsync man page says:
"if the pattern ends with a / then it will only match a directory, not a regular file, symlink, or device."

When a directory is excluded, shouldn't all files within it also be excluded?

And several days ago I did a transfer from an SMB mount to the rsync server and used "--exclude=/backup1/ --exclude=/backup2/" and these folders where excluded completely (the folder and the files).

I will test it without the trailing slash and with several exclude params instead of one with curly braces. But it's still strange to me.
 
Now I did some tests. First of all I found out that the curly braces version only works with at least two entries. Not relevant for my case, but if someone wanted to know. So
Code:
--exclude={"/exclude1/","/exclude2/"}
works and
Code:
--exclude={"/exclude1/"}
does not (nothing is excluded).

Every combination of slashes worked now:
Code:
--exclude={"/exclude1/","/exclude2/"}
--exclude={"/exclude1","/exclude2"}
--exclude={"exclude1/","exclude2/"}
--exclude={"exclude1","exclude2"}
--exclude={"/exclude1/*","/exclude2/*"}
--exclude={"exclude1/*","exclude2/*"}
Which is strange, of course, because before the first version did not work. I guess the reason must be that I now backed up "/test/" instead of "/". I can't do many tests with "/", because it takes too long.

I think leaving the trailing slash away is not a good way anyway, because then also files with those names would be excluded.

I will do further testing to find out what's wrong with my initial approach.
 
Back
Top