From 7fc5b3ad1da33eaf8b54a75b8c820d7164382872 Mon Sep 17 00:00:00 2001 From: jkellerer Date: Sun, 25 Apr 2021 15:44:47 +0200 Subject: [PATCH] Summary from plain output when not run in terminal (#48) --- README.md | 19 ++++++++++--------- term/term.go | 6 ++++++ wrapper.go | 12 ++++++------ 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index c020c698..71e5c42c 100644 --- a/README.md +++ b/README.md @@ -1391,9 +1391,17 @@ Here's an example of a generated file, where you can see that the last `check` f } ``` -## Extended status +Note: In the backup section above you can see some fields like `files_new`, `files_total`, etc. This information is only available when resticprofile's output is either *not* sent to the terminal (e.g. redirected) or when you add the flag `extended-status` to your backup configuration. +This is a technical limitation to ensure restic displays terminal output correctly. + +`extended-status` or stdout redirection is **not needed** for these fields: +- success +- time +- error +- stderr +- duration -On the previous example of a status file you can see some fields like `files_new`, `files_total`, etc. To be able to get this information from restic, you need to add the flag `extended-status` to your backup configuration. +## Extended status `extended-status` is **not set by default because it hides any output from restic** @@ -1409,13 +1417,6 @@ profile: ``` -`extended-status` is **not needed** for these fields: -- success -- time -- error -- stderr -- duration - # Variable expansion in configuration file You might want to reuse the same configuration (or bits of it) on different environments. One way of doing it is to create a generic configuration where specific bits will be replaced by a variable. diff --git a/term/term.go b/term/term.go index da6dd448..c8effb9b 100644 --- a/term/term.go +++ b/term/term.go @@ -72,6 +72,12 @@ func ReadLine() (string, error) { return strings.TrimSpace(line), nil } +// OsStdoutIsTerminal returns true as os.Stdout is a terminal session +func OsStdoutIsTerminal() bool { + fd := int(os.Stdout.Fd()) + return terminal.IsTerminal(fd) +} + // SetOutput changes the default output for the Print* functions func SetOutput(w io.Writer) { terminalOutput = w diff --git a/wrapper.go b/wrapper.go index cff2801f..b5733438 100644 --- a/wrapper.go +++ b/wrapper.go @@ -308,13 +308,13 @@ func (r *resticWrapper) runCommand(command string) error { for { rCommand := r.prepareCommand(command, args) - if command == constants.CommandBackup && r.profile.StatusFile != "" { - if r.profile.Backup != nil && r.profile.Backup.ExtendedStatus { + if command == constants.CommandBackup && r.profile.StatusFile != "" && r.profile.Backup != nil { + if r.profile.Backup.ExtendedStatus { rCommand.scanOutput = shell.ScanBackupJson - // } else { - // scan plain backup could have been a good idea, - // except restic detects its output is not a terminal and no longer displays the progress - // rCommand.scanOutput = shell.ScanBackupPlain + } else if !term.OsStdoutIsTerminal() { + // restic detects its output is not a terminal and no longer displays the progress. + // Scan plain output only if resticprofile is not run from a terminal (e.g. schedule) + rCommand.scanOutput = shell.ScanBackupPlain } }