mirror of https://github.com/restic/restic.git
backup: rework error reporting for subcommand
This commit is contained in:
parent
8bceb8e359
commit
ee305e6041
|
@ -633,8 +633,6 @@ func runBackup(ctx context.Context, opts BackupOptions, gopts GlobalOptions, ter
|
||||||
wg.Go(func() error { return sc.Scan(cancelCtx, targets) })
|
wg.Go(func() error { return sc.Scan(cancelCtx, targets) })
|
||||||
}
|
}
|
||||||
|
|
||||||
snapshotCtx, cancelSnapshot := context.WithCancel(ctx)
|
|
||||||
|
|
||||||
arch := archiver.New(repo, targetFS, archiver.Options{ReadConcurrency: backupOptions.ReadConcurrency})
|
arch := archiver.New(repo, targetFS, archiver.Options{ReadConcurrency: backupOptions.ReadConcurrency})
|
||||||
arch.SelectByName = selectByNameFilter
|
arch.SelectByName = selectByNameFilter
|
||||||
arch.Select = selectFilter
|
arch.Select = selectFilter
|
||||||
|
@ -642,12 +640,13 @@ func runBackup(ctx context.Context, opts BackupOptions, gopts GlobalOptions, ter
|
||||||
success := true
|
success := true
|
||||||
arch.Error = func(item string, err error) error {
|
arch.Error = func(item string, err error) error {
|
||||||
success = false
|
success = false
|
||||||
|
reterr := progressReporter.Error(item, err)
|
||||||
// If we receive a fatal error during the execution of the snapshot,
|
// If we receive a fatal error during the execution of the snapshot,
|
||||||
// we abort the snapshot.
|
// we abort the snapshot.
|
||||||
if errors.IsFatal(err) {
|
if reterr == nil && errors.IsFatal(err) {
|
||||||
cancelSnapshot()
|
reterr = err
|
||||||
}
|
}
|
||||||
return progressReporter.Error(item, err)
|
return reterr
|
||||||
}
|
}
|
||||||
arch.CompleteItem = progressReporter.CompleteItem
|
arch.CompleteItem = progressReporter.CompleteItem
|
||||||
arch.StartFile = progressReporter.StartFile
|
arch.StartFile = progressReporter.StartFile
|
||||||
|
@ -674,8 +673,7 @@ func runBackup(ctx context.Context, opts BackupOptions, gopts GlobalOptions, ter
|
||||||
if !gopts.JSON {
|
if !gopts.JSON {
|
||||||
progressPrinter.V("start backup on %v", targets)
|
progressPrinter.V("start backup on %v", targets)
|
||||||
}
|
}
|
||||||
_, id, err := arch.Snapshot(snapshotCtx, targets, snapshotOpts)
|
_, id, err := arch.Snapshot(ctx, targets, snapshotOpts)
|
||||||
cancelSnapshot()
|
|
||||||
|
|
||||||
// cleanly shutdown all running goroutines
|
// cleanly shutdown all running goroutines
|
||||||
cancel()
|
cancel()
|
||||||
|
|
|
@ -2,6 +2,7 @@ package archiver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -146,7 +147,7 @@ func (s *FileSaver) saveFile(ctx context.Context, chnker *chunker.Chunker, snPat
|
||||||
panic("completed twice")
|
panic("completed twice")
|
||||||
}
|
}
|
||||||
isCompleted = true
|
isCompleted = true
|
||||||
fnr.err = err
|
fnr.err = fmt.Errorf("failed to save %v: %w", target, err)
|
||||||
fnr.node = nil
|
fnr.node = nil
|
||||||
fnr.stats = ItemStats{}
|
fnr.stats = ItemStats{}
|
||||||
finish(fnr)
|
finish(fnr)
|
||||||
|
|
|
@ -83,7 +83,7 @@ func (fp *CommandReader) wait() error {
|
||||||
err := fp.cmd.Wait()
|
err := fp.cmd.Wait()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Use a fatal error to abort the snapshot.
|
// Use a fatal error to abort the snapshot.
|
||||||
return errors.Fatal(err.Error())
|
return errors.Fatal(fmt.Errorf("command failed: %w", err).Error())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue