Browse Source

Add "ssh_command" to configuration for specifying a custom SSH command or options.

master
Dan 1 year ago
parent
commit
425e27dee5

+ 1
- 1
NEWS View File

@@ -1,5 +1,5 @@
1 1
 1.1.11.dev0
2
- * 
2
+ * #25: Add "ssh_command" to configuration for specifying a custom SSH command or options.
3 3
 
4 4
 1.1.10
5 5
  * Pass several Unix signals through to child processes like Borg. This means that Borg now properly

+ 5
- 2
borgmatic/borg/create.py View File

@@ -11,12 +11,15 @@ from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS
11 11
 logger = logging.getLogger(__name__)
12 12
 
13 13
 
14
-def initialize(storage_config):
14
+def initialize_environment(storage_config):
15 15
     passphrase = storage_config.get('encryption_passphrase')
16
-
17 16
     if passphrase:
18 17
         os.environ['BORG_PASSPHRASE'] = passphrase
19 18
 
19
+    ssh_command = storage_config.get('ssh_command')
20
+    if ssh_command:
21
+        os.environ['BORG_RSH'] = ssh_command
22
+
20 23
 
21 24
 def _expand_directory(directory):
22 25
     '''

+ 1
- 1
borgmatic/commands/borgmatic.py View File

@@ -94,7 +94,7 @@ def run_configuration(config_filename, args):  # pragma: no cover
94 94
 
95 95
     try:
96 96
         remote_path = location.get('remote_path')
97
-        create.initialize(storage)
97
+        create.initialize_environment(storage)
98 98
         hook.execute_hook(hooks.get('before_backup'), config_filename, 'pre-backup')
99 99
 
100 100
         for unexpanded_repository in location['repositories']:

+ 4
- 0
borgmatic/config/schema.yaml View File

@@ -96,6 +96,10 @@ map:
96 96
                 type: int
97 97
                 desc: Remote network upload rate limit in kiBytes/second.
98 98
                 example: 100
99
+            ssh_command:
100
+                type: scalar
101
+                desc: Command to use instead of just "ssh". This can be used to specify ssh options.
102
+                example: ssh -i /path/to/private/key
99 103
             umask:
100 104
                 type: scalar
101 105
                 desc: Umask to be used for borg create.

+ 16
- 4
borgmatic/tests/unit/borg/test_create.py View File

@@ -6,24 +6,36 @@ from borgmatic.borg import create as module
6 6
 from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS
7 7
 
8 8
 
9
-def test_initialize_with_passphrase_should_set_environment():
9
+def test_initialize_environment_with_passphrase_should_set_environment():
10 10
     orig_environ = os.environ
11 11
 
12 12
     try:
13 13
         os.environ = {}
14
-        module.initialize({'encryption_passphrase': 'pass'})
14
+        module.initialize_environment({'encryption_passphrase': 'pass'})
15 15
         assert os.environ.get('BORG_PASSPHRASE') == 'pass'
16 16
     finally:
17 17
         os.environ = orig_environ
18 18
 
19 19
 
20
-def test_initialize_without_passphrase_should_not_set_environment():
20
+def test_initialize_environment_with_ssh_command_should_set_environment():
21 21
     orig_environ = os.environ
22 22
 
23 23
     try:
24 24
         os.environ = {}
25
-        module.initialize({})
25
+        module.initialize_environment({'ssh_command': 'ssh -C'})
26
+        assert os.environ.get('BORG_RSH') == 'ssh -C'
27
+    finally:
28
+        os.environ = orig_environ
29
+
30
+
31
+def test_initialize_environment_without_configuration_should_not_set_environment():
32
+    orig_environ = os.environ
33
+
34
+    try:
35
+        os.environ = {}
36
+        module.initialize_environment({})
26 37
         assert os.environ.get('BORG_PASSPHRASE') == None
38
+        assert os.environ.get('BORG_RSH') == None
27 39
     finally:
28 40
         os.environ = orig_environ
29 41
 

Loading…
Cancel
Save