I am trying to set up rsync backup for my FreeBSD servers.
I’ve put together an rsync-command that looks like this:
rsync -avzhe ssh --progress --delete --delete-excluded \
--exclude-from=/root/rsync-excludes \
-e ssh / [email protected]:Backups/location
My /root/rsync-excludes
file looks like this:
- *~
+ /root
+ /usr/home
+ /usr/srv
+ /etc
+ /usr/local/etc
+ /var/backups
+ /usr/local/pgsql/backups
- /root/.my.cnf
- /*
But for some reason, it only backs up /etc and /root, leaving out the other files. Can someone explain why?
Solution
As per the answer from Gilles, I figured it out, and my config now looks like this:
- *~
+ /etc
+ /root
+ /usr/
+ /usr/home
+ /usr/local/
+ /usr/local/etc
+ /usr/local/git
+ /usr/local/pgsql/
+ /usr/local/pgsql/backups
- /usr/local/pgsql/*
+ /usr/local/varnish
- /usr/local/*
+ /usr/srv
- /usr/*
+ /var/
+ /var/backups
- /var/*
- /root/.my.cnf
- /*
During a recursive traversal, rsync matches each directory against the rules. When it comes to
/usr
, the first matching rule is- /*
. Therefore/usr
is excluded, and rsync doesn't even look at anything below it. Fix: explicitly include/usr
, as well as/usr/local
,/usr/local/pgsql
and/var
.The rsync manual has a more extended discussion under “include/exclude pattern rules” (admittedly not the easiest read).
It looks like you are getting --one-file-system behavior. This may be the default on freebsd.
I also see that your destination is not a root account which should break retaining permissions and ownership.