Merge pull request #4912 from MichaelEischer/restore-delete-preserve-root

restore: forbid --target / --delete unless include/exclude is specified
This commit is contained in:
Michael Eischer 2024-07-08 20:14:44 +02:00 committed by GitHub
commit c309ffb35b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,6 +2,7 @@ package main
import ( import (
"context" "context"
"path/filepath"
"time" "time"
"github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/debug"
@ -107,6 +108,10 @@ func runRestore(ctx context.Context, opts RestoreOptions, gopts GlobalOptions,
return errors.Fatal("--dry-run and --verify are mutually exclusive") return errors.Fatal("--dry-run and --verify are mutually exclusive")
} }
if opts.Delete && filepath.Clean(opts.Target) == "/" && !hasExcludes && !hasIncludes {
return errors.Fatal("'--target / --delete' must be combined with an include or exclude filter")
}
snapshotIDString := args[0] snapshotIDString := args[0]
debug.Log("restore %v to %v", snapshotIDString, opts.Target) debug.Log("restore %v to %v", snapshotIDString, opts.Target)