Skip to content

Commit

Permalink
support: modify backup type named for backup policy (apecloud#3227)
Browse files Browse the repository at this point in the history
  • Loading branch information
dengshaojiang authored May 15, 2023
1 parent 54e1b56 commit 4a2cff3
Show file tree
Hide file tree
Showing 37 changed files with 387 additions and 320 deletions.
39 changes: 21 additions & 18 deletions apis/apps/v1alpha1/backuppolicytemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,9 @@ type BackupPolicy struct {
// +kubebuilder:validation:Pattern:=`^[a-z0-9]([a-z0-9\.\-]*[a-z0-9])?$`
ComponentDefRef string `json:"componentDefRef"`

// ttl is a time string ending with the 'd'|'D'|'h'|'H' character to describe how long
// the Backup should be retained. if not set, will be retained forever.
// +kubebuilder:validation:Pattern:=`^\d+[d|D|h|H]$`
// retention describe how long the Backup should be retained. if not set, will be retained forever.
// +optional
TTL *string `json:"ttl,omitempty"`
Retention *RetentionSpec `json:"retention,omitempty"`

// schedule policy for backup.
// +optional
Expand All @@ -69,30 +67,35 @@ type BackupPolicy struct {
// +optional
Snapshot *SnapshotPolicy `json:"snapshot,omitempty"`

// the policy for full backup.
// the policy for datafile backup.
// +optional
Full *CommonBackupPolicy `json:"full,omitempty"`
Datafile *CommonBackupPolicy `json:"datafile,omitempty"`

// the policy for logfile backup.
// +optional
Logfile *CommonBackupPolicy `json:"logfile,omitempty"`
}

// the policy for incremental backup.
type RetentionSpec struct {
// ttl is a time string ending with the 'd'|'D'|'h'|'H' character to describe how long
// the Backup should be retained. if not set, will be retained forever.
// +kubebuilder:validation:Pattern:=`^\d+[d|D|h|H]$`
// +optional
Incremental *CommonBackupPolicy `json:"incremental,omitempty"`
TTL *string `json:"ttl,omitempty"`
}

type Schedule struct {
// schedule policy for base backup.
// schedule policy for snapshot backup.
// +optional
BaseBackup *BaseBackupSchedulePolicy `json:"baseBackup,omitempty"`
Snapshot *SchedulePolicy `json:"snapshot,omitempty"`

// schedule policy for incremental backup.
// schedule policy for datafile backup.
// +optional
Incremental *SchedulePolicy `json:"incremental,omitempty"`
}
Datafile *SchedulePolicy `json:"datafile,omitempty"`

type BaseBackupSchedulePolicy struct {
SchedulePolicy `json:",inline"`
// the type of base backup, only support full and snapshot.
// +kubebuilder:validation:Required
Type BaseBackupType `json:"type"`
// schedule policy for logfile backup.
// +optional
Logfile *SchedulePolicy `json:"logfile,omitempty"`
}

type SchedulePolicy struct {
Expand Down
20 changes: 10 additions & 10 deletions apis/dataprotection/v1alpha1/backup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ type BackupSpec struct {
// +kubebuilder:validation:Pattern:=`^[a-z0-9]([a-z0-9\.\-]*[a-z0-9])?$`
BackupPolicyName string `json:"backupPolicyName"`

// Backup Type. full or incremental or snapshot. if unset, default is full.
// +kubebuilder:default=full
// Backup Type. datafile or logfile or snapshot. if unset, default is datafile.
// +kubebuilder:default=datafile
BackupType BackupType `json:"backupType"`

// if backupType is incremental, parentBackupName is required.
Expand Down Expand Up @@ -195,13 +195,13 @@ func (r *BackupSpec) Validate(backupPolicy *BackupPolicy) error {
if backupPolicy.Spec.Snapshot == nil {
return fmt.Errorf(notSupportedMessage, r.BackupPolicyName, BackupTypeSnapshot)
}
case BackupTypeFull:
if backupPolicy.Spec.Full == nil {
return fmt.Errorf(notSupportedMessage, r.BackupPolicyName, BackupTypeFull)
case BackupTypeDataFile:
if backupPolicy.Spec.Datafile == nil {
return fmt.Errorf(notSupportedMessage, r.BackupPolicyName, BackupTypeDataFile)
}
case BackupTypeIncremental:
if backupPolicy.Spec.Incremental == nil {
return fmt.Errorf(notSupportedMessage, r.BackupPolicyName, BackupTypeIncremental)
case BackupTypeLogFile:
if backupPolicy.Spec.Logfile == nil {
return fmt.Errorf(notSupportedMessage, r.BackupPolicyName, BackupTypeLogFile)
}
}
return nil
Expand All @@ -217,9 +217,9 @@ func GetRecoverableTimeRange(backups []Backup) []BackupLogStatus {
b.Status.Manifests.BackupLog.StopTime == nil {
continue
}
if b.Spec.BackupType == BackupTypeIncremental {
if b.Spec.BackupType == BackupTypeLogFile {
incrementalBackup = &b
} else if b.Spec.BackupType != BackupTypeIncremental && b.Status.Phase == BackupCompleted {
} else if b.Spec.BackupType != BackupTypeLogFile && b.Status.Phase == BackupCompleted {
baseBackups = append(baseBackups, b)
}
}
Expand Down
47 changes: 25 additions & 22 deletions apis/dataprotection/v1alpha1/backuppolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ import (

// BackupPolicySpec defines the desired state of BackupPolicy
type BackupPolicySpec struct {
// ttl is a time string ending with the 'd'|'D'|'h'|'H' character to describe how long
// the Backup should be retained. if not set, will be retained forever.
// +kubebuilder:validation:Pattern:=`^\d+[d|D|h|H]$`
// retention describe how long the Backup should be retained. if not set, will be retained forever.
// +optional
TTL *string `json:"ttl,omitempty"`
Retention *RetentionSpec `json:"retention,omitempty"`

// schedule policy for backup.
// +optional
Expand All @@ -44,30 +42,35 @@ type BackupPolicySpec struct {
// +optional
Snapshot *SnapshotPolicy `json:"snapshot,omitempty"`

// the policy for full backup.
// the policy for datafile backup.
// +optional
Full *CommonBackupPolicy `json:"full,omitempty"`
Datafile *CommonBackupPolicy `json:"datafile,omitempty"`

// the policy for logfile backup.
// +optional
Logfile *CommonBackupPolicy `json:"logfile,omitempty"`
}

// the policy for incremental backup.
type RetentionSpec struct {
// ttl is a time string ending with the 'd'|'D'|'h'|'H' character to describe how long
// the Backup should be retained. if not set, will be retained forever.
// +kubebuilder:validation:Pattern:=`^\d+[d|D|h|H]$`
// +optional
Incremental *CommonBackupPolicy `json:"incremental,omitempty"`
TTL *string `json:"ttl,omitempty"`
}

type Schedule struct {
// schedule policy for base backup.
// schedule policy for snapshot backup.
// +optional
BaseBackup *BaseBackupSchedulePolicy `json:"baseBackup,omitempty"`
Snapshot *SchedulePolicy `json:"snapshot,omitempty"`

// schedule policy for incremental backup.
// schedule policy for datafile backup.
// +optional
Incremental *SchedulePolicy `json:"incremental,omitempty"`
}
Datafile *SchedulePolicy `json:"datafile,omitempty"`

type BaseBackupSchedulePolicy struct {
SchedulePolicy `json:",inline"`
// the type of base backup, only support full and snapshot.
// +kubebuilder:validation:Required
Type BaseBackupType `json:"type"`
// schedule policy for logfile backup.
// +optional
Logfile *SchedulePolicy `json:"logfile,omitempty"`
}

type SchedulePolicy struct {
Expand Down Expand Up @@ -301,10 +304,10 @@ func init() {

func (r *BackupPolicySpec) GetCommonPolicy(backupType BackupType) *CommonBackupPolicy {
switch backupType {
case BackupTypeFull:
return r.Full
case BackupTypeIncremental:
return r.Incremental
case BackupTypeDataFile:
return r.Datafile
case BackupTypeLogFile:
return r.Logfile
}
return nil
}
Expand Down
15 changes: 5 additions & 10 deletions apis/dataprotection/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,22 @@ const (
BackupFailed BackupPhase = "Failed"
)

// BackupType the backup type, marked backup set is full or incremental or snapshot.
// BackupType the backup type, marked backup set is datafile or logfile or snapshot.
// +enum
// +kubebuilder:validation:Enum={full,incremental,snapshot}
// +kubebuilder:validation:Enum={datafile,logfile,snapshot}
type BackupType string

const (
BackupTypeFull BackupType = "full"
BackupTypeIncremental BackupType = "incremental"
BackupTypeSnapshot BackupType = "snapshot"
BackupTypeDataFile BackupType = "datafile"
BackupTypeLogFile BackupType = "logfile"
BackupTypeSnapshot BackupType = "snapshot"
)

// BaseBackupType the base backup type.
// +enum
// +kubebuilder:validation:Enum={full,snapshot}
type BaseBackupType string

const (
BaseBackupTypeFull BaseBackupType = "full"
BaseBackupTypeSnapshot BaseBackupType = "snapshot"
)

// CreatePVCPolicy the policy how to create the PersistentVolumeClaim for backup.
// +enum
// +kubebuilder:validation:Enum={IfNotPresent,Never}
Expand Down
53 changes: 32 additions & 21 deletions config/crd/bases/apps.kubeblocks.io_backuppolicytemplates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ spec:
maxLength: 63
pattern: ^[a-z0-9]([a-z0-9\.\-]*[a-z0-9])?$
type: string
full:
description: the policy for full backup.
datafile:
description: the policy for datafile backup.
properties:
backupStatusUpdates:
description: define how to update metadata for backup status.
Expand Down Expand Up @@ -147,8 +147,8 @@ spec:
type: string
type: object
type: object
incremental:
description: the policy for incremental backup.
logfile:
description: the policy for logfile backup.
properties:
backupStatusUpdates:
description: define how to update metadata for backup status.
Expand Down Expand Up @@ -235,11 +235,22 @@ spec:
type: string
type: object
type: object
retention:
description: retention describe how long the Backup should be
retained. if not set, will be retained forever.
properties:
ttl:
description: ttl is a time string ending with the 'd'|'D'|'h'|'H'
character to describe how long the Backup should be retained.
if not set, will be retained forever.
pattern: ^\d+[d|D|h|H]$
type: string
type: object
schedule:
description: schedule policy for backup.
properties:
baseBackup:
description: schedule policy for base backup.
datafile:
description: schedule policy for datafile backup.
properties:
cronExpression:
description: the cron expression for schedule, the timezone
Expand All @@ -248,20 +259,26 @@ spec:
enable:
description: enable or disable the schedule.
type: boolean
type:
description: the type of base backup, only support full
and snapshot.
enum:
- full
- snapshot
required:
- cronExpression
- enable
type: object
logfile:
description: schedule policy for logfile backup.
properties:
cronExpression:
description: the cron expression for schedule, the timezone
is in UTC. see https://en.wikipedia.org/wiki/Cron.
type: string
enable:
description: enable or disable the schedule.
type: boolean
required:
- cronExpression
- enable
- type
type: object
incremental:
description: schedule policy for incremental backup.
snapshot:
description: schedule policy for snapshot backup.
properties:
cronExpression:
description: the cron expression for schedule, the timezone
Expand Down Expand Up @@ -378,12 +395,6 @@ spec:
type: string
type: object
type: object
ttl:
description: ttl is a time string ending with the 'd'|'D'|'h'|'H'
character to describe how long the Backup should be retained.
if not set, will be retained forever.
pattern: ^\d+[d|D|h|H]$
type: string
required:
- componentDefRef
type: object
Expand Down
Loading

0 comments on commit 4a2cff3

Please sign in to comment.