From 9d1b9c68fd7548ffeff60ca60d4c518ac9cd9bb4 Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Wed, 25 Oct 2023 20:01:37 -0700 Subject: [PATCH] WIP: Automatically set restore target to `/` if all backup paths are absolute --- tasks.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tasks.go b/tasks.go index 496c63f..03fd757 100644 --- a/tasks.go +++ b/tasks.go @@ -6,6 +6,7 @@ import ( "io/fs" "log" "os" + "path" "strings" ) @@ -405,6 +406,23 @@ func (t BackupFilesTask) RunRestore(cfg TaskConfig) error { t.RestoreOpts = &RestoreOpts{} //nolint:exhaustruct } + // If all backup paths are absolute and target is empty, use root as the restore target + if t.RestoreOpts.Target == "" { + allAbs := true + + for _, backupPath := range t.Paths { + if !path.IsAbs(backupPath) { + allAbs = false + + break + } + } + + if allAbs { + t.RestoreOpts.Target = "/" + } + } + if t.snapshot == "" { t.snapshot = "latest" }