Exit 3 when a backup or restore finished but skipped files (closes #439)
check / check (push) Waiting to run

A `snapshot create` or `snapshot restore` that --skip-errors made skip
files now exits 3, the status `restic backup` uses, so a cron job can
tell it from a run that made no backup (1). RunOperation keeps the
operation's error inside errReported so Entry can pick the status.

A run that skipped files and also found a configured path empty, missed
a mount point, or was asked for a path the snapshot lacks still exits 1:
its error wraps only that condition and names the skipped files in text.

The README gains an exit status section.

Model: opus-5-5
This commit is contained in:
sneak committed 2026-11-19 06:38:41 +00:00
1 parent d747ddef3a
commit 7f3fb97012
9 files changed
+180 -68

No files matched your search

+7 -6
View File
@@ -198,7 +198,8 @@ func RunApp(ctx context.Context, app *fx.App) error {
// (or, under `snapshot verify --json`, put in its document). Entry
// turns it into a non-zero exit status without printing anything
// further, so the error line is not doubled. It flows up from
// RunOperation through cobra to Entry.
// RunOperation through cobra to Entry, wrapping the operation's error
// so that Entry can choose the exit status from it.
var errReported = errors.New("operation failed")
// errInterrupted marks an operation that SIGINT or SIGTERM stopped
@@ -232,8 +233,8 @@ func RunOperation(
) error {
var (
mu sync.Mutex
finished bool // op returned before any interrupt cancelled it
failed bool // op finished with an error
finished bool // op returned before any interrupt cancelled it
opErr error // what op returned, when it finished
)
opts.Invokes = append(opts.Invokes,
@@ -258,7 +259,7 @@ func RunOperation(
mu.Lock()
finished = true
failed = err != nil
opErr = err
mu.Unlock()
}
@@ -303,8 +304,8 @@ func RunOperation(
switch {
case !finished:
return errInterrupted
case failed:
return errReported
case opErr != nil:
return fmt.Errorf("%w: %w", errReported, opErr)
default:
return nil
}