mirror of
https://github.com/cupcakearmy/autorestic.git
synced 2024-12-22 08:16:25 +00:00
Use options when calling check or init (#199)
This commit is contained in:
parent
83eeb847ac
commit
b830667264
@ -122,13 +122,17 @@ func (b Backend) validate() error {
|
||||
}
|
||||
options := ExecuteOptions{Envs: env, Silent: true}
|
||||
// Check if already initialized
|
||||
_, _, err = ExecuteResticCommand(options, "check")
|
||||
cmd := []string{"check"}
|
||||
cmd = append(cmd, combineBackendOptions("check", b)...)
|
||||
_, _, err = ExecuteResticCommand(options, cmd...)
|
||||
if err == nil {
|
||||
return nil
|
||||
} else {
|
||||
// If not initialize
|
||||
colors.Body.Printf("Initializing backend \"%s\"...\n", b.name)
|
||||
_, _, err := ExecuteResticCommand(options, "init")
|
||||
cmd := []string{"init"}
|
||||
cmd = append(cmd, combineBackendOptions("init", b)...)
|
||||
_, _, err := ExecuteResticCommand(options, cmd...)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -303,7 +303,17 @@ func getOptions(options Options, keys []string) []string {
|
||||
return selected
|
||||
}
|
||||
|
||||
func combineOptions(key string, l Location, b Backend) []string {
|
||||
func combineBackendOptions(key string, b Backend) []string {
|
||||
// Priority: backend > global
|
||||
var options []string
|
||||
gFlags := getOptions(GetConfig().Global, []string{key})
|
||||
bFlags := getOptions(b.Options, []string{"all", key})
|
||||
options = append(options, gFlags...)
|
||||
options = append(options, bFlags...)
|
||||
return options
|
||||
}
|
||||
|
||||
func combineAllOptions(key string, l Location, b Backend) []string {
|
||||
// Priority: location > backend > global
|
||||
var options []string
|
||||
gFlags := getOptions(GetConfig().Global, []string{key})
|
||||
|
@ -216,7 +216,7 @@ func (l Location) Backup(cron bool, specificBackend string) []error {
|
||||
}
|
||||
|
||||
cmd := []string{"backup"}
|
||||
cmd = append(cmd, combineOptions("backup", l, backend)...)
|
||||
cmd = append(cmd, combineAllOptions("backup", l, backend)...)
|
||||
if cron {
|
||||
cmd = append(cmd, "--tag", buildTag("cron"))
|
||||
}
|
||||
@ -342,7 +342,7 @@ func (l Location) Forget(prune bool, dry bool) error {
|
||||
if dry {
|
||||
cmd = append(cmd, "--dry-run")
|
||||
}
|
||||
cmd = append(cmd, combineOptions("forget", l, backend)...)
|
||||
cmd = append(cmd, combineAllOptions("forget", l, backend)...)
|
||||
_, _, err = ExecuteResticCommand(options, cmd...)
|
||||
if err != nil {
|
||||
return err
|
||||
|
Loading…
Reference in New Issue
Block a user