Skip to content

Commit

Permalink
feat: support full backup
Browse files Browse the repository at this point in the history
ref: longhorn/longhorn 7070

Signed-off-by: Jack Lin <jack.lin@suse.com>
  • Loading branch information
ChanYiLin committed Mar 22, 2024
1 parent 3a87ee0 commit ab6fa5e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
7 changes: 7 additions & 0 deletions backupstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ type Volume struct {
CompressionMethod string `json:",string"`
StorageClassName string `json:",string"`
DataEngine string `json:",string"`

// It is not the count of the current backup on the backupstore,
// but how many backups of the volume have been created before.
BackupCount int64 `json:",string"`
}

type Snapshot struct {
Expand Down Expand Up @@ -74,6 +78,9 @@ func addVolume(driver BackupStoreDriver, volume *Volume) error {
return fmt.Errorf("invalid volume name %v", volume.Name)
}

// first time create backup volume means first time create backup on this backupstore
volume.BackupCount = 0

if err := saveVolume(driver, volume); err != nil {
log.WithError(err).Errorf("Failed to add volume %v", volume.Name)
return err
Expand Down
17 changes: 15 additions & 2 deletions deltablock.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func CreateDeltaBlockBackup(backupName string, config *DeltaBackupConfig) (isInc
}

backupRequest := &backupRequest{}
if volume.LastBackupName != "" {
if volume.LastBackupName != "" && !isFullBackup(config) {
lastBackupName := volume.LastBackupName
var backup, err = loadBackup(bsDriver, lastBackupName, volume.Name)
if err != nil {
Expand Down Expand Up @@ -208,6 +208,9 @@ func CreateDeltaBlockBackup(backupName string, config *DeltaBackupConfig) (isInc
}
}

logrus.Infof("[DEBUG] isFullBackup(config): %v", isFullBackup(config))
logrus.Infof("[DEBUG] backupRequest.lastBackup: %v", backupRequest.lastBackup)

log.WithFields(logrus.Fields{
LogFieldReason: LogReasonStart,
LogFieldObject: LogObjectSnapshot,
Expand Down Expand Up @@ -368,7 +371,7 @@ func backupBlock(bsDriver BackupStoreDriver, config *DeltaBackupConfig,
}()

blkFile := getBlockFilePath(volume.Name, checksum)
if bsDriver.FileExists(blkFile) {
if bsDriver.FileExists(blkFile) && !isFullBackup(config) {
log.Debugf("Found existing block matching at %v", blkFile)
return nil
}
Expand Down Expand Up @@ -554,6 +557,7 @@ func performBackup(bsDriver BackupStoreDriver, config *DeltaBackupConfig, delta
volume.CompressionMethod = config.Volume.CompressionMethod
volume.StorageClassName = config.Volume.StorageClassName
volume.DataEngine = config.Volume.DataEngine
volume.BackupCount = volume.BackupCount + 1

if err := saveVolume(bsDriver, volume); err != nil {
return progress.progress, "", err
Expand Down Expand Up @@ -1303,3 +1307,12 @@ func getBlockNamesForVolume(driver BackupStoreDriver, volumeName string) ([]stri

return util.ExtractNames(names, "", BLK_SUFFIX), nil
}

func isFullBackup(config *DeltaBackupConfig) bool {
if config.Labels != nil {
if backupMode, exist := config.Labels[types.GetLonghornLabelKey(types.LonghornBackupOptionBackupMode)]; exist {
return backupMode == types.LonghornBackupModeFull
}
}
return false
}
1 change: 1 addition & 0 deletions inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func fillVolumeInfo(volume *Volume) *VolumeInfo {
BackingImageChecksum: volume.BackingImageChecksum,
StorageClassname: volume.StorageClassName,
DataEngine: volume.DataEngine,
BackupCount: volume.BackupCount,
}
}

Expand Down
1 change: 1 addition & 0 deletions list.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type VolumeInfo struct {
BackingImageChecksum string
StorageClassname string
DataEngine string
BackupCount int64 `json:",string"`
}

type BackupInfo struct {
Expand Down
16 changes: 16 additions & 0 deletions types/types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package types

import "fmt"

type ProgressState string

const (
Expand Down Expand Up @@ -29,6 +31,16 @@ const (
NOProxy = "NO_PROXY"

VirtualHostedStyle = "VIRTUAL_HOSTED_STYLE"

LonghornLabelKeyPrefix = "longhorn.io"
)

const (
LonghornBackupOptionBackupMode = "backup-mode"
LonghornBackupModeFull = "full"
LonghornBackupModeIncremental = "incremental"

LonghornBackupOptionFullBackupInterval = "full-backup-interval"
)

type Mapping struct {
Expand Down Expand Up @@ -65,3 +77,7 @@ const (
const (
ErrorMsgRestoreCancelled = "backup restoration is cancelled"
)

func GetLonghornLabelKey(name string) string {
return fmt.Sprintf("%s/%s", LonghornLabelKeyPrefix, name)
}

0 comments on commit ab6fa5e

Please sign in to comment.