Skip to content

borg2 repo-list|transfer --from-borg1: date: patterns match no archives #9949

Description

@PhrozenByte

With borg2 v2.0.0b22, the new date: archive pattern (#8776, for reference @c-herz) does not appear to work when filtering archives from a legacy repo via --from-borg1 (e.g. listing archives with borg2 repo-list --from-borg1 or transferring legacy archives with borg2 transfer --from-borg1).

For example:

$ borg2 repo-list -r /run/media/daniel/themisto/Backup/Borg --from-borg1 -a 'date:2026-03'

returns no matching archives, even though matching archives exist (I have removed the unrelated warning from #9935). After transferring archives to a native borg2 repo, the date: pattern works as expected and returns matching archives.

date: matching is implemented for Borg 2 repos here:

borg/src/borg/manifest.py

Lines 240 to 246 in 91bf03e

elif match.startswith("date:"):
wanted_date = match.removeprefix("date:")
try:
date_matches = compile_date_pattern(wanted_date)
except DatePatternError as exc:
raise CommandError(f"Invalid date pattern: {match} ({exc})")
archive_infos = [x for x in archive_infos if date_matches(x.ts)]

but not for legacy repos:

def _matching_info_tuples(self, match_patterns, match_end, *, deleted=False):
archive_infos = list(self._info_tuples(deleted=deleted))
if match_patterns:
assert isinstance(match_patterns, list), f"match_pattern is a {type(match_patterns)}"
for match in match_patterns:
if match.startswith("aid:"):
wanted_id = match.removeprefix("aid:")
archive_infos = [x for x in archive_infos if bin_to_hex(x.id).startswith(wanted_id)]
if len(archive_infos) != 1:
raise CommandError("archive ID based match needs to match precisely one archive ID")
elif match.startswith("tags:"):
wanted_tags = match.removeprefix("tags:")
wanted_tags = [tag for tag in wanted_tags.split(",") if tag]
archive_infos = [x for x in archive_infos if set(x.tags) >= set(wanted_tags)]
elif match.startswith("user:"):
wanted_user = match.removeprefix("user:")
archive_infos = [x for x in archive_infos if x.user == wanted_user]
elif match.startswith("host:"):
wanted_host = match.removeprefix("host:")
archive_infos = [x for x in archive_infos if x.host == wanted_host]
else:
match = match.removeprefix("name:")
regex = get_regex_from_pattern(match)
regex = re.compile(regex + match_end)
archive_infos = [x for x in archive_infos if regex.match(x.name) is not None]
return archive_infos

So my guess is that the date: pattern simply hasn't been implemented for the legacy code path yet. From a quick look, I don't see an obvious reason why it couldn't be supported there as well. This would be an especially helpful feature for borg2 transfer --from-borg1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions