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.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

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

@@ -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):
'''

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

@@ -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']:

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

@@ -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.

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

@@ -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


Loading…
Cancel
Save