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 21, 2024
1 parent 3a87ee0 commit 823fe2c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
4 changes: 4 additions & 0 deletions backupstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Volume struct {
CompressionMethod string `json:",string"`
StorageClassName string `json:",string"`
DataEngine string `json:",string"`
BackupTimes int64 `json:",string"`
}

type Snapshot struct {
Expand Down Expand Up @@ -74,6 +75,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.BackupTimes = 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.BackupTimes = volume.BackupTimes + 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
}
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 823fe2c

Please sign in to comment.