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?

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
1 Like

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.