Explorar o código

When "archive_name_format" is not set, filter archives using the default archive name format (#753).

Dan Helfman hai 1 ano
pai
achega
9f3328781b
Modificáronse 4 ficheiros con 20 adicións e 14 borrados
  1. 2 0
      NEWS
  2. 1 4
      borgmatic/borg/create.py
  3. 9 7
      borgmatic/borg/flags.py
  4. 8 3
      tests/unit/borg/test_flags.py

+ 2 - 0
NEWS

@@ -2,6 +2,8 @@
  * #743: Add a monitoring hook for sending backup status and logs to to Grafana Loki. See the
  * #743: Add a monitoring hook for sending backup status and logs to to Grafana Loki. See the
    documentation for more information:
    documentation for more information:
    https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#loki-hook
    https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#loki-hook
+ * #753: When "archive_name_format" is not set, filter archives using the default archive name
+   format.
  * Update documentation to recommend installing/upgrading borgmatic with pipx instead of pip. See the
  * Update documentation to recommend installing/upgrading borgmatic with pipx instead of pip. See the
    documentation for more information:
    documentation for more information:
    https://torsion.org/borgmatic/docs/how-to/set-up-backups/#installation
    https://torsion.org/borgmatic/docs/how-to/set-up-backups/#installation

+ 1 - 4
borgmatic/borg/create.py

@@ -215,9 +215,6 @@ def make_list_filter_flags(local_borg_version, dry_run):
         return f'{base_flags}-'
         return f'{base_flags}-'
 
 
 
 
-DEFAULT_ARCHIVE_NAME_FORMAT = '{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}'  # noqa: FS003
-
-
 def collect_borgmatic_source_directories(borgmatic_source_directory):
 def collect_borgmatic_source_directories(borgmatic_source_directory):
     '''
     '''
     Return a list of borgmatic-specific source directories used for state like database backups.
     Return a list of borgmatic-specific source directories used for state like database backups.
@@ -388,7 +385,7 @@ def create_archive(
     lock_wait = config.get('lock_wait', None)
     lock_wait = config.get('lock_wait', None)
     list_filter_flags = make_list_filter_flags(local_borg_version, dry_run)
     list_filter_flags = make_list_filter_flags(local_borg_version, dry_run)
     files_cache = config.get('files_cache')
     files_cache = config.get('files_cache')
-    archive_name_format = config.get('archive_name_format', DEFAULT_ARCHIVE_NAME_FORMAT)
+    archive_name_format = config.get('archive_name_format', flags.DEFAULT_ARCHIVE_NAME_FORMAT)
     extra_borg_options = config.get('extra_borg_options', {}).get('create', '')
     extra_borg_options = config.get('extra_borg_options', {}).get('create', '')
 
 
     if feature.available(feature.Feature.ATIME, local_borg_version):
     if feature.available(feature.Feature.ATIME, local_borg_version):

+ 9 - 7
borgmatic/borg/flags.py

@@ -59,12 +59,15 @@ def make_repository_archive_flags(repository_path, archive, local_borg_version):
     )
     )
 
 
 
 
+DEFAULT_ARCHIVE_NAME_FORMAT = '{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}'  # noqa: FS003
+
+
 def make_match_archives_flags(match_archives, archive_name_format, local_borg_version):
 def make_match_archives_flags(match_archives, archive_name_format, local_borg_version):
     '''
     '''
     Return match archives flags based on the given match archives value, if any. If it isn't set,
     Return match archives flags based on the given match archives value, if any. If it isn't set,
-    return match archives flags to match archives created with the given archive name format, if
-    any. This is done by replacing certain archive name format placeholders for ephemeral data (like
-    "{now}") with globs.
+    return match archives flags to match archives created with the given (or default) archive name
+    format. This is done by replacing certain archive name format placeholders for ephemeral data
+    (like "{now}") with globs.
     '''
     '''
     if match_archives:
     if match_archives:
         if feature.available(feature.Feature.MATCH_ARCHIVES, local_borg_version):
         if feature.available(feature.Feature.MATCH_ARCHIVES, local_borg_version):
@@ -72,10 +75,9 @@ def make_match_archives_flags(match_archives, archive_name_format, local_borg_ve
         else:
         else:
             return ('--glob-archives', re.sub(r'^sh:', '', match_archives))
             return ('--glob-archives', re.sub(r'^sh:', '', match_archives))
 
 
-    if not archive_name_format:
-        return ()
-
-    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 or DEFAULT_ARCHIVE_NAME_FORMAT
+    )
 
 
     if derived_match_archives == '*':
     if derived_match_archives == '*':
         return ()
         return ()

+ 8 - 3
tests/unit/borg/test_flags.py

@@ -88,8 +88,8 @@ 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, '', True, ()),
+        (None, None, True, ('--match-archives', 'sh:{hostname}-*')),  # noqa: FS003
+        (None, '', True, ('--match-archives', 'sh:{hostname}-*')),  # noqa: FS003
         (
         (
             're:foo-.*',
             're:foo-.*',
             '{hostname}-{now}',  # noqa: FS003
             '{hostname}-{now}',  # noqa: FS003
@@ -145,7 +145,12 @@ def test_make_repository_archive_flags_with_borg_features_joins_repository_and_a
             True,
             True,
             (),
             (),
         ),
         ),
-        (None, '{utcnow}-docs-{user}', False, ('--glob-archives', '*-docs-{user}')),  # noqa: FS003
+        (
+            None,
+            '{utcnow}-docs-{user}',  # noqa: FS003
+            False,
+            ('--glob-archives', '*-docs-{user}'),  # noqa: FS003
+        ),
     ),
     ),
 )
 )
 def test_make_match_archives_flags_makes_flags_with_globs(
 def test_make_match_archives_flags_makes_flags_with_globs(