Flexbackup: Read per-directory exclude expressions from files

Published by cybso on
This is a post from my original site, which was hosted by the former blog service of the University of Osnabrück. I have moved it to the new site for archiving. Pages linked in this article may no longer work today, and the blog comments under the article no longer exist. Opinions expressed in this article reflect the point of view of the time of publication and do not necessarily reflect my opinion today.

Today I wrote a patch to Flexbackup 1.2.1 which allows you to define exclude expressions on a per-directory-base (like svn:ignore, cvs_ignore or tar's --exclude-from). Apply this patch and add the following line to your flexbackup.conf:

$exclude_expr_filename = '.flexbackup_exclude';

This activates an additional routine in the file_list_cmd() method. As soon as the 'find' command has enough parameters to iterate through all directory it is used to retrieve a list of '.flexbackup_exclude' files. Each file is read line by line and a regular expression will build and appended to the directory's name, e.g:

$ cat dummy/.flexbackup_exclude
.*\.tmp$
a_very_big_file\.iso

Will result in the expression:

dummy\/((.*\.tmp$)|(a_very_big_file\.iso))

All files matching this expression will be ignored. This is done by piping find's output through xargs and perl:

$ find . [conditions...] -print0 | xargs -0 perl -e 'foreach (@ARGV) { print "$_" if ! /dummy\/((.*\.tmp$)|(a_very_big_file\.iso))/ and 1'

If more than one .flexbackup_exclude-file is found more conditions are prepended to the 'and 1'-dummy-condition. Because every condition is tested (and ignored if compilation failed) it should not be possible to break the backup using these files.

Download: flexbackup-exclude-expressions.patch

PS: Perl sucks ;)