diff --git a/NEWS b/NEWS index 8a6caf29..f054e72c 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 2dde10cd..72872690 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 db18521f..521dce7b 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 4d7911d0..dc6b6198 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 9fa25b19..075d9929 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