|
|
@ -70,47 +70,56 @@ func ExecuteHooks(commands []string, options ExecuteOptions) error {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (l Location) Backup() error {
|
|
|
|
func (l Location) forEachBackend(fn func(ExecuteOptions) error) error {
|
|
|
|
from := GetPathRelativeToConfig(l.From)
|
|
|
|
from, err := GetPathRelativeToConfig(l.From)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
for _, to := range l.To {
|
|
|
|
for _, to := range l.To {
|
|
|
|
backend, _ := GetBackend(to)
|
|
|
|
backend, _ := GetBackend(to)
|
|
|
|
|
|
|
|
env, err := backend.getEnv()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
options := ExecuteOptions{
|
|
|
|
options := ExecuteOptions{
|
|
|
|
Command: "bash",
|
|
|
|
Command: "bash",
|
|
|
|
Envs: backend.getEnv(),
|
|
|
|
Envs: env,
|
|
|
|
Dir: from,
|
|
|
|
Dir: from,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := fn(options); err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (l Location) Backup() error {
|
|
|
|
|
|
|
|
return l.forEachBackend(func(options ExecuteOptions) error {
|
|
|
|
if err := ExecuteHooks(l.Hooks.Before, options); err != nil {
|
|
|
|
if err := ExecuteHooks(l.Hooks.Before, options); err != nil {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
|
|
|
|
flags := l.getOptions("backup")
|
|
|
|
flags := l.getOptions("backup")
|
|
|
|
cmd := []string{"backup"}
|
|
|
|
cmd := []string{"backup"}
|
|
|
|
cmd = append(cmd, flags...)
|
|
|
|
cmd = append(cmd, flags...)
|
|
|
|
cmd = append(cmd, ".")
|
|
|
|
cmd = append(cmd, ".")
|
|
|
|
out, err := ExecuteResticCommand(options, cmd...)
|
|
|
|
out, err := ExecuteResticCommand(options, cmd...)
|
|
|
|
fmt.Println(out)
|
|
|
|
fmt.Println(out)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if err := ExecuteHooks(l.Hooks.After, options); err != nil {
|
|
|
|
if err := ExecuteHooks(l.Hooks.After, options); err != nil {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (l Location) Forget(prune bool, dry bool) error {
|
|
|
|
func (l Location) Forget(prune bool, dry bool) error {
|
|
|
|
from := GetPathRelativeToConfig(l.From)
|
|
|
|
return l.forEachBackend(func(options ExecuteOptions) error {
|
|
|
|
for _, to := range l.To {
|
|
|
|
|
|
|
|
backend, _ := GetBackend(to)
|
|
|
|
|
|
|
|
options := ExecuteOptions{
|
|
|
|
|
|
|
|
Envs: backend.getEnv(),
|
|
|
|
|
|
|
|
Dir: from,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
flags := l.getOptions("forget")
|
|
|
|
flags := l.getOptions("forget")
|
|
|
|
cmd := []string{"forget", "--path", from}
|
|
|
|
cmd := []string{"forget", "--path", options.Dir}
|
|
|
|
if prune {
|
|
|
|
if prune {
|
|
|
|
cmd = append(cmd, "--prune")
|
|
|
|
cmd = append(cmd, "--prune")
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -123,8 +132,8 @@ func (l Location) Forget(prune bool, dry bool) error {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (l Location) hasBackend(backend string) bool {
|
|
|
|
func (l Location) hasBackend(backend string) bool {
|
|
|
@ -169,7 +178,11 @@ func (l Location) Restore(to, from string, force bool) error {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
backend, _ := GetBackend(from)
|
|
|
|
backend, _ := GetBackend(from)
|
|
|
|
err = backend.Exec([]string{"restore", "--target", to, "--path", GetPathRelativeToConfig(l.From), "latest"})
|
|
|
|
resolved, err := GetPathRelativeToConfig(l.From)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
err = backend.Exec([]string{"restore", "--target", to, "--path", resolved, "latest"})
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|