mirror of https://github.com/restic/restic.git
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:
parent
25350a9c55
commit
c133065a9f
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue