restic: Log file on Windows contains progress status text, escape characters and extra line breaks
Hello,
The log file on Windows contains progress status text, escape characters and extra line breaks. This does not happen on Linux. (https://forum.restic.net/t/different-log-file-in-windows-and-linux/3273)
Please fix, thanks!
Output of restic version
Windows
restic 0.11.0 compiled with go1.15.3 on windows/amd64
Linux
restic 0.11.0 compiled with go1.15.3 on linux/amd64
How did you run restic exactly?
Windows
restic backup --repo C:\Backup C:\Users --cleanup-cache --verbose --verbose >> C:\restic.log 2>&1
Linux
restic backup --repo /backup /source --cleanup-cache --verbose --verbose >> /restic.log 2>&1
Expected behavior
log files are the same on Windows and Linux
Linux
open repository
lock repository
load index files
using parent snapshot 5f9668c4
start scan on [/source]
start backup on [/source]
new /source/file.txt, saved in 0.044s (100 B added)
unchanged /source/file.jpg
...
Actual behavior
Windows
open repository
e[2Klock repository
e[2Kload index files
e[2Kusing parent snapshot cf8362f4
e[2Kstart scan on [C:\Users]
e[2Kstart backup on [C:\Users]
e[2K[0:00] 0 files, 0 B, 0 errors
e[2Kunchanged /C/Users/MyUser/Config.xml
e[2K[0:00] 0 files, 0 B, 0 errors
e[2Kunchanged /C/Users/MyUser/test.html
...
(e[ = Escape character)
Do you have an idea how to solve the issue?
This did not happen in older versions <= 0.9.5
Did restic help you today? Did it make you happy in any way?
I’m happy that Restic also works on Windows
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 20 (10 by maintainers)
Commits related to this issue
- reverting the removal of pipe checks in termstatus Turns out these checks are needed for Windows when piping output. Resolves #3111 — committed to kmwoley/restic by kmwoley 3 years ago
I can also confirm the issue shows up for me in powershell after updating to v0.12.0, and reverting to v0.11.0 fixes the issue.
I did a bit of testing; as far as I can tell, the issue currently seems to only affect powershell, and only when redirecting restic output to a log file. If the output isn’t redirected, there’s no problem. I checked with both Tee-Object, Out-File and normal redirection as below, both in a simple powershell script and just in a live terminal:
Whether restic is run by a powershell script or in a live terminal doesn’t seem to matter; the unwanted characters still end up in the output file.
I suspect normal redirection being affected as well as the two piped versions in my tests is because of this:
It looks like you already have a very good idea of what’s causing the behaviour, so I’m not sure how useful the below paragraphs will be…
That said, I was curious, so I did some digging, and think what I found might explain why the reports on which versions/terminals are affected appear to conflict at times in this thread.
I started with a git bisect between v0.11.0 and v0.12.0, which pointed to this commit (PR https://github.com/restic/restic/pull/3150) as where the problem first appeared for me (in powershell):
Which is a little weird, given that particular PR was supposed to resolve this specific problem.
Bearing that in mind, I went backwards further, as v0.10.0 and v0.9.6 are mentioned at the beginning of this issue. I found I could reproduce the problem on 0.9.6 (again, still in powershell), but not on 0.10.0, which is the inverse of the original issue report.
Using the downloadable restic binaries, I was able to pin the first appearance of the problem down to between v0.8.3 and v0.9.0. Unfortunately, I was unable to bisect fully due to problems building some of the older restic commits (may be user error, not sure). I narrowed it down somewhat though:
Anyway, while bisecting, I checked again using cmd, and was surprised to find that the symptoms were the inverse of powershell; so when powershell works fine, cmd doesn’t, and vice versa.
When using cmd, redirected output is normal for the 0.9.x series and 0.12.0, but has problems in versions v0.10.0 and v0.11.0. Powershell is the opposite, it has the problems with redirected output with the v0.9.x series and v0.12.0, but doesn’t with v0.10.0 or v0.11.0. For the 0.8.x series of releases, both cmd and powershell appear to work fine.
Based on the above, I think the changes in PR 3105 and PR https://github.com/restic/restic/pull/2608 caused the problem to switch between powershell and cmd (and possibly other terminals?). This was apparently because of the isPipe condition being flipped, and is why there’s some confusion over which terminals/verions are affected here.
tldr; redirected output looks like it has had this issue in powershell since v0.9.0. PR 2608 unintentionally fixed it for powershell but broke it for cmd (and possibly others?), then PR 3105 reverted this.
Hope the above helps!
@MichaelEischer I am not sure, but I believe it was v0.11 cause I set my backup and got notified since 29 Dec last year. Note that v0.11 tagged on Nov 5 2020.
Yes, the result is obtained with powershell and pushed via discord webhook for notification. Please find my code and its corresponding output below.
result before (presumably v0.11)
result now (v0.12)