I’m using restic for quite some time for generic backups and am very happy with it.
Now I’ve come across a specific use case, that I don’t see covered well at the moment.
I’d like to only include files with specific extensions in the backup.
Or probably rather: I’d like to exclude everything except folders and files with a specific extension.
Specifically this is about Excel files (don’t ask…).
One possibility I see is to just use
--files-from and create the file list with an external tool.
find . -name "*.xlsx"or similar would come to my mind and for Windows there is definitely a possible equivalent with Powershell, but that’s not the point here.
I’d like to avoid it since this very much pollutes the list of sources in the snapshot list.
Since the exclude functionality now has negative excludes, there might be a possibility, but where I’m struggling is excluding all files, but not excluding all folders (and therefore the parent directories of all files).
.gitignore syntax, that inspired has this behavior:
If there is a separator at the end of the pattern then the pattern will only match directories, otherwise the pattern can match both files and directories.
This would allow something like
# Exclude everything... * # ...but keep directories. !*/ # Keep Excel files !*.xlsx !*.xlsm
But since restic’s documentation states
/is ignored, a leading
/anchors the pattern at the root directory. This means,
/bin/bashbut does not match
The above example does not work and I also did not come up with another easy way to achieve what I want.
Are my assumptions correct or am I missing something?
And: would matching exclude patterns with a trailing
/ to only directories be a sensible feature to add?
It would be a bit of a change since – from what I saw in the code – the current pattern matcher only works on the filename, but does not have information about the type (file/directory) present.