-
-
Notifications
You must be signed in to change notification settings - Fork 825
Description
In rsync it's possible to recursively include all sub-directories below a directory (e.g. /var/log/), but exclude all files, using a pair of filters of the form:
+ /var/log/**/
- /var/log/**
Unfortunately nothing was included when I tried this using Borg (borg-linux64_1.1.0b4) as follows:
borg create --patterns-from $BB/patterns.txt $BB/test::excl-logs_1 /var/log
where $BB is my home for Borg Backup repos and the patterns file.
At first I thought that this was due issue #2314 and it doesn't work because Borg doesn't yet have a rule prefix to "exclude, but recurse into, searching for includes". However it works in rsync OK even though it doesn't support that type of rule either (as far as I know), and if I understand rsync correctly "-" means "exclude, do not recurse into". The real problem seems to be the way that Borg handles patterns ending with "/".
In rsync "if the pattern ends with a / then it will only match a directory, not a file, link, or device". The first pattern above matches all the subdirectories because they end with "/". Everything else falls through and is excluded by the second pattern. This is consistent with the way expansion works in bash (when globstar is set): /var/log/**/ expands to /var/log/ followed by all its subdirectories (in depth first order) but nothing else.
However in Borg "if a given pattern ends in a path separator, a '*' is appended before matching is attempted.". This means that the first pattern above becomes /var/log/**/*, which matches the contents of all the subdirectories but none of the subdirectories themselves, so they are excluded by the second pattern. I assume the contents aren't included because the directories that contained them weren't. This pattern matching can be confirmed by in bash where ls -ld /var/log/**/* doesn't list any files or subdirectories immediately below /var/log/, only the contents of the subdirectories.
If Borg didn't append the extra "*" to patterns ending with "/", and it's pattern matching worked in the same way as rsync, then that would have at least two advantages:
- It be possible to include subdirectories but not files as described above.
- The new "exclude, but recurse into, searching for includes" rule probably wouldn't be needed because rule-sets could be re-written to work the rsync way.