Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm using rsync on an Ubuntu 12.04 LTS server with the following script to back up all of /, however, whenever I run the script (as root), the directory /backup is included, when it should be excluded:

#!/bin/sh
rsync --password-file=/etc/rsyncd.password --delete -aAXzv --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found,/home/*/.gvfs,/home/*/Downloads/*,/backup/*,/var/spool/squid3,/opt/atlassian,var/www/\~*} /* fsbak@servername::fsbak

Why is this happening, and how can I make rsync ignore /backup?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Changing #!/bin/sh to #!/bin/bash in the script has fixed this issue. The curly brace expansion used in the script is a bash feature and, as such, is not available in sh.

share|improve this answer

From the rsync(1) manpage:


      --exclude=PATTERN       exclude **files** matching PATTERN

When you specify /backup/*, you are excluding all files inside the directory, but not the directory itself. To exclude the directory, use /backup

Example:


$ tree test
test
├── a
│   ├── 1
│   ├── 2
│   ├── 3
│   └── 4
└── b

$ rsync -av --exclude=4 $PWD/test/a/ $PWD/test/b/
sending incremental file list
./
1/
2/
3/

sent 87 bytes  received 27 bytes  228.00 bytes/sec
total size is 0  speedup is 0.00

$ tree test
test
├── a
│   ├── 1
│   ├── 2
│   ├── 3
│   └── 4
└── b
    ├── 1
    ├── 2
    └── 3

9 directories, 0 files

share|improve this answer
    
All of the files inside /backup are still being included in the rsync. I have tried changing it from /backup/* to /backup, and it doesn't help. –  Xenon Apr 12 '13 at 23:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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