diff --git a/pkg/kopia/snapshot.go b/pkg/kopia/snapshot.go index 5f71cac8b0..4170a7ab37 100644 --- a/pkg/kopia/snapshot.go +++ b/pkg/kopia/snapshot.go @@ -36,50 +36,51 @@ func SnapshotSource( sourceInfo snapshot.SourceInfo, rootDir fs.Entry, description string, -) (string, string, error) { +) (snapID string, snapSize int64, err error) { fmt.Printf("Snapshotting %v ...\n", sourceInfo) t0 := time.Now() previous, err := findPreviousSnapshotManifest(ctx, rep, sourceInfo, nil) if err != nil { - return "", "", errors.Wrap(err, "Failed to find previous kopia manifests") + return "", 0, errors.Wrap(err, "Failed to find previous kopia manifests") } policyTree, err := policy.TreeForSource(ctx, rep, sourceInfo) if err != nil { - return "", "", errors.Wrap(err, "Failed to get kopia policy tree") + return "", 0, errors.Wrap(err, "Failed to get kopia policy tree") } manifest, err := u.Upload(ctx, rootDir, policyTree, sourceInfo, previous...) if err != nil { - return "", "", errors.Wrap(err, "Failed to upload the kopia snapshot") + return "", 0, errors.Wrap(err, "Failed to upload the kopia snapshot") } manifest.Description = description - snapID, err := snapshot.SaveSnapshot(ctx, rep, manifest) + manifestID, err := snapshot.SaveSnapshot(ctx, rep, manifest) if err != nil { - return "", "", errors.Wrap(err, "Failed to save kopia manifest") + return "", 0, errors.Wrap(err, "Failed to save kopia manifest") } _, err = policy.ApplyRetentionPolicy(ctx, rep, sourceInfo, true) if err != nil { - return "", "", errors.Wrap(err, "Failed to apply kopia retention policy") + return "", 0, errors.Wrap(err, "Failed to apply kopia retention policy") } if err = policy.SetManual(ctx, rep, sourceInfo); err != nil { - return "", "", errors.Wrap(err, "Failed to set manual field in kopia scheduling policy for source") + return "", 0, errors.Wrap(err, "Failed to set manual field in kopia scheduling policy for source") } if ferr := rep.Flush(ctx); ferr != nil { - return "", "", errors.Wrap(ferr, "Failed to flush kopia repository") + return "", 0, errors.Wrap(ferr, "Failed to flush kopia repository") } - // TODO: Add size related logs for parsing + snapSize = manifest.Stats.TotalFileSize + fmt.Printf("\nCreated snapshot with root %v and ID %v in %v\n", manifest.RootObjectID(), snapID, time.Since(t0).Truncate(time.Second)) - return string(snapID), string(manifest.RootObjectID()), nil + return string(manifestID), snapSize, nil } // DeleteSnapshot deletes Kopia snapshot with given manifest ID diff --git a/pkg/kopia/stream.go b/pkg/kopia/stream.go index 9b891464ba..10dc085569 100644 --- a/pkg/kopia/stream.go +++ b/pkg/kopia/stream.go @@ -46,7 +46,7 @@ type SnapshotInfo struct { ID string `json:"id"` // LogicalSize is the sum of cached and hashed file size in bytes LogicalSize int64 `json:"logicalSize"` - // LogicalSize is the uploaded size in bytes + // PhysicalSize is the uploaded size in bytes PhysicalSize int64 `json:"physicalSize"` } @@ -100,17 +100,15 @@ func Write(ctx context.Context, path string, source io.Reader) (*SnapshotInfo, e u := snapshotfs.NewUploader(rep) // Create a kopia snapshot - snapID, _, err := SnapshotSource(ctx, rep, u, sourceInfo, rootDir, "Kanister Database Backup") + snapID, snapshotSize, err := SnapshotSource(ctx, rep, u, sourceInfo, rootDir, "Kanister Database Backup") if err != nil { return nil, err } - // TODO@pavan: Add kopia snapshot size information - zeroSize := int64(0) snapshotInfo := &SnapshotInfo{ ID: snapID, - LogicalSize: zeroSize, - PhysicalSize: zeroSize, + LogicalSize: snapshotSize, + PhysicalSize: int64(0), } return snapshotInfo, nil