mirror of
https://github.com/cupcakearmy/autorestic.git
synced 2025-09-07 19:10:39 +00:00
current state
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/cupcakearmy/autorestic/internal/colors"
|
||||
"github.com/cupcakearmy/autorestic/internal/lock"
|
||||
"github.com/robfig/cron"
|
||||
)
|
||||
@@ -71,11 +72,17 @@ func (l Location) getOptions(key string) []string {
|
||||
}
|
||||
|
||||
func ExecuteHooks(commands []string, options ExecuteOptions) error {
|
||||
if len(commands) == 0 {
|
||||
return nil
|
||||
}
|
||||
colors.Secondary.Println("🪝 Running hooks")
|
||||
for _, command := range commands {
|
||||
colors.Body.Println(command)
|
||||
out, err := ExecuteCommand(options, "-c", command)
|
||||
fmt.Println(out)
|
||||
colors.Faint.Print(out)
|
||||
return err
|
||||
}
|
||||
fmt.Println("")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -103,26 +110,47 @@ func (l Location) forEachBackend(fn func(ExecuteOptions) error) error {
|
||||
}
|
||||
|
||||
func (l Location) Backup() error {
|
||||
return l.forEachBackend(func(options ExecuteOptions) error {
|
||||
if err := ExecuteHooks(l.Hooks.Before, options); err != nil {
|
||||
fmt.Printf("\n\n")
|
||||
colors.Primary.Printf("💽 Backing up location \"%s\"", l.Name)
|
||||
fmt.Printf("\n")
|
||||
from, err := GetPathRelativeToConfig(l.From)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
options := ExecuteOptions{
|
||||
Command: "bash",
|
||||
Dir: from,
|
||||
}
|
||||
if err := ExecuteHooks(l.Hooks.Before, options); err != nil {
|
||||
return nil
|
||||
}
|
||||
for _, to := range l.To {
|
||||
backend, _ := GetBackend(to)
|
||||
colors.Secondary.Printf("Backend: %s\n", backend.Name)
|
||||
env, err := backend.getEnv()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
options := ExecuteOptions{
|
||||
Command: "restic",
|
||||
Dir: from,
|
||||
Envs: env,
|
||||
}
|
||||
flags := l.getOptions("backup")
|
||||
cmd := []string{"backup"}
|
||||
cmd = append(cmd, flags...)
|
||||
cmd = append(cmd, ".")
|
||||
out, err := ExecuteResticCommand(options, cmd...)
|
||||
fmt.Println(out)
|
||||
colors.Faint.Print(out)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := ExecuteHooks(l.Hooks.After, options); err != nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
if err := ExecuteHooks(l.Hooks.After, options); err != nil {
|
||||
return nil
|
||||
})
|
||||
}
|
||||
colors.Success.Println("✅ Done")
|
||||
return err
|
||||
}
|
||||
|
||||
func (l Location) Forget(prune bool, dry bool) error {
|
||||
|
Reference in New Issue
Block a user