diff --git a/cmd/restic/progress.go b/cmd/restic/progress.go index 3ac4eef4a..4407f3760 100644 --- a/cmd/restic/progress.go +++ b/cmd/restic/progress.go @@ -17,7 +17,7 @@ func newProgressMax(show bool, max uint64, description string) *progress.Counter interval := time.Second / 60 if !stdoutIsTerminal() { - interval = time.Second + interval = 0 } else { fps, err := strconv.ParseInt(os.Getenv("RESTIC_PROGRESS_FPS"), 10, 64) if err == nil && fps >= 1 { diff --git a/doc/manual_rest.rst b/doc/manual_rest.rst index 73dfa296b..d26bde9f9 100644 --- a/doc/manual_rest.rst +++ b/doc/manual_rest.rst @@ -133,15 +133,14 @@ command: --tls-client-cert file path to a file containing PEM encoded TLS client certificate and private key -v, --verbose n be verbose (specify multiple times or a level using --verbose=n, max level/times is 3) -Subcommand that support showing progress information such as ``backup``, +Subcommands that support showing progress information such as ``backup``, ``check`` and ``prune`` will do so unless the quiet flag ``-q`` or -``--quiet`` is set. When running from a non-interactive console progress -reporting will be limited to once every 10 seconds to not fill your -logs. Use ``backup`` with the quiet flag ``-q`` or ``--quiet`` to skip -the initial scan of the source directory, this may shorten the backup -time needed for large directories. +``--quiet`` is set. For interactive consoles the environment variable +``RESTIC_PROGRESS_FPS`` can be used to control the frequency of progress +reporting. When running from a non-interactive console progress reporting +is disabled to not fill your logs. -Additionally on Unix systems if ``restic`` receives a SIGUSR1 signal the +Additionally, on Unix systems if ``restic`` receives a SIGUSR1 signal the current progress will be written to the standard output so you can check up on the status at will. diff --git a/internal/ui/progress/counter.go b/internal/ui/progress/counter.go index 3b0009649..3e6a50c2c 100644 --- a/internal/ui/progress/counter.go +++ b/internal/ui/progress/counter.go @@ -41,7 +41,9 @@ func New(interval time.Duration, report Func) *Counter { start: time.Now(), stopped: make(chan struct{}), stop: make(chan struct{}), - tick: time.NewTicker(interval), + } + if interval > 0 { + c.tick = time.NewTicker(interval) } go c.run() @@ -64,7 +66,9 @@ func (c *Counter) Done() { if c == nil { return } - c.tick.Stop() + if c.tick != nil { + c.tick.Stop() + } close(c.stop) <-c.stopped // Wait for last progress report. *c = Counter{} // Prevent reuse. @@ -85,11 +89,15 @@ func (c *Counter) run() { c.report(c.get(), time.Since(c.start), true) }() + var tick <-chan time.Time + if c.tick != nil { + tick = c.tick.C + } for { var now time.Time select { - case now = <-c.tick.C: + case now = <-tick: case sig := <-signals.ch: debug.Log("Signal received: %v\n", sig) now = time.Now() diff --git a/internal/ui/progress/counter_test.go b/internal/ui/progress/counter_test.go index 1ebc17a7c..9a76d9cbf 100644 --- a/internal/ui/progress/counter_test.go +++ b/internal/ui/progress/counter_test.go @@ -53,3 +53,22 @@ func TestCounterNil(t *testing.T) { c.Add(1) c.Done() } + +func TestCounterNoTick(t *testing.T) { + finalSeen := false + otherSeen := false + + report := func(value uint64, d time.Duration, final bool) { + if final { + finalSeen = true + } else { + otherSeen = true + } + } + c := progress.New(0, report) + time.Sleep(time.Millisecond) + c.Done() + + test.Assert(t, finalSeen, "final call did not happen") + test.Assert(t, !otherSeen, "unexpected status update") +}