New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
backup: add flag --summary-filename #3586
Conversation
The summary statistics in JSON form will be appeded to the specified filename. This works independently of verbosity level and reporter (json or text) chosen.
Can you please include a usage example that shows how this is used and solves a problem? You can edit your initial post to add it. |
I feel like an idiot right now, because I don't see at all what this PR does that you can't already very easily do. Here are two examples that as far as I can tell yields the same result as your usage example above (one with a silly
So why should we complicate restic with another option/flag for such a specific use, when this is super simple to do with existing tooling? I just don't get it. Restic already outputs summary information in a structured format - how you use or store that information is something that is best kept as a separate concern IMO (similar to UNIX philosophy). |
Yes, but then you don't get any progress indication. You can have more events added to the JSON log, but then it becomes extremely verbose and it is not very human friendly. The built-in terminal based progress indicator in Restic is very nice, and it would be a shame to have to re-implement it in an external script which parses the stream of JSON events. |
You know the code, do you think this is a possible/reasonable thing to do? I would definitely prefer it over maintaining the history outside Restic itself. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a few comments below, independent of whether we should add that flag or not.
You know the code, do you think this is a possible/reasonable thing to do? I would definitely prefer it over maintaining the history outside Restic itself.
There has been some discussion on that point in #874 (comment) . Adding backup statistics to a snapshot would definitely be possible. The only downside would be that only new restic versions would create and be able to interpret these (restic cat snapshot 12345678
will work though).
@@ -186,3 +186,25 @@ func (b *TextProgress) Finish(snapshotID restic.ID, start time.Time, summary *Su | |||
formatDuration(time.Since(start)), | |||
) | |||
} | |||
|
|||
// Return finishing stats in a struct. | |||
func (b *TextProgress) FinishSummary(snapshotID restic.ID, start time.Time, summary *Summary, dryRun bool) summaryOutput { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function does not require any data stored in the TextProgress struct. Thus please extract it into a separate function and remove the duplication with the JsonProgress.
if err := json.NewEncoder(buf).Encode(progressReporter.FinishSummary(id)); err != nil { | ||
return errors.Errorf("encoding summary failed: %v", err) | ||
} | ||
fmt.Fprintf(sf, "%s", buf.String()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use sf.Write(buf.Bytes())
instead. There's no need for format string interpolation and multiple String <-> []byte conversions.
@@ -710,7 +713,21 @@ func runBackup(opts BackupOptions, gopts GlobalOptions, term *termstatus.Termina | |||
if !gopts.JSON && !opts.DryRun { | |||
progressPrinter.P("snapshot %s saved\n", id.Str()) | |||
} | |||
if !success { | |||
if opts.SummaryFilename != "" { | |||
sf, err := os.OpenFile(opts.SummaryFilename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to extract that code into a separate function. runBackup
is already far too long.
@MichaelEischer Sorry if it came to you as advertisement of rustic. I only intended to be clear about what I'm talking and prevent confusions as already happened in the forum - so I decided to always put the link when talking about rustic If you are complaining about advertising other issue solutions which I prefer - well, this is of course intended 😉 |
The summary statistics in JSON form will be appended to the specified
filename. This works independently of verbosity level and reporter
(json or text) chosen.
What does this PR change? What problem does it solve?
Collecting statistics from the jobs which have run is currently relatively awkward. This patch allows statistics and metadata to be collected and processed by other scripts.
It uses append mode and prepares the JSON string so it is written atomically to the file, so no locking should be required.
A simple example run:
If this idea is accepted, I would like to add the timestamp for when the backup job started to the metadata.
Ideally this metadata would be available from the snapshot sub-command, but it seems like a chicken and egg problem to add that information as part of the snapshot, so I gave up on that idea.
Was the change previously discussed in an issue or on the forum?
It has been discussed loosely on IRC from time to time.
Checklist
changelog/unreleased/
that describes the changes for our users (see template).gofmt
on the code in all commits.