2

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?

Xenon
  • 165
  • 8

2 Answers2

4

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.

Xenon
  • 165
  • 8
0

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

dawud
  • 14,918
  • 3
  • 41
  • 61
  • 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