Backup logs from Windows Task Scheduler

Just wanted to post a quick tip…

I use restic to backup several machines and it’s been working great so far. One of those machines, however, is a Windows 10 desktop. I was able to use the Windows Task Scheduler to run the backup/prune jobs, but was super annoyed by the lack of logging. Note: This is a fault of the Windows Task Scheduler, not restic. I saw suggestions from multiple people saying to just “>>” append the output to a file and call it a day. The danger there is that the solution does not provide for common (and necessary) log file capabilities like rolling and deletion. So the file would only ever grow larger and would eventually run the risk of filling my disk. As a solution, I created a simple go app that will fill this gap. It allows you to pipe any other executable’s output to it and it will direct it to the specified file. If that file get’s above the specified max size, it will be rolled. Any files that exceed the specified max age or max rolled files will be removed. It’s located at the below link if anyone else is interested.

And here’s a copy of the “Actions” that I added to my Scheduled Task so you can see how to use it. All tasks run %SYSTEMROOT%\System32\cmd.exe and the following are the args passed to the executable:

  1. /C start "Restic Unlock" /B /MIN /BELOWNORMAL /WAIT %SYSTEMROOT%\System32\restic.exe --quiet --verbose unlock | %SYSTEMROOT%\System32\log.exe -tstmp -size 10 -file %LOCALAPPDATA%\restic\logs\restic.log --
  2. /C start "Restic Backup" /B /MIN /BELOWNORMAL /WAIT %SYSTEMROOT%\System32\restic.exe --quiet --verbose backup --hostname win10 --tag user1@win10 --files-from %APPDATA%\restic\includes --exclude-file %APPDATA%\restic\excludes | %SYSTEMROOT%\System32\log.exe -tstmp -size 10 -file %LOCALAPPDATA%\restic\logs\restic.log --
  3. /C start "Restic Forget" /B /MIN /BELOWNORMAL /WAIT %SYSTEMROOT%\System32\restic.exe --quiet --verbose forget --host win10 --tag user1@win10 --keep-last 5 --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --keep-yearly 5 | %SYSTEMROOT%\System32\log.exe -tstmp -size 10 -file %LOCALAPPDATA%\restic\logs\restic.log --