Backup log as json and plain text

I would like to log what happened during a backup or forget command, in particular when run automatically via systemd. But also for a manual run, because it then behaves the same no matter if I start it or systemd. To this end, I use these options (simplified):

restic backup ... --json | grep summary > ~/resticlogs/backup_$(date).json
restic forget ... --json > ~/resticlogs/forget_$(date).json

However, these commands, I have no output on the command line and for longer backups I cannot see what the command is doing. Is there a way around that?

One idea (which would be a feature request probably) is this: there could be a --log-file option to indicate where a log file is created. Something like:

restic backup ... --log-file ~/resticlogs/backup_$(date).json

would then show the normal command line output but write the json output to the given file.
As long as this is not implemented, can I retrieve the same information that --json writes also from a restic diff output without creating log files during backup?

Summary

  1. Is there a way to get both json and plain text output simultaneously
  2. Would that be a reasonable feature request?
  3. Can I get the same information from restic diff or any other command?
2 Likes

You can use the tee command for this, e.g.

ping www.google.com | tee output.log

You can also continuously display the content of a file being written to using the tail command:

tail -f output.log
2 Likes

I am not sure I understand your reply correctly. I want a --json output passed to the log file and a normal plaintext output on stdout.

Sorry, I didn’t quite catch that that was the main requirement, just thought that seeing the json output on stdout would be good enough to see how the command is progressing…

The suggested --log-file feature is hardly a priority at this point, and I can’t recall anyone else asking for it either so it doesn’t seem like a pressing need. And if it were to exist, it would then have to be established how one is supposed to configure that the log file is supposed to be JSON and not plain text, while at the same time one wants either of those on the standard output. I just don’t see this being something worth considering right now, honestly.

I would love to have that feature! :grinning:

3 Likes

I would love to have that feature too!

1 Like

An even better solution would be to have the backup metadata (like added size, backup duration) already to the snapshot as asked for in the forum thread below. Then json log files would not be necessary.

Look up the logs using journalctl -u then. With --follow you can even watch them live. Be aware though, that with high verbosity journald will ratelimit and drop a lot of lines.

There is tee which will take stdin and write it to stdout and the given file.

$ restic backup … | grep summary | tee ~/resticlogs/backup_$(date).json

Thanks, I know tee. That’s not the point. If I do a manual backup, I like the updating progress where I can see which files are currently processed. But I want to know the backup duration etc. which is provided only by the backup command and afaik not in the snapshot metadata.

Now, I have to do this tee thing to logfiles (and not just restic backup) and if I want to see the files flying by, I have to parse the text output instead of using --json and a json parser. For backup monitoring it would be much easier if the summary data (duration, data added) was stored with the snapshots.

It would have been really helpful if there is one.

@Restic_User It’s not the same thing, but since 0.17.0, the snapshot summary is stored in the snapshot:

  • Enh #693: Include snapshot size in snapshots output

and can be read with restic snapshots latest --json after the backup.

Might the summary also contain an error or warning that occurred during the backup or check?

I have not tested it, but I don’t think so as the error section and the summary section are part of the JSON output of a backup, but only the summary object is part of the snapshot JSON data.

1 Like

Hi, I would love to have it as well.

I am currently using resticker/README.md at master · djmaze/resticker · GitHub and can’t find a way to get logs that I can notify myself with.

a --log-file argument would have been so useful. It’s even an open issue : Introduce `ENABLE_JSON_LOGGING` by jeankhawand · Pull Request #215 · djmaze/resticker · GitHub
Healthcheck and stats for monitoring · Issue #181 · djmaze/resticker · GitHub

Btw, if someone has a solution (with minimal to no changes to the original image), don’t hesitate to share it.