From 1856f4d87a076315d1095a87d2c338391259a630 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 7 Jul 2024 13:54:45 +0200 Subject: [PATCH] restore: forbid --target / --delete unless include/exclude is specified --- cmd/restic/cmd_restore.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmd/restic/cmd_restore.go b/cmd/restic/cmd_restore.go index 1835219ad..e21d0bd94 100644 --- a/cmd/restic/cmd_restore.go +++ b/cmd/restic/cmd_restore.go @@ -2,6 +2,7 @@ package main import ( "context" + "path/filepath" "time" "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") } + 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] debug.Log("restore %v to %v", snapshotIDString, opts.Target)