浏览代码

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.
Antoine Beaupré 9 年之前
父节点
当前提交
a0ef4e25dd
共有 3 个文件被更改,包括 6 次插入1 次删除
  1. 2 1
      borg/remote.py
  2. 2 0
      borg/testsuite/repository.py
  3. 2 0
      docs/usage.rst

+ 2 - 1
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:

+ 2 - 0
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):

+ 2 - 0
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)