rustic icon indicating copy to clipboard operation
rustic copied to clipboard

Confusing order of `as-path` remapping and path filtering

Open tilpner opened this issue 4 months ago • 0 comments

The order in which the as-path remapping and the path exclusion happen leads to a potentially confusing interaction (or I'm holding it wrong). I didn't start with a PR because it might be intended behavior, and it looks like moving the remapping into the sources would be a significant change (and probably involve a PR to ignore).

Example

Setup

$ mkdir -p foo/quux
$ touch foo/quux/{3,4}
$ find foo
foo
foo/quux
foo/quux/4
foo/quux/3
$ rustic init --repo local:repo --password foobar

Now I'd like to exclude quux/4, which works with --glob '!foo/quux/4':

$ rustic backup --repo local:repo --password foobar --dry-run --log-level debug --glob '!foo/quux/4' foo |& grep quux/4
[DEBUG] (41) ignore::walk: ignoring foo/quux/4: Ignore(IgnoreMatch(Override(Glob(Matched(Glob { from: None, original: "!foo/quux/4", actual: "foo/quux/4", is_whitelist: true, is_only_dir: false })))))

But there's no need to have foo as a prefix to all my backup paths, and it'd be more readable if my exclude rules didn't have to repeat it every line, so I trim/replace the prefix with --as-path /:

$ rustic backup --repo local:repo --password foobar --dry-run --log-level debug --as-path / --glob '!quux/4' foo |& grep quux/4
[DEBUG] (1) rustic_core::archiver::tree_archiver: new       file: "/quux/4"

$ rustic backup --repo local:repo --password foobar --dry-run --log-level debug --as-path / --glob '!foo/quux/4' foo |& grep quux/4
[DEBUG] (41) ignore::walk: ignoring foo/quux/4: Ignore(IgnoreMatch(Override(Glob(Matched(Glob { from: None, original: "!foo/quux/4", actual: "foo/quux/4", is_whitelist: true, is_only_dir: false })))))

The exclude lists operate on the source path, before the as-path remapping, which can be confusing, as the backup lists the remapped paths, against which the exclude rules should have rejected quux/4:

$ rustic backup --repo local:repo --password foobar --as-path / --glob '!quux/4' foo                  
[INFO] starting to backup foo ...
snapshot ac715191 successfully saved.
[INFO] backup of foo done.

$ rustic --repo local:repo --password foobar ls ac715191
quux
quux/3
quux/4

Why use as-path?

I realize it's possible to change the current working directory to foo and use the source ./ to remove the prefix in the path listing and the exclude rules, but that only works for a single snapshot, not for a profile that contains many snapshots, each in a different directory.

tilpner avatar May 31 '25 19:05 tilpner