mirror of
https://github.com/restic/restic.git
synced 2026-10-11 12:37:13 +00:00
restic-from-command: abort snapshot on non-zero exit codes
This commit is contained in:
1 parent
6990b0122e
commit
81f8d473df
2 files changed
+43
-4
No files matched your search
@@ -634,6 +634,8 @@ func runBackup(ctx context.Context, opts BackupOptions, gopts GlobalOptions, ter
|
||||
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.SelectByName = selectByNameFilter
|
||||
arch.Select = selectFilter
|
||||
@@ -641,6 +643,11 @@ func runBackup(ctx context.Context, opts BackupOptions, gopts GlobalOptions, ter
|
||||
success := true
|
||||
arch.Error = func(item string, err error) error {
|
||||
success = false
|
||||
// If we receive a fatal error during the execution of the snapshot,
|
||||
// we abort the snapshot.
|
||||
if errors.IsFatal(err) {
|
||||
cancelSnapshot()
|
||||
}
|
||||
return progressReporter.Error(item, err)
|
||||
}
|
||||
arch.CompleteItem = progressReporter.CompleteItem
|
||||
@@ -668,7 +675,8 @@ func runBackup(ctx context.Context, opts BackupOptions, gopts GlobalOptions, ter
|
||||
if !gopts.JSON {
|
||||
progressPrinter.V("start backup on %v", targets)
|
||||
}
|
||||
_, id, err := arch.Snapshot(ctx, targets, snapshotOpts)
|
||||
_, id, err := arch.Snapshot(snapshotCtx, targets, snapshotOpts)
|
||||
cancelSnapshot()
|
||||
|
||||
// cleanly shutdown all running goroutines
|
||||
cancel()
|
||||
|
||||
Reference in new issue
Block a user