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:

2 Likes

I would love to have that feature too!