Only include some specific file extensions in backup

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.
On Linux, 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).

The .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

But since restic’s documentation states

A trailing / is ignored, a leading / anchors the pattern at the root directory. This means, /bin matches /bin/bash but does not match /usr/bin/restic.

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.

And option to overwrite the sources list in the snapshot would also work here (Ability to overwrite Drive/Path on backups · Issue #1376 · restic/restic · GitHub).

Hmm, it sounds reasonable, although it’s also somewhat not optimal for you use case: that way the backup would include tons of empty folders.

Would not be an issue in this specific case since most of the folders contain the files, but yes, good point.

Could you open a feature request on GitHub?

Created: #4399.

1 Like