mirror of
https://github.com/kopia/kopia.git
synced 2026-02-05 12:13:29 -05:00
Uses go/ssh and pkg/sftp as building blocks and implements the common sharded.Storage interface, shared between the filesystem and webdav providers. A couple of notes: - The provider assumes the user has a working public/private key connection to the ssh server. No other authentication method is supported - The repository path must exist on the server - (testing related) The pkg/sftp server doesn't offer a way to set a server filesystem root, so, during testing, it runs from the local directory which is repo/blob/sftp. So the tests leave some debris behind. Additionally, that's the reason why id_rsa and known_hosts are there at all. - Encrypted keyfiles are currently not supported (but it could be done)
39 lines
1.0 KiB
Go
39 lines
1.0 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
|
|
"gopkg.in/alecthomas/kingpin.v2"
|
|
|
|
"github.com/kopia/kopia/repo/blob"
|
|
"github.com/kopia/kopia/repo/blob/sftp"
|
|
)
|
|
|
|
func init() {
|
|
var (
|
|
options sftp.Options
|
|
connectFlat bool
|
|
)
|
|
|
|
RegisterStorageConnectFlags(
|
|
"sftp",
|
|
"an sftp storage",
|
|
func(cmd *kingpin.CmdClause) {
|
|
cmd.Flag("path", "Path to the repository in the SFTP/SSH server").Required().StringVar(&options.Path)
|
|
cmd.Flag("host", "SFTP/SSH server hostname").Required().StringVar(&options.Host)
|
|
cmd.Flag("port", "SFTP/SSH server port").Default("22").IntVar(&options.Port)
|
|
cmd.Flag("username", "SFTP/SSH server username").Required().StringVar(&options.Username)
|
|
cmd.Flag("keyfile", "path to private key file for SFTP/SSH server").Required().StringVar(&options.Keyfile)
|
|
cmd.Flag("flat", "Use flat directory structure").BoolVar(&connectFlat)
|
|
},
|
|
func(ctx context.Context, isNew bool) (blob.Storage, error) {
|
|
sftpo := options
|
|
|
|
if connectFlat {
|
|
sftpo.DirectoryShards = []int{}
|
|
}
|
|
|
|
return sftp.New(ctx, &sftpo)
|
|
})
|
|
}
|