From f495550ad7fdfb95e1d25d0a7c134e3490abc5da Mon Sep 17 00:00:00 2001 From: Dan Date: Sun, 29 Oct 2017 20:14:18 -0700 Subject: [PATCH] Default "prefix" to "{hostname}-" if not specified. --- NEWS | 3 ++- borgmatic/borg/prune.py | 3 +++ borgmatic/config/schema.yaml | 2 +- borgmatic/tests/unit/borg/test_prune.py | 4 ++-- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index 1b815db1..00c5298d 100644 --- a/NEWS +++ b/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. diff --git a/borgmatic/borg/prune.py b/borgmatic/borg/prune.py index 7f0c0381..0f20c3d6 100644 --- a/borgmatic/borg/prune.py +++ b/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() diff --git a/borgmatic/config/schema.yaml b/borgmatic/config/schema.yaml index 0c0a328d..c70cba09 100644 --- a/borgmatic/config/schema.yaml +++ b/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: | diff --git a/borgmatic/tests/unit/borg/test_prune.py b/borgmatic/tests/unit/borg/test_prune.py index 003b2cbb..ac941fea 100644 --- a/borgmatic/tests/unit/borg/test_prune.py +++ b/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():