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.
This commit is contained in:
Michael Eischer 2021-02-15 21:59:33 +01:00
parent 12f0ccc237
commit 65bd2a9a49
3 changed files with 16 additions and 5 deletions

View file

@ -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

View file

@ -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)) })

View file

@ -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