rsync --exclude option???

Asked by jetbundle on 2009-01-31


Just a question whether a problem with rsync is a bug...
I wrote a nice little backup script for my entire disk. The line for the partition at / reads:

rsync -au --delete --exclude=/home --exclude=/media/*/* --exclude=/boot /* /media/usb2/

and should exclude /home and /boot (which are on other partitions) and /media/*/*, in order not to copy mounted drives (and in particular not recurse into the external disk mounted at /media/usb2/).
I think it used to work, but recently it recursed into /media/usb2/ and the resulting crash managed to damage the whole system, which I had to recover from a third backup.
What works now is

rsync -au --delete --exclude=/home --exclude=/media/*/* --exclude=/media/usb2/* --exclude=/boot /* /media/usb2/

but I think the extra --exclude should not be necessary.
Should I report this as a bug?


Question information

English Edit question
Ubuntu rsync Edit question
No assignee Edit question
Solved by:
Last query:
Last reply:
Revision history for this message
Best juancarlospaco (juancarlospaco) said :

No, no report this as a bug.

use rsync with:
--exclude-from=FILE read exclude patterns from FILE

check this out, run:
rsync --help | grep exclude
and you get all exclude related options.

Revision history for this message
jetbundle (mbrane) said :

Thanks. I'll play around with it a bit more then :)

Revision history for this message
Buz Cory (buzco) said :

OK, I don't know much about rsync (high security risk unless you control the entire path between machines) but in general excluding a directory _should_ exclude all content including subdirs. So
should suffice.

If that is not the case, then I would consider it a bug.

Word of warning, test such things in such a way that if they fail they fail safe, without causing utter disaster.

Also, don't take the advice of the first person that happens to answer as being authoritative. There is no screening of who answers questions here. You have seen how easy it is to get an account here and anyone w/ an account can answer any question.

== Buz :)

Revision history for this message
jetbundle (mbrane) said :

Thanks for your answer, Buz.

Actually, your trailing / on the directories (e.g. /home/ vs. /home ) inspired me to study the man page a bit more rigorously (Which I should have done before posting here actually).
So I think what I should have written is /media/*/**, because "*" matches only components without a "/" in them (but I want to reproduce any changes to my mount points).
I'm still confused why it worked when I tested the script, but maybe I didn't test it properly?

P.S. as for security of rsync, my laptop, the external HD and the ultrabay HD adapter are all under my control, and one of my two backups gets locked in the office cabinet and the other in my fireproof safe ;)

Revision history for this message
Buz Cory (buzco) said :


Using the trailing slash on a directory name was inspired by the http: protocol (I have worked a lot on HTML) and also by ZSH and other apps which make good use of it. As a further incentive, it makes it obvious to a human reader that this is a dir and not an ordinary file.

I never saw that "/**" notation used anywhere but in ZSH, where it works very well.

I also did not mean to imply that you should not be using rsync, only that I had not had circumstances that made it appropriate. It does seem to me, however, that you are leaving yourself vulnerable to a "man in the middle" attack. The necessary security is that you have complete control of the entire network path between the machines which does not seem to be the case here. Security of the backups between sync runs is an entirely different matter.

Anyway, glad I could be of help,
Have fun,
== Buz :)