Exclude all except 1 file in folder

Guys hi,

Long time (and happy) restic user.

My main back up command is something like this:

restic -r $REPO backup k:/sync --exclude logs

there is one folder in which i want to exclude all files except one, so i was thinking to add to my command --exclude-file .rignore, and placing in it

/k/sync/Mems/AAA/**
!/k/sync/Mems/AAA/url-watches.json

but apparently i can’t do cause “It works similarly to gitignore, with the same limitation: once a directory is excluded, it is not possible to include files inside the directory.”

So i will have to do

/k/sync/Mems/**
!/k/sync/Mems/AAA/
/k/sync/Mems/AAA/
!/k/sync/Mems/AAA/url-watches.json

problem that Mems folder has lots of folders so i will have to do something like

/k/sync/Mems/**
!/k/sync/Mems/AAA/
/k/sync/Mems/AAA/
!/k/sync/Mems/AAA/url-watches.json
!/k/sync/Mems/BBB/
!/k/sync/Mems/CCC/

!/k/sync/Mems/ZZZ/

which is obviously very dirty / unconvenient.

Do i understand i right best solution here is to exclude full fulder with --exclude AAA and than run separate backup command only for the file i need?

1 Like

The correct pattern would be as follows: (* instead of **)

/k/sync/Mems/AAA/*
!/k/sync/Mems/AAA/url-watches.json

** matches zero or more directory levels, whereas * matches a single one. That is /k/sync/Mems/AAA/* only excludes directory entries within AAA, whereas /k/sync/Mems/AAA/** also excludes AAA.

1 Like

I wonder whether restic should warn about exclude patterns that end with /**. These are basically guaranteed to not behave as expected.

Is there a readily available basic commend-line tool to play with such rules and patterns ?
What I would envision is using a pre-filled file with 1 path / line, and partitioning this file from the set of rules provided to restic. The output of the tool would be the partition, for example as two files : excluded and included.

There is backup --dry-run --verbose=2 which shows each file that would be backed up, but doesn’t upload anything. But excluded files aren’t shown there I think.