diff --git a/deltablock.go b/deltablock.go index 73851e53b..56d23f641 100644 --- a/deltablock.go +++ b/deltablock.go @@ -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 { @@ -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, @@ -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 } @@ -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 +} diff --git a/types/types.go b/types/types.go index bc626cc5f..bc16f74f3 100644 --- a/types/types.go +++ b/types/types.go @@ -1,5 +1,7 @@ package types +import "fmt" + type ProgressState string const ( @@ -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 { @@ -65,3 +73,7 @@ const ( const ( ErrorMsgRestoreCancelled = "backup restoration is cancelled" ) + +func GetLonghornLabelKey(name string) string { + return fmt.Sprintf("%s/%s", LonghornLabelKeyPrefix, name) +}