2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-25 06:07:44 +00:00

Check command result before snapshotting

Return with an error containing the stderr of the given command in case it fails. No new snapshot will be created and future prune operations on the repository will remove the unreferenced data.

Signed-off-by: Sebastian Hoß <seb@xn--ho-hia.de>
This commit is contained in:
Sebastian Hoß 2023-03-16 08:13:15 +01:00 committed by Michael Eischer
parent 25350a9c55
commit c133065a9f

View File

@ -796,6 +796,15 @@ func (arch *Archiver) Snapshot(ctx context.Context, targets []string, opts Snaps
return nil, restic.ID{}, err return nil, restic.ID{}, err
} }
if opts.Command != nil {
errBytes, _ := io.ReadAll(opts.CommandStderr)
cmdErr := opts.Command.Wait()
if cmdErr != nil {
debug.Log("error while executing command: %v", cmdErr)
return nil, restic.ID{}, errors.New(string(errBytes))
}
}
sn, err := restic.NewSnapshot(targets, opts.Tags, opts.Hostname, opts.Time) sn, err := restic.NewSnapshot(targets, opts.Tags, opts.Hostname, opts.Time)
if err != nil { if err != nil {
return nil, restic.ID{}, err return nil, restic.ID{}, err