From 425e27dee5443e3121d18340b990974a6de51071 Mon Sep 17 00:00:00 2001 From: Dan Date: Fri, 3 Nov 2017 22:01:04 -0700 Subject: [PATCH] Add "ssh_command" to configuration for specifying a custom SSH command or options. --- NEWS | 2 +- borgmatic/borg/create.py | 7 +++++-- borgmatic/commands/borgmatic.py | 2 +- borgmatic/config/schema.yaml | 4 ++++ borgmatic/tests/unit/borg/test_create.py | 20 ++++++++++++++++---- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index a6d244d43..71086dc62 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,5 @@ 1.1.11.dev0 - * + * #25: Add "ssh_command" to configuration for specifying a custom SSH command or options. 1.1.10 * Pass several Unix signals through to child processes like Borg. This means that Borg now properly diff --git a/borgmatic/borg/create.py b/borgmatic/borg/create.py index 6f0d7246d..755aff612 100644 --- a/borgmatic/borg/create.py +++ b/borgmatic/borg/create.py @@ -11,12 +11,15 @@ from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS logger = logging.getLogger(__name__) -def initialize(storage_config): +def initialize_environment(storage_config): passphrase = storage_config.get('encryption_passphrase') - if passphrase: os.environ['BORG_PASSPHRASE'] = passphrase + ssh_command = storage_config.get('ssh_command') + if ssh_command: + os.environ['BORG_RSH'] = ssh_command + def _expand_directory(directory): ''' diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index ad3e2972f..a1ecff764 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -94,7 +94,7 @@ def run_configuration(config_filename, args): # pragma: no cover try: remote_path = location.get('remote_path') - create.initialize(storage) + create.initialize_environment(storage) hook.execute_hook(hooks.get('before_backup'), config_filename, 'pre-backup') for unexpanded_repository in location['repositories']: diff --git a/borgmatic/config/schema.yaml b/borgmatic/config/schema.yaml index 69a660ad8..b98967af3 100644 --- a/borgmatic/config/schema.yaml +++ b/borgmatic/config/schema.yaml @@ -96,6 +96,10 @@ map: type: int desc: Remote network upload rate limit in kiBytes/second. example: 100 + ssh_command: + type: scalar + desc: Command to use instead of just "ssh". This can be used to specify ssh options. + example: ssh -i /path/to/private/key umask: type: scalar desc: Umask to be used for borg create. diff --git a/borgmatic/tests/unit/borg/test_create.py b/borgmatic/tests/unit/borg/test_create.py index 045aa5210..30fb3ecba 100644 --- a/borgmatic/tests/unit/borg/test_create.py +++ b/borgmatic/tests/unit/borg/test_create.py @@ -6,24 +6,36 @@ from borgmatic.borg import create as module from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS -def test_initialize_with_passphrase_should_set_environment(): +def test_initialize_environment_with_passphrase_should_set_environment(): orig_environ = os.environ try: os.environ = {} - module.initialize({'encryption_passphrase': 'pass'}) + module.initialize_environment({'encryption_passphrase': 'pass'}) assert os.environ.get('BORG_PASSPHRASE') == 'pass' finally: os.environ = orig_environ -def test_initialize_without_passphrase_should_not_set_environment(): +def test_initialize_environment_with_ssh_command_should_set_environment(): orig_environ = os.environ try: os.environ = {} - module.initialize({}) + module.initialize_environment({'ssh_command': 'ssh -C'}) + assert os.environ.get('BORG_RSH') == 'ssh -C' + finally: + os.environ = orig_environ + + +def test_initialize_environment_without_configuration_should_not_set_environment(): + orig_environ = os.environ + + try: + os.environ = {} + module.initialize_environment({}) assert os.environ.get('BORG_PASSPHRASE') == None + assert os.environ.get('BORG_RSH') == None finally: os.environ = orig_environ