22 Dec 2014, 17:36

rsync: include a subdirectory from an excluded directory

Share

Messing with rsync Filter-Options tends to get a little bit messy.

Imaging you want to backup some machine holding a set of nested, rotated MySQL Backups in paths like this:

srv/backup/mysql/{instance}/{daily,weekly,monthly}/{0-9}/
If you were to backup everything you’d get a lot of noise in your backups, since the numbered directories at the end will get rotated daily, as well weekly and monthly directories with less frequency.

I certainly did not want that, so I was look for an rsync exclude/filter rule that would exclude the whole /srv/backup/mysql folder but still include the most recent directory (daily/0). Since I did that more once now, I thought it would be good to write it down.

The following list will achieche that. Please note that it’s important to include each directory while excluding the unwanted contents.

+ srv/backup/mysql/localhost/daily/0/
+ srv/backup/mysql/localhost/daily/
- srv/backup/mysql/localhost/daily/*
+ srv/backup/mysql/localhost/
- srv/backup/mysql/localhost/*
+ srv/backup/mysql/
- srv/backup/mysql/*
- srv/backup/*