Skip to content

Commit

Permalink
Summary from plain output when not run in terminal (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkellerer authored Apr 25, 2021
1 parent b7edeb5 commit 7fc5b3a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand All @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions term/term.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down

0 comments on commit 7fc5b3a

Please sign in to comment.