From a0ef4e25ddbc36e2004a8fa6f035890b8cb17e0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Mon, 5 Oct 2015 18:54:00 -0400 Subject: [PATCH] add support for arbitrary SSH commands (attic#99) while SSH options can be specified through `~/.ssh/config`, some users may want to use a completely different SSH command for their backups, without overriding their $PATH variable. it may also be easier to do ad-hoc configuration and tests that way. plus, the POLA tells us that users expects something like this to be supported by commands that talk to ssh. it is supported by rsync, git and so on. --- borg/remote.py | 3 ++- borg/testsuite/repository.py | 2 ++ docs/usage.rst | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/borg/remote.py b/borg/remote.py index 19a1416a0..c9d8145ba 100644 --- a/borg/remote.py +++ b/borg/remote.py @@ -3,6 +3,7 @@ import fcntl import msgpack import os import select +import shlex from subprocess import Popen, PIPE import sys import tempfile @@ -160,7 +161,7 @@ class RemoteRepository: return ['--umask', '%03o' % self.umask] def ssh_cmd(self, location): - args = ['ssh'] + args = shlex.split(os.environ.get('BORG_RSH', 'ssh')) if location.port: args += ['-p', str(location.port)] if location.user: diff --git a/borg/testsuite/repository.py b/borg/testsuite/repository.py index 5df0a6f97..5a1524ed9 100644 --- a/borg/testsuite/repository.py +++ b/borg/testsuite/repository.py @@ -328,6 +328,8 @@ class RemoteRepositoryTestCase(RepositoryTestCase): def test_ssh_cmd(self): assert self.repository.umask is not None assert self.repository.ssh_cmd(Location('example.com:foo')) == ['ssh', 'example.com', 'borg', 'serve'] + self.repository.umask_flag() + os.environ['BORG_RSH'] = 'ssh --foo' + assert self.repository.ssh_cmd(Location('example.com:foo')) == ['ssh', '--foo', 'example.com', 'borg', 'serve'] + self.repository.umask_flag() class RemoteRepositoryCheckTestCase(RepositoryCheckTestCase): diff --git a/docs/usage.rst b/docs/usage.rst index 95b95d90d..6bd292e14 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -48,6 +48,8 @@ General: can either leave it away or abbreviate as `::`, if a positional parameter is required. BORG_PASSPHRASE When set, use the value to answer the passphrase question for encrypted repositories. + BORG_RSH + When set, use this command instead of ``ssh``. TMPDIR where temporary files are stored (might need a lot of temporary space for some operations)