From ef3dda9213bd06a59c9f93b7b226e5d4f1ff904c Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Mon, 26 Aug 2019 09:39:41 -0700 Subject: [PATCH] Bypass Borg error about a moved repository (#209). --- NEWS | 4 ++++ borgmatic/borg/environment.py | 12 ++++++++++++ borgmatic/config/schema.yaml | 10 ++++++++++ setup.py | 2 +- tests/unit/borg/test_environment.py | 18 ++++++++++++++++-- 5 files changed, 43 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 8a6caf2..f054e72 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,7 @@ +1.3.15.dev0 + * #209: Bypass Borg error about a moved repository via "relocated_repo_access_is_ok" option in + borgmatic storage configuration section. + 1.3.14 * #204: Do not treat Borg warnings (exit code 1) as failures. * When validating configuration files, require strings instead of allowing any scalar type. diff --git a/borgmatic/borg/environment.py b/borgmatic/borg/environment.py index 2dde10c..7287269 100644 --- a/borgmatic/borg/environment.py +++ b/borgmatic/borg/environment.py @@ -11,9 +11,21 @@ OPTION_TO_ENVIRONMENT_VARIABLE = { 'ssh_command': 'BORG_RSH', } +DEFAULT_BOOL_OPTION_TO_ENVIRONMENT_VARIABLE = { + 'relocated_repo_access_is_ok': 'BORG_RELOCATED_REPO_ACCESS_IS_OK', + 'unknown_unencrypted_repo_access_is_ok': 'BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK', +} + def initialize(storage_config): for option_name, environment_variable_name in OPTION_TO_ENVIRONMENT_VARIABLE.items(): value = storage_config.get(option_name) if value: os.environ[environment_variable_name] = value + + for ( + option_name, + environment_variable_name, + ) in DEFAULT_BOOL_OPTION_TO_ENVIRONMENT_VARIABLE.items(): + value = storage_config.get(option_name, False) + os.environ[environment_variable_name] = 'yes' if value else 'no' diff --git a/borgmatic/config/schema.yaml b/borgmatic/config/schema.yaml index db18521..521dce7 100644 --- a/borgmatic/config/schema.yaml +++ b/borgmatic/config/schema.yaml @@ -224,6 +224,16 @@ map: archives with a different archive name format. And you should also specify a prefix in the consistency section as well. example: "{hostname}-documents-{now}" + relocated_repo_access_is_ok: + type: bool + desc: Bypass Borg error about a repository that has been moved. Defaults to false. + example: true + unknown_unencrypted_repo_access_is_ok: + type: bool + desc: | + Bypass Borg error about a previously unknown unencrypted repository. Defaults to + false. + example: true retention: desc: | Retention policy for how many backups to keep in each category. See diff --git a/setup.py b/setup.py index 4d7911d..dc6b619 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -VERSION = '1.3.14' +VERSION = '1.3.15.dev0' setup( diff --git a/tests/unit/borg/test_environment.py b/tests/unit/borg/test_environment.py index 9fa25b1..075d992 100644 --- a/tests/unit/borg/test_environment.py +++ b/tests/unit/borg/test_environment.py @@ -36,13 +36,27 @@ def test_initialize_with_ssh_command_should_set_environment(): os.environ = orig_environ -def test_initialize_without_configuration_should_not_set_environment(): +def test_initialize_without_configuration_should_only_set_default_environment(): orig_environ = os.environ try: os.environ = {} module.initialize({}) - assert sum(1 for key in os.environ.keys() if key.startswith('BORG_')) == 0 + assert {key: value for key, value in os.environ.items() if key.startswith('BORG_')} == { + 'BORG_RELOCATED_REPO_ACCESS_IS_OK': 'no', + 'BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK': 'no', + } + finally: + os.environ = orig_environ + + +def test_initialize_with_relocated_repo_access_should_override_default(): + orig_environ = os.environ + + try: + os.environ = {} + module.initialize({'relocated_repo_access_is_ok': True}) + assert os.environ.get('BORG_RELOCATED_REPO_ACCESS_IS_OK') == 'yes' finally: os.environ = orig_environ