Hi,
I am trying to all `kopia snapshot create’ from os.exec(), on success trying to parse the JSON output but not able to fetch the size
Here is the sample output
{\"id\":\"8f2e36f02815fe71747cc5b9fc781bb2\",\"source\":{\"host\":\"kopia-aws-mysql-1-rst-mysql-data-jh4ct\",\"userName\":\"root\",\"path\":\"/data/pvc-c6826179-acf4-481d-a724-b1b6ff5f444c\"},\"description\":\"\",\"startTime\":\"2021-08-31T19:04:46.101549214Z\",\"endTime\":\"2021-08-31T19:04:46.766772951Z\",\"rootEntry\":{\"name\":\"pvc-c6826179-acf4-481d-a724-b1b6ff5f444c\",\"type\":\"d\",\"mode\":\"0755\",\"mtime\":\"2021-07-09T11:09:33.641023675Z\",\"uid\":999,\"obj\":\"k8d44668936971a31de23ab25c2ffffcd\",\"summ\":{\"size\":120861096,\"files\":136,\"symlinks\":0,\"dirs\":3,\"maxTime\":\"2021-07-09T11:09:35.734024033Z\",\"numFailed\":0}}}"
Here is the structure for JSON urmashalling i used (took fron kopis src)
// BackupSummaryResponse describes single snapshot entry.
type BackupSummaryResponse struct {
ID string `json:"id"`
Source SourceInfo `json:"source"`
Description string `json:"description"`
StartTime time.Time `json:"startTime"`
EndTime time.Time `json:"endTime"`
IncompleteReason string `json:"incomplete,omitempty"`
Summary DirectorySummary `json:"summ"`
RootEntry string `json:"rootID"`
RetentionReasons []string `json:"retention"`
}
// DirectorySummary represents summary information about a directory.
type DirectorySummary struct {
TotalFileSize int64 `json:"size"`
TotalFileCount int64 `json:"files"`
TotalSymlinkCount int64 `json:"symlinks"`
TotalDirCount int64 `json:"dirs"`
MaxModTime time.Time `json:"maxTime"`
IncompleteReason string `json:"incomplete,omitempty"`
// number of failed files
FatalErrorCount int `json:"numFailed"`
IgnoredErrorCount int `json:"numIgnoredErrors,omitempty"`
FailedEntries []*EntryWithError `json:"errors,omitempty"`
}
When i Unmarshal
summaryResponse := &BackupSummaryResponse{
Summary: DirectorySummary{},
}
json.Unmarshal(outResponse, summaryResponse);
And upon printing the JSON unmarshalled output, not able to see TotalSize
summaryResponse: &{ID:8f2e36f02815fe71747cc5b9fc781bb2 Source:{Host:kopia-aws-mysql-1-rst-mysql-data-jh4ct UserName:root Path:/data/pvc-c6826179-acf4-481d-a724-b1b6ff5f444c} Description: StartTime:2021-08-31 19:04:46.101549214 +0000 UTC EndTime:2021-08-31 19:04:46.766772951 +0000 UTC IncompleteReason: Summary:{TotalFileSize:0 TotalFileCount:0 TotalSymlinkCount:0 TotalDirCount:0 MaxModTime:0001-01-01 00:00:00 +0000 UTC IncompleteReason: FatalErrorCount:0 IgnoredErrorCount:0 FailedEntries:[]} RootEntry: RetentionReasons:[]}"
time="2021-08-31T19:04:47Z" level=info msg="line 220 summaryResponse.Summary: {TotalFileSize:0 TotalFileCount:0 TotalSymlinkCount:0 TotalDirCount:0 MaxModTime:0001-01-01 00:00:00 +0000 UTC IncompleteReason: FatalErrorCount:0 IgnoredErrorCount:0 FailedEntries:[]}"
I tried json tag summ
and summary
both didn’t help
I also tried by making Summary as pointer, didn’t help
Summary * DirectorySummary json:"summ"
Can you please let me know what i am missing here?