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 <[email protected]>
  • Loading branch information
ChanYiLin committed Mar 19, 2024
1 parent 3a87ee0 commit 4991090
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
16 changes: 14 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 @@ -1303,3 +1306,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
}
12 changes: 12 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,12 @@ const (
NOProxy = "NO_PROXY"

VirtualHostedStyle = "VIRTUAL_HOSTED_STYLE"

LonghornLabelKeyPrefix = "longhorn.io"

LonghornBackupOptionBackupMode = "backup-mode"
LonghornBackupModeFull = "full"
LonghornBackupModeIncremental = "incremental"
)

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

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

0 comments on commit 4991090

Please sign in to comment.