Browse Source

Bypass Borg error about a moved repository (#209).

Dan Helfman 5 years ago
parent
commit
ef3dda9213
5 changed files with 43 additions and 3 deletions
  1. 4 0
      NEWS
  2. 12 0
      borgmatic/borg/environment.py
  3. 10 0
      borgmatic/config/schema.yaml
  4. 1 1
      setup.py
  5. 16 2
      tests/unit/borg/test_environment.py

+ 4 - 0
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.

+ 12 - 0
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'

+ 10 - 0
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

+ 1 - 1
setup.py

@@ -1,6 +1,6 @@
 from setuptools import find_packages, setup
 
-VERSION = '1.3.14'
+VERSION = '1.3.15.dev0'
 
 
 setup(

+ 16 - 2
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