Rsnapshot and backing up only specific subdirectories

Rsnapshot is very useful tool when it comes to backups – based on reliable and versatile ‘rsync’ is capable to meet most of possible expectations.

Just recently I had to figure out how to make it backup only specific subdirectories from the tree, i.e. mail in example below:


Needless to say that these are not the only folders in user’s home directory.

To configure Rsnapshot to add and exclude files/folders from backup you have to use keywords “include” and “exclude” followed by name/path and this is all it really takes to achieve our goal.

Firstly configuration below seemed to make perfect sense:

include */mail/**
exclude *

I expected it to include the mail folder from every single folder in backup point (which is set to “/home/”) and exclude all the rest – but it didn’t work that way and every other variation of this was failing also.

The solution happened to be including in separate “include” user’s home folder by adding this first line:

include */
include */mail/**
exclude *

The solution is very simple but took me some time to find it.

Now the only thing that you may need or not are empty dirs because rsnapshot/rsync sill create whole folder tree and only copy files from mail (in this case) – if you don’t want this you can add “ –prune-empty-dirs” to long arguments in Rsnapshot configuration and there will be left only folders that actually are having some files in.

This entry was posted in Managed Hosting. Bookmark the permalink.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>