A better way to include/exclude

I prefer excluding over including files when doing backups, so I simply backup / and pass a list of excludes via --exclude-file, like so:

**.egg-info
**.lck
**.lock
**.log
**.pyc
**.swp
**~

/bin
/boot
/dev
/lib*
/media
/opt
/proc
/run
/sbin
/sys
/tmp

[...]

Regarding /var it’s a bit more complex. I can’t simply exclude /var, because I want to keep certain directories inside /var, say /var/spool/cron/crontabs.

A pattern like the following would obviously not work:

/var                           # exlcude /var
!/var/spool/cron/crontabs      # ... but include the crontabs

So, instead I have to do this:

# Exclude everything just below /var
/var/*

# ... but keep /var/spool, exclude its contents
!/var/spool
/var/spool/*

# ... but keep /var/spool/cron, exclude its contents
!/var/spool/cron
/var/spool/cron/*

# ... but keep the crontabs
!/var/spool/cron/crontabs

This is very cumbersome. Are there easier ways to achieve the same?

1 Like

So far there’s no easier way. In theory, it should be possible for restic to generate the missing excludes to allow !/var/spool/cron/crontabs to just work. However, there are probably quite a few pitfalls there that would have to be sorted out first. Please open an issue on Github, we don’t track feature requests in the forum.

Sorry to piggy back this issue, I’ve got some ready to use exclude lists for restic at npbackup/excludes at main · netinvent/npbackup · GitHub

Would love to get a second look at what I may have missed.

IMO there would be a way, needing restic to support regex excludes, or perhaps add /var/spool/cron/crontabs to include lists and make sure includes override excludes.

@virvum, please keep me posted, this subject is of high interest for me ^^