From 65bd2a9a498581c42e5ea2d4944a8b732619f244 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Mon, 15 Feb 2021 21:59:33 +0100 Subject: [PATCH] backup: Correctly handle --quiet flag The quiet flag changes the backup output to assume a non-interactive terminal. However, the output progress interval was not set to 0 by default. --- changelog/unreleased/issue-3284 | 11 +++++++++++ cmd/restic/cmd_backup.go | 2 +- cmd/restic/progress.go | 8 ++++---- 3 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 changelog/unreleased/issue-3284 diff --git a/changelog/unreleased/issue-3284 b/changelog/unreleased/issue-3284 new file mode 100644 index 000000000..b0cf0ea8e --- /dev/null +++ b/changelog/unreleased/issue-3284 @@ -0,0 +1,11 @@ +Bugfix: `backup --quiet` no longer prints status information + +A regression in the latest restic version caused the output of `backup --quiet` +to contain large amounts of backup progress information when run using an +interactive terminal. This is fixed now. + +A workaround for this bug is to run restic as follows: +`restic backup --quiet [..] | cat -`. + +https://github.com/restic/restic/issues/3184 +https://github.com/restic/restic/pull/3186 diff --git a/cmd/restic/cmd_backup.go b/cmd/restic/cmd_backup.go index bd8b4da8c..ef03884ab 100644 --- a/cmd/restic/cmd_backup.go +++ b/cmd/restic/cmd_backup.go @@ -561,7 +561,7 @@ func runBackup(opts BackupOptions, gopts GlobalOptions, term *termstatus.Termina }() gopts.stdout, gopts.stderr = p.Stdout(), p.Stderr() - p.SetMinUpdatePause(calculateProgressInterval()) + p.SetMinUpdatePause(calculateProgressInterval(!gopts.Quiet)) t.Go(func() error { return p.Run(t.Context(gopts.ctx)) }) diff --git a/cmd/restic/progress.go b/cmd/restic/progress.go index c0b6c56fb..62f2e6396 100644 --- a/cmd/restic/progress.go +++ b/cmd/restic/progress.go @@ -11,8 +11,8 @@ import ( // calculateProgressInterval returns the interval configured via RESTIC_PROGRESS_FPS // or if unset returns an interval for 60fps on interactive terminals and 0 (=disabled) -// for non-interactive terminals -func calculateProgressInterval() time.Duration { +// for non-interactive terminals or when run using the --quiet flag +func calculateProgressInterval(show bool) time.Duration { interval := time.Second / 60 fps, err := strconv.ParseFloat(os.Getenv("RESTIC_PROGRESS_FPS"), 64) if err == nil && fps > 0 { @@ -20,7 +20,7 @@ func calculateProgressInterval() time.Duration { fps = 60 } interval = time.Duration(float64(time.Second) / fps) - } else if !stdoutIsTerminal() { + } else if !stdoutIsTerminal() || !show { interval = 0 } return interval @@ -31,7 +31,7 @@ func newProgressMax(show bool, max uint64, description string) *progress.Counter if !show { return nil } - interval := calculateProgressInterval() + interval := calculateProgressInterval(show) return progress.New(interval, max, func(v uint64, max uint64, d time.Duration, final bool) { var status string