diff --git a/NEWS b/NEWS index 88b9cc9d..0c5d84a4 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,8 @@ * #732: Include multiple configuration files with a single "!include". See the documentation for more information: https://torsion.org/borgmatic/docs/how-to/make-per-application-backups/#multiple-merge-includes + * #734: Omit "--glob-archives" or "--match-archives" Borg flag when its value would be "*" (meaning + all archives). 1.8.0 * #575: BREAKING: For the "borgmatic borg" action, instead of implicitly injecting diff --git a/borgmatic/borg/flags.py b/borgmatic/borg/flags.py index 986531bc..dc7e84d6 100644 --- a/borgmatic/borg/flags.py +++ b/borgmatic/borg/flags.py @@ -77,6 +77,9 @@ def make_match_archives_flags(match_archives, archive_name_format, local_borg_ve derived_match_archives = re.sub(r'\{(now|utcnow|pid)([:%\w\.-]*)\}', '*', archive_name_format) + if derived_match_archives == '*': + return () + if feature.available(feature.Feature.MATCH_ARCHIVES, local_borg_version): return ('--match-archives', f'sh:{derived_match_archives}') else: diff --git a/tests/unit/borg/test_flags.py b/tests/unit/borg/test_flags.py index 2eaff0ae..804dd8f1 100644 --- a/tests/unit/borg/test_flags.py +++ b/tests/unit/borg/test_flags.py @@ -86,28 +86,28 @@ def test_make_repository_archive_flags_with_borg_features_joins_repository_and_a @pytest.mark.parametrize( - 'match_archives, archive_name_format,feature_available,expected_result', + 'match_archives,archive_name_format,feature_available,expected_result', ( (None, None, True, ()), (None, '', True, ()), ( 're:foo-.*', - '{hostname}-{now}', + '{hostname}-{now}', # noqa: FS003 True, ('--match-archives', 're:foo-.*'), - ), # noqa: FS003 + ), ( 'sh:foo-*', - '{hostname}-{now}', + '{hostname}-{now}', # noqa: FS003 False, ('--glob-archives', 'foo-*'), - ), # noqa: FS003 + ), ( 'foo-*', - '{hostname}-{now}', + '{hostname}-{now}', # noqa: FS003 False, ('--glob-archives', 'foo-*'), - ), # noqa: FS003 + ), ( None, '{hostname}-docs-{now}', # noqa: FS003 @@ -133,6 +133,18 @@ def test_make_repository_archive_flags_with_borg_features_joins_repository_and_a False, ('--glob-archives', '{hostname}-docs-*'), # noqa: FS003 ), + ( + None, + '{now}', # noqa: FS003 + False, + (), + ), + ( + None, + '{now}', # noqa: FS003 + True, + (), + ), (None, '{utcnow}-docs-{user}', False, ('--glob-archives', '*-docs-{user}')), # noqa: FS003 ), )