Omit "--glob-archives" or "--match-archives" Borg flag when its value would be "*" (#734).

This commit is contained in:
Dan Helfman 2023-08-02 10:23:22 -07:00
parent e607de7df1
commit 14e2a6b89d
3 changed files with 24 additions and 7 deletions

2
NEWS
View file

@ -11,6 +11,8 @@
* #732: Include multiple configuration files with a single "!include". See the documentation for * #732: Include multiple configuration files with a single "!include". See the documentation for
more information: more information:
https://torsion.org/borgmatic/docs/how-to/make-per-application-backups/#multiple-merge-includes 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 1.8.0
* #575: BREAKING: For the "borgmatic borg" action, instead of implicitly injecting * #575: BREAKING: For the "borgmatic borg" action, instead of implicitly injecting

View file

@ -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) 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): if feature.available(feature.Feature.MATCH_ARCHIVES, local_borg_version):
return ('--match-archives', f'sh:{derived_match_archives}') return ('--match-archives', f'sh:{derived_match_archives}')
else: else:

View file

@ -86,28 +86,28 @@ def test_make_repository_archive_flags_with_borg_features_joins_repository_and_a
@pytest.mark.parametrize( @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, None, True, ()),
(None, '', True, ()), (None, '', True, ()),
( (
're:foo-.*', 're:foo-.*',
'{hostname}-{now}', '{hostname}-{now}', # noqa: FS003
True, True,
('--match-archives', 're:foo-.*'), ('--match-archives', 're:foo-.*'),
), # noqa: FS003 ),
( (
'sh:foo-*', 'sh:foo-*',
'{hostname}-{now}', '{hostname}-{now}', # noqa: FS003
False, False,
('--glob-archives', 'foo-*'), ('--glob-archives', 'foo-*'),
), # noqa: FS003 ),
( (
'foo-*', 'foo-*',
'{hostname}-{now}', '{hostname}-{now}', # noqa: FS003
False, False,
('--glob-archives', 'foo-*'), ('--glob-archives', 'foo-*'),
), # noqa: FS003 ),
( (
None, None,
'{hostname}-docs-{now}', # noqa: FS003 '{hostname}-docs-{now}', # noqa: FS003
@ -133,6 +133,18 @@ def test_make_repository_archive_flags_with_borg_features_joins_repository_and_a
False, False,
('--glob-archives', '{hostname}-docs-*'), # noqa: FS003 ('--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 (None, '{utcnow}-docs-{user}', False, ('--glob-archives', '*-docs-{user}')), # noqa: FS003
), ),
) )