From 25350a9c55fab726106bb8fbc4adbabe399d6ee7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Ho=C3=9F?= Date: Thu, 16 Mar 2023 07:47:31 +0100 Subject: [PATCH] Extend SnapshotOptions w/ command data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In order to determine whether to save a snapshot, we need to capture the exit code returned by a command. In order to provide a nice error message, we supply stderr as well. Signed-off-by: Sebastian Hoß --- cmd/restic/cmd_backup.go | 2 ++ internal/archiver/archiver.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/cmd/restic/cmd_backup.go b/cmd/restic/cmd_backup.go index 3f494a8cf..798d5609c 100644 --- a/cmd/restic/cmd_backup.go +++ b/cmd/restic/cmd_backup.go @@ -676,6 +676,8 @@ func runBackup(ctx context.Context, opts BackupOptions, gopts GlobalOptions, ter Hostname: opts.Host, ParentSnapshot: parentSnapshot, ProgramVersion: "restic " + version, + Command: command, + CommandStderr: stderr, } if !gopts.JSON { diff --git a/internal/archiver/archiver.go b/internal/archiver/archiver.go index 98819d797..ed1eb62bd 100644 --- a/internal/archiver/archiver.go +++ b/internal/archiver/archiver.go @@ -2,7 +2,9 @@ package archiver import ( "context" + "io" "os" + "os/exec" "path" "runtime" "sort" @@ -681,6 +683,8 @@ type SnapshotOptions struct { Time time.Time ParentSnapshot *restic.Snapshot ProgramVersion string + Command *exec.Cmd + CommandStderr io.ReadCloser } // loadParentTree loads a tree referenced by snapshot id. If id is null, nil is returned.