2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-18 16:42:00 +00:00
restic/internal/backend/rclone/config.go

47 lines
1.3 KiB
Go
Raw Normal View History

2018-03-13 21:30:51 +00:00
package rclone
import (
"strings"
"time"
2018-03-13 21:30:51 +00:00
"github.com/restic/restic/internal/errors"
"github.com/restic/restic/internal/options"
)
// Config contains all configuration necessary to start rclone.
type Config struct {
Program string `option:"program" help:"path to rclone (default: rclone)"`
Args string `option:"args" help:"arguments for running rclone (default: serve restic --stdio --b2-hard-delete)"`
Remote string
Connections uint `option:"connections" help:"set a limit for the number of concurrent connections (default: 5)"`
Timeout time.Duration `option:"timeout" help:"set a timeout limit to wait for rclone to establish a connection (default: 1m)"`
2018-03-13 21:30:51 +00:00
}
var defaultConfig = Config{
Program: "rclone",
Args: "serve restic --stdio --b2-hard-delete",
Connections: 5,
2021-11-07 16:47:18 +00:00
Timeout: time.Minute,
}
2018-03-13 21:30:51 +00:00
func init() {
options.Register("rclone", Config{})
}
// NewConfig returns a new Config with the default values filled in.
func NewConfig() Config {
return defaultConfig
2018-03-13 21:30:51 +00:00
}
// ParseConfig parses the string s and extracts the remote server URL.
func ParseConfig(s string) (*Config, error) {
2018-03-13 21:30:51 +00:00
if !strings.HasPrefix(s, "rclone:") {
return nil, errors.New("invalid rclone backend specification")
2018-03-13 21:30:51 +00:00
}
s = s[7:]
cfg := NewConfig()
cfg.Remote = s
return &cfg, nil
2018-03-13 21:30:51 +00:00
}