Skip to content
This repository has been archived by the owner on Mar 2, 2022. It is now read-only.

Reduce Restic Progress FPS #82

Merged
merged 1 commit into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ type PercentageFunc func(logr.InfoLogger, float64)
type BackupOutputParser struct {
log logr.Logger
errorCount int
lineCounter int
summaryFunc SummaryFunc
percentageFunc PercentageFunc
folder string
Expand Down Expand Up @@ -162,11 +161,7 @@ func (b *BackupOutputParser) out(s string) error {
b.errorCount++
b.log.Error(fmt.Errorf("error occurred during backup"), envelope.Item+" during "+envelope.During+" "+envelope.Error.Op)
case "status":
// Restic does the json output with 60hz, which is a bit much...
if b.lineCounter%60 == 0 {
b.percentageFunc(b.log, envelope.PercentDone)
}
b.lineCounter++
b.percentageFunc(b.log, envelope.PercentDone)
case "summary":
b.log.Info("backup finished", "new files", envelope.FilesNew, "changed files", envelope.FilesChanged, "errors", b.errorCount)
b.log.Info("stats", "time", envelope.TotalDuration, "bytes added", envelope.DataAdded, "bytes processed", envelope.TotalBytesProcessed)
Expand Down
16 changes: 15 additions & 1 deletion restic/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"os"
"os/exec"
"strings"

"github.com/go-logr/logr"
)
Expand Down Expand Up @@ -54,7 +55,8 @@ func (c *Command) Run() {
// Mainly set the env vars and wire the right stdins/outs.
func (c *Command) Configure() {
c.cmd = exec.CommandContext(c.ctx, c.options.Path, c.options.Args...)
c.cmd.Env = os.Environ()
osEnv := os.Environ()
c.cmd.Env = c.setResticProgressFPSIfNotDefined(osEnv)

if c.options.StdIn != nil {
c.cmd.Stdin = c.options.StdIn
Expand All @@ -69,6 +71,18 @@ func (c *Command) Configure() {
}
}

func (c *Command) setResticProgressFPSIfNotDefined(givenEnv []string) []string {
for _, envVar := range givenEnv {
if strings.HasPrefix("RESTIC_PROGRESS_FPS=", envVar) {
return givenEnv
}
}

const frequency = 1.0 / 60.0
c.cmdLogger.Info("Defining RESTIC_PROGRESS_FPS", "frequency", frequency)
return append(givenEnv, fmt.Sprintf("RESTIC_PROGRESS_FPS=%f", frequency))
}

// Start starts the specified command but does not wait for it to complete.
func (c *Command) Start() {
if c.cmd == nil {
Expand Down