From 32a1043468a7e637a8a0873e2904ff1969017ade Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Mon, 23 May 2022 16:11:24 -0700 Subject: [PATCH] Remove the error when "archive_name_format" is specified but a retention prefix isn't (#402). --- NEWS | 1 + borgmatic/config/schema.yaml | 8 ++++---- borgmatic/config/validate.py | 9 --------- tests/unit/config/test_validate.py | 27 --------------------------- 4 files changed, 5 insertions(+), 40 deletions(-) diff --git a/NEWS b/NEWS index 4c082e6..4445849 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,5 @@ 1.6.1.dev0 + * #402: Remove the error when "archive_name_format" is specified but a retention prefix isn't. * #420: Warn when an unsupported variable is used in a hook command. * #528: Improve the error message when a configuration override contains an invalid value. * #531: BREAKING: When deep merging common configuration, merge colliding list values by appending diff --git a/borgmatic/config/schema.yaml b/borgmatic/config/schema.yaml index 6b4ca4c..16a3fd5 100644 --- a/borgmatic/config/schema.yaml +++ b/borgmatic/config/schema.yaml @@ -332,10 +332,10 @@ properties: Name of the archive. Borg placeholders can be used. See the output of "borg help placeholders" for details. Defaults to "{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}". If you specify this - option, you must also specify a prefix in the retention - section to avoid accidental pruning of archives with a - different archive name format. And you should also specify a - prefix in the consistency section as well. + option, consider also specifying a prefix in the retention + and consistency sections to avoid accidental + pruning/checking of archives with different archive name + formats. example: "{hostname}-documents-{now}" relocated_repo_access_is_ok: type: boolean diff --git a/borgmatic/config/validate.py b/borgmatic/config/validate.py index 3f8f303..156b4a6 100644 --- a/borgmatic/config/validate.py +++ b/borgmatic/config/validate.py @@ -65,15 +65,6 @@ def apply_logical_validation(config_filename, parsed_configuration): below), run through any additional logical validation checks. If there are any such validation problems, raise a Validation_error. ''' - archive_name_format = parsed_configuration.get('storage', {}).get('archive_name_format') - prefix = parsed_configuration.get('retention', {}).get('prefix') - - if archive_name_format and not prefix: - raise Validation_error( - config_filename, - ('If you provide an archive_name_format, you must also specify a retention prefix.',), - ) - location_repositories = parsed_configuration.get('location', {}).get('repositories') check_repositories = parsed_configuration.get('consistency', {}).get('check_repositories', []) for repository in check_repositories: diff --git a/tests/unit/config/test_validate.py b/tests/unit/config/test_validate.py index 84eb0a8..a858899 100644 --- a/tests/unit/config/test_validate.py +++ b/tests/unit/config/test_validate.py @@ -37,33 +37,6 @@ def test_validation_error_string_contains_errors(): assert 'uh oh' in result -def test_apply_logical_validation_raises_if_archive_name_format_present_without_prefix(): - flexmock(module).format_json_error = lambda error: error.message - - with pytest.raises(module.Validation_error): - module.apply_logical_validation( - 'config.yaml', - { - 'storage': {'archive_name_format': '{hostname}-{now}'}, - 'retention': {'keep_daily': 7}, - }, - ) - - -def test_apply_logical_validation_raises_if_archive_name_format_present_without_retention_prefix(): - flexmock(module).format_json_error = lambda error: error.message - - with pytest.raises(module.Validation_error): - module.apply_logical_validation( - 'config.yaml', - { - 'storage': {'archive_name_format': '{hostname}-{now}'}, - 'retention': {'keep_daily': 7}, - 'consistency': {'prefix': '{hostname}-'}, - }, - ) - - def test_apply_locical_validation_raises_if_unknown_repository_in_check_repositories(): flexmock(module).format_json_error = lambda error: error.message