From f7fad5fd7a4b78928ac07eb0de056d9bda7dbdcd Mon Sep 17 00:00:00 2001 From: Eugen Sumin Date: Tue, 12 Mar 2024 16:00:29 +0100 Subject: [PATCH 1/8] Parse `kopia snapshot restore` progress output. --- pkg/kopia/command/parse_command_output.go | 92 ++++++++++++++++++- .../command/parse_command_output_test.go | 62 +++++++++++++ 2 files changed, 153 insertions(+), 1 deletion(-) diff --git a/pkg/kopia/command/parse_command_output.go b/pkg/kopia/command/parse_command_output.go index 0f510abd0d..341f50e2ef 100644 --- a/pkg/kopia/command/parse_command_output.go +++ b/pkg/kopia/command/parse_command_output.go @@ -39,6 +39,7 @@ const ( //nolint:lll snapshotCreateOutputRegEx = `(?P[|/\-\\\*]).+[^\d](?P\d+) hashed \((?P[^\)]+)\), (?P\d+) cached \((?P[^\)]+)\), uploaded (?P[^\)]+), (?:estimating...|estimated (?P[^\)]+) \((?P[^\)]+)\%\).+)` + snapshotRestoreOutputRegEx = `Processed (?P\d+) \((?P.*)\) of (?P\d+) \((?P.*)\) (?P.*) \((?P.*)%\) remaining (?P.*)\.` extractSnapshotIDRegEx = `Created snapshot with root ([^\s]+) and ID ([^\s]+).*$` repoTotalSizeFromBlobStatsRegEx = `Total: (\d+)$` repoCountFromBlobStatsRegEx = `Count: (\d+)$` @@ -205,7 +206,10 @@ type SnapshotCreateStats struct { ProgressPercent int64 } -var kopiaProgressPattern = regexp.MustCompile(snapshotCreateOutputRegEx) //nolint:lll +var ( + kopiaProgressPattern = regexp.MustCompile(snapshotCreateOutputRegEx) + kopiaSnapshotRestorePattern = regexp.MustCompile(snapshotRestoreOutputRegEx) +) // SnapshotStatsFromSnapshotCreate parses the output of a kopia snapshot // create execution for a log of the stats for that execution. @@ -327,6 +331,92 @@ func parseKopiaProgressLine(line string, matchOnlyFinished bool) (stats *Snapsho } } +// SnapshotRestoreStats is a container for stats parsed from the output of a `kopia snapshot restore` command. +type SnapshotRestoreStats struct { + FilesProcessed int64 + SizeProcessedB int64 + FilesTotal int64 + SizeTotalB int64 + ProgressPercent int64 +} + +// SnapshotStatsFromSnapshotRestore parses the output of a `kopia snapshot restore` execution +// for a log of the stats for that execution. +func SnapshotStatsFromSnapshotRestore(snapRestoreStderrOutput string) (stats *SnapshotRestoreStats) { + if snapRestoreStderrOutput == "" { + return nil + } + logs := regexp.MustCompile("[\r\n]").Split(snapRestoreStderrOutput, -1) + + for _, l := range logs { + lineStats := parseKopiaSnapshotRestoreProgressLine(l) + if lineStats != nil { + stats = lineStats + } + } + + return stats +} + +func parseKopiaSnapshotRestoreProgressLine(line string) (stats *SnapshotRestoreStats) { + match := kopiaSnapshotRestorePattern.FindStringSubmatch(line) + if len(match) < 8 { + return nil + } + + groups := make(map[string]string) + for i, name := range kopiaSnapshotRestorePattern.SubexpNames() { + if i != 0 && name != "" { + groups[name] = match[i] + } + } + + processedCount, err := strconv.Atoi(groups["processedCount"]) + if err != nil { + log.WithError(err).Print("Skipping entry due to inability to parse number of processed files", field.M{"processedCount": groups["processedCount"]}) + return nil + } + + processedSize, err := humanize.ParseBytes(groups["processedSize"]) + if err != nil { + log.WithError(err).Print("Skipping entry due to inability to parse amount of processed bytes", field.M{"processedSize": groups["processedSize"]}) + return nil + } + + totalCount, err := strconv.Atoi(groups["totalCount"]) + if err != nil { + log.WithError(err).Print("Skipping entry due to inability to parse expected number of files", field.M{"totalCount": groups["totalCount"]}) + return nil + } + + totalSize, err := humanize.ParseBytes(groups["totalSize"]) + if err != nil { + log.WithError(err).Print("Skipping entry due to inability to parse expected amount of bytes", field.M{"totalSize": groups["totalSize"]}) + return nil + } + + progressPercent, err := strconv.ParseFloat(groups["percentage"], 64) + if err != nil { + log.WithError(err).Print("Skipping entry due to inability to parse progress percent string", field.M{"progressPercent": groups["progressPercent"]}) + return nil + } + + if progressPercent >= 100 { + // It may happen that kopia reports progress of 100 or higher without actual completing the task. + // This can occur due to inaccurate estimation. + // In such case, we will return the progress as 99% to avoid confusion. + progressPercent = 99 + } + + return &SnapshotRestoreStats{ + FilesProcessed: int64(processedCount), + SizeProcessedB: int64(processedSize), + FilesTotal: int64(totalCount), + SizeTotalB: int64(totalSize), + ProgressPercent: int64(progressPercent), + } +} + // RepoSizeStatsFromBlobStatsRaw takes a string as input, interprets it as a kopia blob stats // output in an expected format (Contains the line "Total: "), and returns the integer // size in bytes or an error if parsing is unsuccessful. diff --git a/pkg/kopia/command/parse_command_output_test.go b/pkg/kopia/command/parse_command_output_test.go index 963955e9db..d3ed0f571f 100644 --- a/pkg/kopia/command/parse_command_output_test.go +++ b/pkg/kopia/command/parse_command_output_test.go @@ -440,6 +440,68 @@ func (kParse *KopiaParseUtilsTestSuite) TestSnapshotStatsFromSnapshotCreate(c *C } } +func (kParse *KopiaParseUtilsTestSuite) TestSnapshotStatsFromSnapshotRestore(c *C) { + type args struct { + snapshotRestoreOutput string + } + tests := []struct { + name string + args args + wantStats *SnapshotRestoreStats + }{ + { + name: "Basic test case", + args: args{ + snapshotRestoreOutput: "Processed 2 (397.5 MB) of 3 (3.1 GB) 14.9 MB/s (12.6%) remaining 3m3s.", + }, + wantStats: &SnapshotRestoreStats{ + FilesProcessed: 2, + SizeProcessedB: 397500000, + FilesTotal: 3, + SizeTotalB: 3100000000, + ProgressPercent: 12, + }, + }, + { + name: "Real test case", + args: args{ + snapshotRestoreOutput: "Processed 2 (13.7 MB) of 2 (3.1 GB) 8.5 MB/s (0.4%) remaining 6m10s.", + }, + wantStats: &SnapshotRestoreStats{ + FilesProcessed: 2, + SizeProcessedB: 13700000, + FilesTotal: 2, + SizeTotalB: 3100000000, + ProgressPercent: 0, + }, + }, + { + name: "Ignore incomplete stats without during estimation", + args: args{ + snapshotRestoreOutput: "Processed 2 (32.8 KB) of 2 (3.1 GB).", + }, + wantStats: nil, + }, + { + name: "Progress is over 100% and still not ready - set 99%", + args: args{ + snapshotRestoreOutput: "Processed 2 (13.7 MB) of 2 (3.1 GB) 8.5 MB/s (120.4%) remaining 6m10s.", + }, + wantStats: &SnapshotRestoreStats{ + FilesProcessed: 2, + SizeProcessedB: 13700000, + FilesTotal: 2, + SizeTotalB: 3100000000, + ProgressPercent: 99, + }, + }, + } + for _, tt := range tests { + stats := SnapshotStatsFromSnapshotRestore(tt.args.snapshotRestoreOutput) + c.Check(stats, DeepEquals, tt.wantStats, Commentf("Failed for %s", tt.name)) + } +} + func (kParse *KopiaParseUtilsTestSuite) TestPhysicalSizeFromBlobStatsRaw(c *C) { for _, tc := range []struct { blobStatsOutput string From 7e4a04cd2767223eeea2de24c10c608350addb7b Mon Sep 17 00:00:00 2001 From: Eugene Sumin <95425330+e-sumin@users.noreply.github.com> Date: Thu, 16 May 2024 01:15:37 +0200 Subject: [PATCH 2/8] Apply suggestions from code review Reformat comments Co-authored-by: Pavan Navarathna <6504783+pavannd1@users.noreply.github.com> --- pkg/kopia/command/parse_command_output.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/kopia/command/parse_command_output.go b/pkg/kopia/command/parse_command_output.go index 341f50e2ef..5f0872e25c 100644 --- a/pkg/kopia/command/parse_command_output.go +++ b/pkg/kopia/command/parse_command_output.go @@ -331,7 +331,8 @@ func parseKopiaProgressLine(line string, matchOnlyFinished bool) (stats *Snapsho } } -// SnapshotRestoreStats is a container for stats parsed from the output of a `kopia snapshot restore` command. +// SnapshotRestoreStats is a container for stats parsed from the output of a +// `kopia snapshot restore` command. type SnapshotRestoreStats struct { FilesProcessed int64 SizeProcessedB int64 @@ -340,8 +341,8 @@ type SnapshotRestoreStats struct { ProgressPercent int64 } -// SnapshotStatsFromSnapshotRestore parses the output of a `kopia snapshot restore` execution -// for a log of the stats for that execution. +// SnapshotStatsFromSnapshotRestore parses the output of a `kopia snapshot +// restore` execution for a log of the stats for that execution. func SnapshotStatsFromSnapshotRestore(snapRestoreStderrOutput string) (stats *SnapshotRestoreStats) { if snapRestoreStderrOutput == "" { return nil @@ -402,8 +403,8 @@ func parseKopiaSnapshotRestoreProgressLine(line string) (stats *SnapshotRestoreS } if progressPercent >= 100 { - // It may happen that kopia reports progress of 100 or higher without actual completing the task. - // This can occur due to inaccurate estimation. + // It may happen that kopia reports progress of 100 or higher without actual + // completing the task. This can occur due to inaccurate estimation. // In such case, we will return the progress as 99% to avoid confusion. progressPercent = 99 } From f932adeb5e9029fa88cce04982cc714b0f63bb7e Mon Sep 17 00:00:00 2001 From: Eugen Sumin Date: Mon, 20 May 2024 06:24:33 +0200 Subject: [PATCH 3/8] Address review notes --- pkg/kopia/command/parse_command_output.go | 19 +++++++++++-------- .../command/parse_command_output_test.go | 10 +++++----- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/pkg/kopia/command/parse_command_output.go b/pkg/kopia/command/parse_command_output.go index 5f0872e25c..fb1b97a681 100644 --- a/pkg/kopia/command/parse_command_output.go +++ b/pkg/kopia/command/parse_command_output.go @@ -331,9 +331,9 @@ func parseKopiaProgressLine(line string, matchOnlyFinished bool) (stats *Snapsho } } -// SnapshotRestoreStats is a container for stats parsed from the output of a -// `kopia snapshot restore` command. -type SnapshotRestoreStats struct { +// RestoreStats is a container for stats parsed from the output of a +// `kopia restore` command. +type RestoreStats struct { FilesProcessed int64 SizeProcessedB int64 FilesTotal int64 @@ -341,9 +341,9 @@ type SnapshotRestoreStats struct { ProgressPercent int64 } -// SnapshotStatsFromSnapshotRestore parses the output of a `kopia snapshot -// restore` execution for a log of the stats for that execution. -func SnapshotStatsFromSnapshotRestore(snapRestoreStderrOutput string) (stats *SnapshotRestoreStats) { +// RestoreStatsFromRestoreOutput parses the output of a `kopia restore` +// execution for a log of the stats for that execution. +func RestoreStatsFromRestoreOutput(snapRestoreStderrOutput string) (stats *RestoreStats) { if snapRestoreStderrOutput == "" { return nil } @@ -359,7 +359,10 @@ func SnapshotStatsFromSnapshotRestore(snapRestoreStderrOutput string) (stats *Sn return stats } -func parseKopiaSnapshotRestoreProgressLine(line string) (stats *SnapshotRestoreStats) { +// parseKopiaSnapshotRestoreProgressLine parses restore stats from line +// which expected to be in the following format: +// Processed 5 (1.4 GB) of 5 (1.8 GB) 291.1 MB/s (75.2%) remaining 1s. +func parseKopiaSnapshotRestoreProgressLine(line string) (stats *RestoreStats) { match := kopiaSnapshotRestorePattern.FindStringSubmatch(line) if len(match) < 8 { return nil @@ -409,7 +412,7 @@ func parseKopiaSnapshotRestoreProgressLine(line string) (stats *SnapshotRestoreS progressPercent = 99 } - return &SnapshotRestoreStats{ + return &RestoreStats{ FilesProcessed: int64(processedCount), SizeProcessedB: int64(processedSize), FilesTotal: int64(totalCount), diff --git a/pkg/kopia/command/parse_command_output_test.go b/pkg/kopia/command/parse_command_output_test.go index d3ed0f571f..e42783207f 100644 --- a/pkg/kopia/command/parse_command_output_test.go +++ b/pkg/kopia/command/parse_command_output_test.go @@ -447,14 +447,14 @@ func (kParse *KopiaParseUtilsTestSuite) TestSnapshotStatsFromSnapshotRestore(c * tests := []struct { name string args args - wantStats *SnapshotRestoreStats + wantStats *RestoreStats }{ { name: "Basic test case", args: args{ snapshotRestoreOutput: "Processed 2 (397.5 MB) of 3 (3.1 GB) 14.9 MB/s (12.6%) remaining 3m3s.", }, - wantStats: &SnapshotRestoreStats{ + wantStats: &RestoreStats{ FilesProcessed: 2, SizeProcessedB: 397500000, FilesTotal: 3, @@ -467,7 +467,7 @@ func (kParse *KopiaParseUtilsTestSuite) TestSnapshotStatsFromSnapshotRestore(c * args: args{ snapshotRestoreOutput: "Processed 2 (13.7 MB) of 2 (3.1 GB) 8.5 MB/s (0.4%) remaining 6m10s.", }, - wantStats: &SnapshotRestoreStats{ + wantStats: &RestoreStats{ FilesProcessed: 2, SizeProcessedB: 13700000, FilesTotal: 2, @@ -487,7 +487,7 @@ func (kParse *KopiaParseUtilsTestSuite) TestSnapshotStatsFromSnapshotRestore(c * args: args{ snapshotRestoreOutput: "Processed 2 (13.7 MB) of 2 (3.1 GB) 8.5 MB/s (120.4%) remaining 6m10s.", }, - wantStats: &SnapshotRestoreStats{ + wantStats: &RestoreStats{ FilesProcessed: 2, SizeProcessedB: 13700000, FilesTotal: 2, @@ -497,7 +497,7 @@ func (kParse *KopiaParseUtilsTestSuite) TestSnapshotStatsFromSnapshotRestore(c * }, } for _, tt := range tests { - stats := SnapshotStatsFromSnapshotRestore(tt.args.snapshotRestoreOutput) + stats := RestoreStatsFromRestoreOutput(tt.args.snapshotRestoreOutput) c.Check(stats, DeepEquals, tt.wantStats, Commentf("Failed for %s", tt.name)) } } From fc193682137af87e7a815cf681a199426943725f Mon Sep 17 00:00:00 2001 From: Eugen Sumin Date: Mon, 20 May 2024 06:35:49 +0200 Subject: [PATCH 4/8] Address review notes --- pkg/kopia/command/parse_command_output.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/kopia/command/parse_command_output.go b/pkg/kopia/command/parse_command_output.go index fb1b97a681..8a0b307695 100644 --- a/pkg/kopia/command/parse_command_output.go +++ b/pkg/kopia/command/parse_command_output.go @@ -207,8 +207,8 @@ type SnapshotCreateStats struct { } var ( - kopiaProgressPattern = regexp.MustCompile(snapshotCreateOutputRegEx) - kopiaSnapshotRestorePattern = regexp.MustCompile(snapshotRestoreOutputRegEx) + kopiaProgressPattern = regexp.MustCompile(snapshotCreateOutputRegEx) + kopiaRestorePattern = regexp.MustCompile(snapshotRestoreOutputRegEx) ) // SnapshotStatsFromSnapshotCreate parses the output of a kopia snapshot @@ -363,13 +363,13 @@ func RestoreStatsFromRestoreOutput(snapRestoreStderrOutput string) (stats *Resto // which expected to be in the following format: // Processed 5 (1.4 GB) of 5 (1.8 GB) 291.1 MB/s (75.2%) remaining 1s. func parseKopiaSnapshotRestoreProgressLine(line string) (stats *RestoreStats) { - match := kopiaSnapshotRestorePattern.FindStringSubmatch(line) + match := kopiaRestorePattern.FindStringSubmatch(line) if len(match) < 8 { return nil } groups := make(map[string]string) - for i, name := range kopiaSnapshotRestorePattern.SubexpNames() { + for i, name := range kopiaRestorePattern.SubexpNames() { if i != 0 && name != "" { groups[name] = match[i] } From cfefd78b41a0855c3b2ee94e00cce27f67e3725c Mon Sep 17 00:00:00 2001 From: Eugen Sumin Date: Mon, 20 May 2024 06:36:40 +0200 Subject: [PATCH 5/8] Address review notes --- pkg/kopia/command/parse_command_output.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/kopia/command/parse_command_output.go b/pkg/kopia/command/parse_command_output.go index 8a0b307695..91b3d24e44 100644 --- a/pkg/kopia/command/parse_command_output.go +++ b/pkg/kopia/command/parse_command_output.go @@ -343,11 +343,11 @@ type RestoreStats struct { // RestoreStatsFromRestoreOutput parses the output of a `kopia restore` // execution for a log of the stats for that execution. -func RestoreStatsFromRestoreOutput(snapRestoreStderrOutput string) (stats *RestoreStats) { - if snapRestoreStderrOutput == "" { +func RestoreStatsFromRestoreOutput(restoreStderrOutput string) (stats *RestoreStats) { + if restoreStderrOutput == "" { return nil } - logs := regexp.MustCompile("[\r\n]").Split(snapRestoreStderrOutput, -1) + logs := regexp.MustCompile("[\r\n]").Split(restoreStderrOutput, -1) for _, l := range logs { lineStats := parseKopiaSnapshotRestoreProgressLine(l) From 222b34b296020092041e5c46888ff39e053660e3 Mon Sep 17 00:00:00 2001 From: Eugene Sumin <95425330+e-sumin@users.noreply.github.com> Date: Mon, 20 May 2024 20:36:27 +0200 Subject: [PATCH 6/8] Apply suggestions from code review Co-authored-by: Vivek Singh --- pkg/kopia/command/parse_command_output.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/kopia/command/parse_command_output.go b/pkg/kopia/command/parse_command_output.go index 91b3d24e44..4c7f9d77cd 100644 --- a/pkg/kopia/command/parse_command_output.go +++ b/pkg/kopia/command/parse_command_output.go @@ -406,9 +406,9 @@ func parseKopiaSnapshotRestoreProgressLine(line string) (stats *RestoreStats) { } if progressPercent >= 100 { - // It may happen that kopia reports progress of 100 or higher without actual + // It may happen that kopia reports progress of 100 or higher without actually // completing the task. This can occur due to inaccurate estimation. - // In such case, we will return the progress as 99% to avoid confusion. + // In such cases, we will return the progress as 99% to avoid confusion. progressPercent = 99 } From 2547a8db97363391049f20b396b5ab94dd41fd96 Mon Sep 17 00:00:00 2001 From: Eugen Sumin Date: Mon, 20 May 2024 20:36:42 +0200 Subject: [PATCH 7/8] Address review notes --- pkg/kopia/command/parse_command_output.go | 27 +++++++++++++++-------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/pkg/kopia/command/parse_command_output.go b/pkg/kopia/command/parse_command_output.go index 4c7f9d77cd..0dfe1ce6be 100644 --- a/pkg/kopia/command/parse_command_output.go +++ b/pkg/kopia/command/parse_command_output.go @@ -211,9 +211,14 @@ var ( kopiaRestorePattern = regexp.MustCompile(snapshotRestoreOutputRegEx) ) -// SnapshotStatsFromSnapshotCreate parses the output of a kopia snapshot -// create execution for a log of the stats for that execution. -func SnapshotStatsFromSnapshotCreate(snapCreateStderrOutput string, matchOnlyFinished bool) (stats *SnapshotCreateStats) { +// SnapshotStatsFromSnapshotCreate parses the output of a `kopia snapshot +// create` line-by-line in search of progress statistics. +// It returns nil if no statistics are found, or the most recent statistic +// if multiple are encountered. +func SnapshotStatsFromSnapshotCreate( + snapCreateStderrOutput string, + matchOnlyFinished bool, +) (stats *SnapshotCreateStats) { if snapCreateStderrOutput == "" { return nil } @@ -342,15 +347,19 @@ type RestoreStats struct { } // RestoreStatsFromRestoreOutput parses the output of a `kopia restore` -// execution for a log of the stats for that execution. -func RestoreStatsFromRestoreOutput(restoreStderrOutput string) (stats *RestoreStats) { +// line-by-line in search of progress statistics. +// It returns nil if no statistics are found, or the most recent statistic +// if multiple are encountered. +func RestoreStatsFromRestoreOutput( + restoreStderrOutput string, +) (stats *RestoreStats) { if restoreStderrOutput == "" { return nil } logs := regexp.MustCompile("[\r\n]").Split(restoreStderrOutput, -1) for _, l := range logs { - lineStats := parseKopiaSnapshotRestoreProgressLine(l) + lineStats := parseKopiaRestoreProgressLine(l) if lineStats != nil { stats = lineStats } @@ -359,10 +368,10 @@ func RestoreStatsFromRestoreOutput(restoreStderrOutput string) (stats *RestoreSt return stats } -// parseKopiaSnapshotRestoreProgressLine parses restore stats from line -// which expected to be in the following format: +// parseKopiaRestoreProgressLine parses restore stats from the output log line, +// which is expected to be in the following format: // Processed 5 (1.4 GB) of 5 (1.8 GB) 291.1 MB/s (75.2%) remaining 1s. -func parseKopiaSnapshotRestoreProgressLine(line string) (stats *RestoreStats) { +func parseKopiaRestoreProgressLine(line string) (stats *RestoreStats) { match := kopiaRestorePattern.FindStringSubmatch(line) if len(match) < 8 { return nil From 92c4a3a003d44209c06da685c7171e8a651404bc Mon Sep 17 00:00:00 2001 From: Eugen Sumin Date: Tue, 21 May 2024 10:03:49 +0200 Subject: [PATCH 8/8] Rename SnapshotRestore to Restore --- pkg/kopia/command/parse_command_output.go | 4 ++-- pkg/kopia/command/parse_command_output_test.go | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/kopia/command/parse_command_output.go b/pkg/kopia/command/parse_command_output.go index 0dfe1ce6be..1789d64138 100644 --- a/pkg/kopia/command/parse_command_output.go +++ b/pkg/kopia/command/parse_command_output.go @@ -39,7 +39,7 @@ const ( //nolint:lll snapshotCreateOutputRegEx = `(?P[|/\-\\\*]).+[^\d](?P\d+) hashed \((?P[^\)]+)\), (?P\d+) cached \((?P[^\)]+)\), uploaded (?P[^\)]+), (?:estimating...|estimated (?P[^\)]+) \((?P[^\)]+)\%\).+)` - snapshotRestoreOutputRegEx = `Processed (?P\d+) \((?P.*)\) of (?P\d+) \((?P.*)\) (?P.*) \((?P.*)%\) remaining (?P.*)\.` + restoreOutputRegEx = `Processed (?P\d+) \((?P.*)\) of (?P\d+) \((?P.*)\) (?P.*) \((?P.*)%\) remaining (?P.*)\.` extractSnapshotIDRegEx = `Created snapshot with root ([^\s]+) and ID ([^\s]+).*$` repoTotalSizeFromBlobStatsRegEx = `Total: (\d+)$` repoCountFromBlobStatsRegEx = `Count: (\d+)$` @@ -208,7 +208,7 @@ type SnapshotCreateStats struct { var ( kopiaProgressPattern = regexp.MustCompile(snapshotCreateOutputRegEx) - kopiaRestorePattern = regexp.MustCompile(snapshotRestoreOutputRegEx) + kopiaRestorePattern = regexp.MustCompile(restoreOutputRegEx) ) // SnapshotStatsFromSnapshotCreate parses the output of a `kopia snapshot diff --git a/pkg/kopia/command/parse_command_output_test.go b/pkg/kopia/command/parse_command_output_test.go index e42783207f..67671e78c4 100644 --- a/pkg/kopia/command/parse_command_output_test.go +++ b/pkg/kopia/command/parse_command_output_test.go @@ -440,9 +440,9 @@ func (kParse *KopiaParseUtilsTestSuite) TestSnapshotStatsFromSnapshotCreate(c *C } } -func (kParse *KopiaParseUtilsTestSuite) TestSnapshotStatsFromSnapshotRestore(c *C) { +func (kParse *KopiaParseUtilsTestSuite) TestRestoreStatsFromRestoreOutput(c *C) { type args struct { - snapshotRestoreOutput string + restoreOutput string } tests := []struct { name string @@ -452,7 +452,7 @@ func (kParse *KopiaParseUtilsTestSuite) TestSnapshotStatsFromSnapshotRestore(c * { name: "Basic test case", args: args{ - snapshotRestoreOutput: "Processed 2 (397.5 MB) of 3 (3.1 GB) 14.9 MB/s (12.6%) remaining 3m3s.", + restoreOutput: "Processed 2 (397.5 MB) of 3 (3.1 GB) 14.9 MB/s (12.6%) remaining 3m3s.", }, wantStats: &RestoreStats{ FilesProcessed: 2, @@ -465,7 +465,7 @@ func (kParse *KopiaParseUtilsTestSuite) TestSnapshotStatsFromSnapshotRestore(c * { name: "Real test case", args: args{ - snapshotRestoreOutput: "Processed 2 (13.7 MB) of 2 (3.1 GB) 8.5 MB/s (0.4%) remaining 6m10s.", + restoreOutput: "Processed 2 (13.7 MB) of 2 (3.1 GB) 8.5 MB/s (0.4%) remaining 6m10s.", }, wantStats: &RestoreStats{ FilesProcessed: 2, @@ -478,14 +478,14 @@ func (kParse *KopiaParseUtilsTestSuite) TestSnapshotStatsFromSnapshotRestore(c * { name: "Ignore incomplete stats without during estimation", args: args{ - snapshotRestoreOutput: "Processed 2 (32.8 KB) of 2 (3.1 GB).", + restoreOutput: "Processed 2 (32.8 KB) of 2 (3.1 GB).", }, wantStats: nil, }, { name: "Progress is over 100% and still not ready - set 99%", args: args{ - snapshotRestoreOutput: "Processed 2 (13.7 MB) of 2 (3.1 GB) 8.5 MB/s (120.4%) remaining 6m10s.", + restoreOutput: "Processed 2 (13.7 MB) of 2 (3.1 GB) 8.5 MB/s (120.4%) remaining 6m10s.", }, wantStats: &RestoreStats{ FilesProcessed: 2, @@ -497,7 +497,7 @@ func (kParse *KopiaParseUtilsTestSuite) TestSnapshotStatsFromSnapshotRestore(c * }, } for _, tt := range tests { - stats := RestoreStatsFromRestoreOutput(tt.args.snapshotRestoreOutput) + stats := RestoreStatsFromRestoreOutput(tt.args.restoreOutput) c.Check(stats, DeepEquals, tt.wantStats, Commentf("Failed for %s", tt.name)) } }