restic-from-command: abort snapshot on non-zero exit codes

This commit is contained in:
Enrico204 authored and Michael Eischer committed 2023-10-27 23:58:51 +02:00
1 parent 6990b0122e
commit 81f8d473df
2 files changed
+43 -4

No files matched your search

+9 -1
View File
@@ -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()