Skip to content

borg2: Add --exclude-archives #9936

Description

@PhrozenByte

Borg supports --match-archives, which allows selecting archives using various patterns, including archive name (default with exact or pattern matching), archive ID prefix (aid: pattern), archive tags (tags: pattern), archive creation time (date: pattern), etc. For an archive to be selected, it must match all given inclusion patterns.

Borg currently does not support the inversion of --match-archives, i.e., exclusion patterns for archives, similar to --exclude for paths. Having an equivalent mechanism for archives would make archive selection much more expressive while keeping the matching logic rather simple.

Suggestion

Add a new --exclude-archives option. The new option should accept the same archive matcher syntax as --match-archives, but instead exclude archives matching any of the given patterns. An archive should then be selected if it matches all patterns given with --match-archives and none of the patterns given with --exclude-archives.

For example:

borg repo-list \
    --match-archives "sh:my-machine-name-*" \
    --exclude-archives "tags:test"

would list all archives whose name matches my-machine-name-*, except those tagged with test.

Likewise:

borg delete \
    --match-archives "tags:daily" \
    --exclude-archives "tags:keep"

would delete all archives tagged with daily, except those additionally tagged with keep.

Benefits

This would

  • make archive selection composable,
  • avoid adding dedicated command-line options for every special filtering case,
  • naturally complement the existing --match-archives mechanism,
  • provide a flexible foundation for future archive matchers.

For example, together with the proposed extensions to the date: matcher discussed in #8715, --older TIMESPAN could eventually be deprecated in favour of --exclude-archives "date:TIMESPAN/now"

Note

The documentation currently does not explicitly state whether multiple --match-archives options are combined using OR or AND semantics. Documenting the matching semantics and evaluation order would be useful regardless of whether this proposal is accepted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions