Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return snapshot size from kopia snapshot manifest #1016

Merged
merged 3 commits into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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