Skip to content

Commit

Permalink
Return snapshot size from kopia snapshot manifest (#1016)
Browse files Browse the repository at this point in the history
* Add progress update to capture stats

* Use stats in the manifest

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
pavannd1 and mergify[bot] committed Jun 11, 2021
1 parent 2434637 commit 936c938
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
23 changes: 12 additions & 11 deletions pkg/kopia/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions pkg/kopia/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 936c938

Please sign in to comment.