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

This commit is contained in:
Dan 2017-10-29 20:14:18 -07:00
parent 43d0e597a2
commit f495550ad7
4 changed files with 8 additions and 4 deletions

3
NEWS
View file

@ -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.

View file

@ -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()

View file

@ -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: |

View file

@ -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():