Skip to content

Commit

Permalink
backup: move common functions and types to backupstore lib
Browse files Browse the repository at this point in the history
Longhorn 6138

Signed-off-by: Derek Su <[email protected]>
  • Loading branch information
derekbit authored and PhanLe1010 committed Sep 14, 2023
1 parent 206f08f commit b422245
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 173 deletions.
5 changes: 3 additions & 2 deletions app/cmd/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/urfave/cli"

"github.com/longhorn/backupstore/cmd"
butil "github.com/longhorn/backupstore/util"

replicaClient "github.com/longhorn/longhorn-engine/pkg/replica/client"
"github.com/longhorn/longhorn-engine/pkg/sync"
Expand Down Expand Up @@ -262,7 +263,7 @@ func createBackup(c *cli.Context) error {
}
}

credential, err := util.GetBackupCredential(dest)
credential, err := butil.GetBackupCredential(dest)
if err != nil {
return err
}
Expand Down Expand Up @@ -308,7 +309,7 @@ func restoreBackup(c *cli.Context) error {
}
backupURL := util.UnescapeURL(backup)

credential, err := util.GetBackupCredential(backup)
credential, err := butil.GetBackupCredential(backup)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/backup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type CreateBackupParameters struct {
BackingImageChecksum string
CompressionMethod string
ConcurrentLimit int32
StorageClassname string
StorageClassName string
Labels []string
}

Expand Down Expand Up @@ -110,7 +110,7 @@ func DoBackupInit(params *CreateBackupParameters) (*replica.BackupStatus, *backu
BackingImageName: params.BackingImageName,
BackingImageChecksum: params.BackingImageChecksum,
CompressionMethod: params.CompressionMethod,
StorageClassName: params.StorageClassname,
StorageClassName: params.StorageClassName,
CreatedTime: util.Now(),
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/replica/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"

"github.com/longhorn/backupstore"
btypes "github.com/longhorn/backupstore/types"
butil "github.com/longhorn/backupstore/util"

"github.com/longhorn/longhorn-engine/pkg/backingfile"
Expand Down Expand Up @@ -288,7 +288,7 @@ func (rb *BackupStatus) CloseSnapshot(snapID, volumeID string) error {
return err
}

func (rb *BackupStatus) CompareSnapshot(snapID, compareSnapID, volumeID string) (*backupstore.Mappings, error) {
func (rb *BackupStatus) CompareSnapshot(snapID, compareSnapID, volumeID string) (*btypes.Mappings, error) {
id := diskutil.GenerateSnapshotDiskName(snapID)
compareID := ""
if compareSnapID != "" {
Expand All @@ -314,10 +314,10 @@ func (rb *BackupStatus) CompareSnapshot(snapID, compareSnapID, volumeID string)
return nil, fmt.Errorf("failed to find snapshot %s in chain", compareID)
}

mappings := &backupstore.Mappings{
mappings := &btypes.Mappings{
BlockSize: snapBlockSize,
}
mapping := backupstore.Mapping{
mapping := btypes.Mapping{
Offset: -1,
}

Expand All @@ -331,7 +331,7 @@ func (rb *BackupStatus) CompareSnapshot(snapID, compareSnapID, volumeID string)
// align
offset -= (offset % snapBlockSize)
if mapping.Offset != offset {
mapping = backupstore.Mapping{
mapping = btypes.Mapping{
Offset: offset,
Size: snapBlockSize,
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/sync/rpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"google.golang.org/grpc/reflection"

"github.com/longhorn/backupstore"
butil "github.com/longhorn/backupstore/util"
"github.com/longhorn/sparse-tools/sparse"
sparserest "github.com/longhorn/sparse-tools/sparse/rest"

Expand Down Expand Up @@ -681,12 +682,12 @@ func (s *SyncAgentServer) SnapshotCloneStatus(ctx context.Context, req *empty.Em
}

func (s *SyncAgentServer) BackupCreate(ctx context.Context, req *ptypes.BackupCreateRequest) (*ptypes.BackupCreateResponse, error) {
backupType, err := util.CheckBackupType(req.BackupTarget)
backupType, err := butil.CheckBackupType(req.BackupTarget)
if err != nil {
return nil, err
}

if err := util.SetupCredential(backupType, req.Credential); err != nil {
if err := butil.SetupCredential(backupType, req.Credential); err != nil {
return nil, err
}

Expand All @@ -706,7 +707,7 @@ func (s *SyncAgentServer) BackupCreate(ctx context.Context, req *ptypes.BackupCr
BackingImageChecksum: req.BackingImageChecksum,
CompressionMethod: req.CompressionMethod,
ConcurrentLimit: req.ConcurrentLimit,
StorageClassname: req.StorageClassName,
StorageClassName: req.StorageClassName,
Labels: req.Labels,
})
if err != nil {
Expand Down Expand Up @@ -815,12 +816,12 @@ func (s *SyncAgentServer) BackupRestore(ctx context.Context, req *ptypes.BackupR
return nil, fmt.Errorf("empty backup URL for the restore")
}

backupType, err := util.CheckBackupType(req.Backup)
backupType, err := butil.CheckBackupType(req.Backup)
if err != nil {
return nil, errors.Wrapf(err, "failed to check the type for backup %v", req.Backup)
}

if err := util.SetupCredential(backupType, req.Credential); err != nil {
if err := butil.SetupCredential(backupType, req.Credential); err != nil {
return nil, errors.Wrapf(err, "failed to setup credential for backup %v", req.Backup)
}

Expand Down
159 changes: 0 additions & 159 deletions pkg/util/credential.go

This file was deleted.

0 comments on commit b422245

Please sign in to comment.