From 1733b24f9d462407e8fe9893332e2f1cc093076a Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 25 Mar 2017 09:06:46 +0100 Subject: [PATCH] doc: Add section about how to change the sftp port Closes #895 Related to #785 --- doc/Manual.md | 34 +++++++++++++++++++++++++++++++ src/restic/backend/sftp/config.go | 7 +++---- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/doc/Manual.md b/doc/Manual.md index d4747190b..bbf2e7714 100644 --- a/doc/Manual.md +++ b/doc/Manual.md @@ -517,6 +517,40 @@ You can also specify a relative (read: no slash (`/`) character at the beginning) directory, in this case the dir is relative to the remote user's home directory. +The backend config string does not allow specifying a port. If you need to +contact an sftp server on a different port, you can create an entry in the +`ssh` file, usually located in your user's home directory at `~/.ssh/config` or +in `/etc/ssh/ssh_config`: + +``` +Host foo + User bar + Port 2222 +``` + +Then use the specified host name `foo` normally (you don't need to specify the +user name in this case): + +``` +$ restic -r sftp:foo:/tmp/backup init +``` + +You can also add an entry with a special host name which does not exist, just +for use with restic, and use the `Hostname` option to set the real host name: + +``` +Host restic-backup-host + Hostname foo + User bar + Port 2222 +``` + +Then use it in the backend specification: + +``` +$ restic -r sftp:restic-backup-host:/tmp/backup init +``` + # Create a REST server repository In order to backup data to the remote server via HTTP or HTTPS protocol, diff --git a/src/restic/backend/sftp/config.go b/src/restic/backend/sftp/config.go index abd8b0c2f..c5b65e639 100644 --- a/src/restic/backend/sftp/config.go +++ b/src/restic/backend/sftp/config.go @@ -15,10 +15,9 @@ type Config struct { // ParseConfig parses the string s and extracts the sftp config. The // supported configuration formats are sftp://user@host/directory -// (with an optional port sftp://user@host:port/directory) and -// sftp:user@host:directory. The directory will be path Cleaned and -// can be an absolute path if it starts with a '/' -// (e.g. sftp://user@host//absolute and sftp:user@host:/absolute). +// and sftp:user@host:directory. The directory will be path Cleaned and can +// be an absolute path if it starts with a '/' (e.g. +// sftp://user@host//absolute and sftp:user@host:/absolute). func ParseConfig(s string) (interface{}, error) { var user, host, dir string switch {