How to exclude only subdirs (not files) but keep one certain subdir?

Hi,
I cannot find out how to set exclude options such that all but one special subdirectory is excluded and furthermore all (arbitrary) files in the first level are kept. Something like
--exclude 'path/to/exclude/**/*' --exclude '!path/to/exclude/keep_nonetheless'
does the first thing, simple enough.
Appending another
--exclude '!path/to/exclude/*
for keeping all files unfortunately draws back the whole contents of ‘path/to/exclude’.
Any idea? Thanks!

1 Like

Check this PR:

I think it’s merged, so it should be working. The last post may be of interest to you.

!/Users
/Users/*
!/Users/daniel

So perhaps using --exclude “!path/to/exclude” --exclude “path/to/exclude/*” --exclude “!path/to/exclude/keep_nonetheless” would work?

Oh interesting and very cool! I did not know that this functionality has been implemented.

I haven’t tried, but the docs say, that the following should work, too:

/Users/**/*
!/Users/daniel

(see Backing up — restic 0.14.0 documentation)

Does anybody know, if the behavior is different between /Users/* and /Users/**/*?

The first one only explicitly excludes everything directly within the Users directory, which means that you can easily cancel its effect. The latter one excludes everything inside Users and in every of its subfolders. The latter is somewhat inefficient, as matching ** takes more time.

But the negative pattern should have priority, so both should work, although the **/ variant is less efficient.

2 Likes