Browse Source

Default "prefix" to "{hostname}-" if not specified.

Dan 7 years ago
parent
commit
f495550ad7
4 changed files with 8 additions and 4 deletions
  1. 2 1
      NEWS
  2. 3 0
      borgmatic/borg/prune.py
  3. 1 1
      borgmatic/config/schema.yaml
  4. 2 2
      borgmatic/tests/unit/borg/test_prune.py

+ 2 - 1
NEWS

@@ -3,7 +3,8 @@
  * #33: Improve clarity of logging spew at high verbosity levels.
  * #29: Support for using tilde in source directory path to reference home directory.
  * Require "prefix" in retention section when "archive_name_format" is set. This is to avoid
-   accidental pruning of archives with a different archive name format.
+   accidental pruning of archives with a different archive name format. For similar reasons, default
+   "prefix" to "{hostname}-" if not specified.
  * Convert main source repository from Mercurial to Git.
  * Update dead links to Borg documentation.
 

+ 3 - 0
borgmatic/borg/prune.py

@@ -19,6 +19,9 @@ def _make_prune_flags(retention_config):
             ('--keep-monthly', '6'),
         )
     '''
+    if not retention_config.get('prefix'):
+        retention_config['prefix'] = '{hostname}-'
+
     return (
         ('--' + option_name.replace('_', '-'), str(retention_config[option_name]))
         for option_name, value in retention_config.items()

+ 1 - 1
borgmatic/config/schema.yaml

@@ -132,7 +132,7 @@ map:
                 desc: |
                     When pruning, only consider archive names starting with this prefix.
                     Borg placeholders can be used. See the output of "borg help placeholders" for
-                    details.
+                    details. Default is "{hostname}-".
                 example: sourcehostname
     consistency:
         desc: |

+ 2 - 2
borgmatic/tests/unit/borg/test_prune.py

@@ -18,7 +18,7 @@ BASE_PRUNE_FLAGS = (
 )
 
 
-def test_make_prune_flags_should_return_flags_from_config():
+def test_make_prune_flags_should_return_flags_from_config_plus_default_prefix():
     retention_config = OrderedDict(
         (
             ('keep_daily', 1),
@@ -29,7 +29,7 @@ def test_make_prune_flags_should_return_flags_from_config():
 
     result = module._make_prune_flags(retention_config)
 
-    assert tuple(result) == BASE_PRUNE_FLAGS
+    assert tuple(result) == BASE_PRUNE_FLAGS + (('--prefix', '{hostname}-'),)
 
 
 def test_make_prune_flags_accepts_prefix_with_placeholders():