restic icon indicating copy to clipboard operation
restic copied to clipboard

Allow excluding/negative-excluding directories only – give meaning to trailing slashes

Open halms opened this issue 1 year ago • 2 comments

Output of restic version

restic 0.15.2 compiled with go1.20.3 on linux/amd64

What should restic do differently? Which functionality do you think we should add?

I would like restic to more closely follow the .gitignore syntax, specifically this part:

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.

Rather than the current behavior:

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.

This would allow something like:

# Exclude everything...
*
# ...but keep directories.
!*/
# Keep Excel files
!*.xlsx
!*.xlsm

What are you trying to do? What problem would this solve?

This forum discussion provides a bit more context.

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.

My specific use case is about Excel files on a Windows Fileshare (don’t ask…). Currently this is only possible by using --files-from and creating the file list with an external tool (such as find on Linux; there's probably a Powershell equivalent). I’d like to avoid this behavior since it requires an external tool and pollutes the list of sources in the snapshot list.

Since the exclude functionality now has negative excludes, this could nicely be covered there. But it currently is not possible to exclude all files, but not exclude all directories (and therefore the parent directories of all files).

Maybe this is currently somehow possibly by looking for names with a dot/file extension, but this is not clean since both directories with a dot in the name and files without an extension are quite common.

Did restic help you today? Did it make you happy in any way?

Restic runs great on a daily basis to backup all my personal files to Google Drive (via Rclone) and has saved my ass more than once. 🙌

halms avatar Jul 07 '23 10:07 halms

Including only specified files by mask with --files-from is better than nothing, but if you have thousends of files mentioned in --files-from list then they all will be listed in restic snapshots table in Paths section. So if i whant to see previous snapshot ID from command line a need to scroll down thousands of Path's lines..

itatelier avatar Mar 11 '24 18:03 itatelier

It could also be very convenient to distinguish between excluding a directory or a file, e.g. I want to exclude my .git DIRECTORY, but want include a .git FILE.

That means the pattern .git/ can be used to exclude only a directory with this name, but not a file with the same name.

FreeHarry avatar Jul 02 '24 10:07 FreeHarry