mirror of
https://github.com/cupcakearmy/autorestic.git
synced 2024-12-22 00:06:25 +00:00
allow options for backend
This commit is contained in:
parent
41736ea3c4
commit
61673bd88b
@ -17,12 +17,13 @@ type BackendRest struct {
|
||||
}
|
||||
|
||||
type Backend struct {
|
||||
name string
|
||||
Type string `yaml:"type,omitempty"`
|
||||
Path string `yaml:"path,omitempty"`
|
||||
Key string `yaml:"key,omitempty"`
|
||||
Env map[string]string `yaml:"env,omitempty"`
|
||||
Rest BackendRest `yaml:"rest,omitempty"`
|
||||
name string
|
||||
Type string `yaml:"type,omitempty"`
|
||||
Path string `yaml:"path,omitempty"`
|
||||
Key string `yaml:"key,omitempty"`
|
||||
Env map[string]string `yaml:"env,omitempty"`
|
||||
Rest BackendRest `yaml:"rest,omitempty"`
|
||||
Options Options `yaml:"options,omitempty"`
|
||||
}
|
||||
|
||||
func GetBackend(name string) (Backend, bool) {
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
const VERSION = "1.1.0"
|
||||
const VERSION = "1.1.1"
|
||||
|
||||
var CI bool = false
|
||||
var VERBOSE bool = false
|
||||
@ -220,3 +220,13 @@ func (c *Config) SaveConfig() error {
|
||||
|
||||
return viper.WriteConfig()
|
||||
}
|
||||
|
||||
func getOptions(options Options, key string) []string {
|
||||
var selected []string
|
||||
for k, values := range options[key] {
|
||||
for _, value := range values {
|
||||
selected = append(selected, fmt.Sprintf("--%s", k), value)
|
||||
}
|
||||
}
|
||||
return selected
|
||||
}
|
||||
|
@ -78,17 +78,6 @@ func (l Location) validate(c *Config) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l Location) getOptions(key string) []string {
|
||||
var options []string
|
||||
saved := l.Options[key]
|
||||
for k, values := range saved {
|
||||
for _, value := range values {
|
||||
options = append(options, fmt.Sprintf("--%s", k), value)
|
||||
}
|
||||
}
|
||||
return options
|
||||
}
|
||||
|
||||
func ExecuteHooks(commands []string, options ExecuteOptions) error {
|
||||
if len(commands) == 0 {
|
||||
return nil
|
||||
@ -164,9 +153,11 @@ func (l Location) Backup(cron bool) []error {
|
||||
continue
|
||||
}
|
||||
|
||||
flags := l.getOptions("backup")
|
||||
lFlags := getOptions(l.Options, "backup")
|
||||
bFlags := getOptions(backend.Options, "backup")
|
||||
cmd := []string{"backup"}
|
||||
cmd = append(cmd, flags...)
|
||||
cmd = append(cmd, lFlags...)
|
||||
cmd = append(cmd, bFlags...)
|
||||
if cron {
|
||||
cmd = append(cmd, "--tag", "cron")
|
||||
}
|
||||
@ -232,7 +223,8 @@ func (l Location) Forget(prune bool, dry bool) error {
|
||||
options := ExecuteOptions{
|
||||
Envs: env,
|
||||
}
|
||||
flags := l.getOptions("forget")
|
||||
lFlags := getOptions(l.Options, "forget")
|
||||
bFlags := getOptions(backend.Options, "forget")
|
||||
cmd := []string{"forget", "--path", path}
|
||||
if prune {
|
||||
cmd = append(cmd, "--prune")
|
||||
@ -240,7 +232,8 @@ func (l Location) Forget(prune bool, dry bool) error {
|
||||
if dry {
|
||||
cmd = append(cmd, "--dry-run")
|
||||
}
|
||||
cmd = append(cmd, flags...)
|
||||
cmd = append(cmd, lFlags...)
|
||||
cmd = append(cmd, bFlags...)
|
||||
out, err := ExecuteResticCommand(options, cmd...)
|
||||
if VERBOSE {
|
||||
colors.Faint.Println(out)
|
||||
|
Loading…
Reference in New Issue
Block a user