Rsnapshot –exclude-from file not working for sub directories

Posted on

Problem :

I am doing a remote backup. This are my rsnapshot config.

config_version  1.2
snapshot_root   /data/sbackup/
cmd_cp  /bin/cp
cmd_rm  /bin/rm
cmd_rsync       /usr/bin/rsync
cmd_ssh /usr/bin/ssh
cmd_logger      /usr/bin/logger
interval        alpha   2
interval        beta    2
interval        gamma   2
interval        delta   1
ssh_args    -p xxxx
verbose         3
loglevel        4
logfile /var/log/rsnapshot/
exclude_file    /data/xxxxx.exclude
rsync_long_args --stats --delete --numeric-ids --relative   --delete-excluded
lockfile        /var/run/
backup xxxxx-server/

I have added this bottom lines in exclude_file

+ /root
+ /backups/mysqldb/latest
+ /etc/automysqlbackup
+ /etc/imscp
+ /etc/postfix
+ /etc/fail2ban
+ /etc/dovecot
+ /etc/apache2
+ /etc/ssh
+ /etc/ssl
+ /etc/php5
+ /etc/cron.d
+ /usr
+ /var/mail
+ /var/www
+ /var/log
- /var/cache
- /boot
- /home
- /opt
- /etc
- /*

But after doing a rsync I am only getting full root & usr directory’s. No other mentioned + path files/sub directories are getting downloaded.

I want + directories to be includes and - not to be includes.

What I am doing wrong?.

Solution :

the syntax is difficult, but not impossible once you get the hang of it, the trick is to realize you must list the directories to match one by one relative to the the root of the rsync/rsnapshot working directory:

say you want to include the /var/log directory and nothing else

+ /var  # we want the var directory
+ /var/log # we want the var/log directory
- /var/* # we dont want anything else in the var directory
- /* # we don't want anything else at all

Hope you see it, first we have a match on /var, then on /var/log, then on /var/* and then on /*.

This would not work

+ /var/log
- /*

because /var/log will not generate a match, oddly enough….

In your example your first

+ /backups/mysqldb/latest

would never create a match.. for the same reason!

It seems your exclude pattern /* means that any paths like /etc/something will
be excluded unless you explicitly include /etc and then exclude those you don’t want
with /etc/*.

So add + /etc and - /etc/*, and similarly for /var and /backups and /backups/mysqldb.

By the way, I said earlier you needed 2 files, a separate include_file and exclude_file.
You can do this, but in fact if you start each line in the file with an
explicit ‘+ ‘ or ‘- ‘ it overrides the default include or exclude aspect.
So you can put all in one file, provided you prefix the lines as you have done.

Leave a Reply

Your email address will not be published. Required fields are marked *