diff --git a/shell/json_summary.go b/shell/json_summary.go index 29cdeb4a..1bb79851 100644 --- a/shell/json_summary.go +++ b/shell/json_summary.go @@ -27,6 +27,7 @@ type ResticJsonSummary struct { // ScanBackupJson should populate the backup summary values from the output of the --json flag var ScanBackupJson ScanOutput = func(r io.Reader, summary *Summary, w io.Writer) error { + bogusPrefix := []byte("\r\x1b[2K") jsonPrefix := []byte(`{"message_type":"`) summaryPrefix := []byte(`{"message_type":"summary",`) jsonSuffix := []byte("}") @@ -37,6 +38,7 @@ var ScanBackupJson ScanOutput = func(r io.Reader, summary *Summary, w io.Writer) scanner := bufio.NewScanner(r) for scanner.Scan() { line := scanner.Bytes() + line = bytes.TrimPrefix(line, bogusPrefix) if bytes.HasPrefix(line, jsonPrefix) && bytes.HasSuffix(line, jsonSuffix) { if bytes.HasPrefix(line, summaryPrefix) { jsonSummary := ResticJsonSummary{} diff --git a/shell/json_summary_test.go b/shell/json_summary_test.go index b9b1df1b..0eedd32c 100644 --- a/shell/json_summary_test.go +++ b/shell/json_summary_test.go @@ -36,6 +36,10 @@ func TestScanJsonSummary(t *testing.T) { lines := strings.Split(resticOutput, "\n") for _, line := range lines { line = strings.TrimRight(line, "\r") + if runtime.GOOS == "windows" { + // https://github.com/restic/restic/issues/3111 + writer.WriteString("\r\x1b[2K") + } writer.WriteString(line + eol) } writer.Close()