diff --git a/apis/apps/v1/cluster_types.go b/apis/apps/v1/cluster_types.go index 2b0c260ceff..49c15b4e0ba 100644 --- a/apis/apps/v1/cluster_types.go +++ b/apis/apps/v1/cluster_types.go @@ -679,6 +679,17 @@ type ClusterBackup struct { // +kubebuilder:default=false // +optional PITREnabled *bool `json:"pitrEnabled,omitempty"` + + // Specifies whether to enable incremental backup. + // + // +kubebuilder:default=false + // +optional + IncrementalBackupEnabled *bool `json:"incrementalBackupEnabled,omitempty"` + + // The cron expression for the incremental backup schedule. The timezone is in UTC. See https://en.wikipedia.org/wiki/Cron. + // + // +optional + IncrementalCronExpression string `json:"incrementalCronExpression,omitempty"` } // ClusterPhase defines the phase of the Cluster within the .status.phase field. diff --git a/apis/apps/v1/zz_generated.deepcopy.go b/apis/apps/v1/zz_generated.deepcopy.go index 9bfdbab1022..300a52d5052 100644 --- a/apis/apps/v1/zz_generated.deepcopy.go +++ b/apis/apps/v1/zz_generated.deepcopy.go @@ -162,6 +162,11 @@ func (in *ClusterBackup) DeepCopyInto(out *ClusterBackup) { *out = new(bool) **out = **in } + if in.IncrementalBackupEnabled != nil { + in, out := &in.IncrementalBackupEnabled, &out.IncrementalBackupEnabled + *out = new(bool) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterBackup. diff --git a/apis/apps/v1alpha1/cluster_types.go b/apis/apps/v1alpha1/cluster_types.go index 47f1b9b51e8..67d538722c0 100644 --- a/apis/apps/v1alpha1/cluster_types.go +++ b/apis/apps/v1alpha1/cluster_types.go @@ -300,6 +300,17 @@ type ClusterBackup struct { // +kubebuilder:default=false // +optional PITREnabled *bool `json:"pitrEnabled,omitempty"` + + // Specifies whether to enable incremental backup. + // + // +kubebuilder:default=false + // +optional + IncrementalBackupEnabled *bool `json:"incrementalBackupEnabled,omitempty"` + + // The cron expression for the incremental backup schedule. The timezone is in UTC. See https://en.wikipedia.org/wiki/Cron. + // + // +optional + IncrementalCronExpression string `json:"incrementalCronExpression,omitempty"` } // ClusterResources is deprecated since v0.9. diff --git a/apis/apps/v1alpha1/zz_generated.deepcopy.go b/apis/apps/v1alpha1/zz_generated.deepcopy.go index f8a75fac677..0b8733683df 100644 --- a/apis/apps/v1alpha1/zz_generated.deepcopy.go +++ b/apis/apps/v1alpha1/zz_generated.deepcopy.go @@ -163,6 +163,11 @@ func (in *ClusterBackup) DeepCopyInto(out *ClusterBackup) { *out = new(bool) **out = **in } + if in.IncrementalBackupEnabled != nil { + in, out := &in.IncrementalBackupEnabled, &out.IncrementalBackupEnabled + *out = new(bool) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterBackup. diff --git a/config/crd/bases/apps.kubeblocks.io_clusters.yaml b/config/crd/bases/apps.kubeblocks.io_clusters.yaml index a0b50b41612..7ac44eebc41 100644 --- a/config/crd/bases/apps.kubeblocks.io_clusters.yaml +++ b/config/crd/bases/apps.kubeblocks.io_clusters.yaml @@ -99,6 +99,14 @@ spec: description: Specifies whether automated backup is enabled for the Cluster. type: boolean + incrementalBackupEnabled: + default: false + description: Specifies whether to enable incremental backup. + type: boolean + incrementalCronExpression: + description: The cron expression for the incremental backup schedule. + The timezone is in UTC. See https://en.wikipedia.org/wiki/Cron. + type: string method: description: Specifies the backup method to use, as defined in backupPolicy. @@ -16377,6 +16385,14 @@ spec: description: Specifies whether automated backup is enabled for the Cluster. type: boolean + incrementalBackupEnabled: + default: false + description: Specifies whether to enable incremental backup. + type: boolean + incrementalCronExpression: + description: The cron expression for the incremental backup schedule. + The timezone is in UTC. See https://en.wikipedia.org/wiki/Cron. + type: string method: description: Specifies the backup method to use, as defined in backupPolicy. diff --git a/controllers/apps/cluster/transformer_cluster_backup_policy.go b/controllers/apps/cluster/transformer_cluster_backup_policy.go index b6fc6e5ace0..630b62fd055 100644 --- a/controllers/apps/cluster/transformer_cluster_backup_policy.go +++ b/controllers/apps/cluster/transformer_cluster_backup_policy.go @@ -597,6 +597,7 @@ func (r *backupPolicyBuilder) mergeClusterBackup( // disable A and enable B. exist := false hasSyncPITRMethod := false + hasSyncIncMethod := false enableAutoBackup := boolptr.IsSetToTrue(backup.Enabled) for i, s := range backupSchedule.Spec.Schedules { if s.BackupMethod == backup.Method { @@ -630,6 +631,16 @@ func (r *backupPolicyBuilder) mergeClusterBackup( } hasSyncPITRMethod = true } + if as.Spec.BackupType == dpv1alpha1.BackupTypeIncremental && backup.IncrementalBackupEnabled != nil && + !hasSyncIncMethod && len(backup.Method) > 0 && m.CompatibleMethod == backup.Method { + // auto-sync the first compatible incremental backup for the 'incrementalBackupEnabled' option. + mergeSchedulePolicy(&dpv1alpha1.SchedulePolicy{ + Enabled: backup.IncrementalBackupEnabled, + RetentionPeriod: backup.RetentionPeriod, + CronExpression: backup.IncrementalCronExpression, + }, &backupSchedule.Spec.Schedules[i]) + hasSyncIncMethod = true + } if as.Spec.BackupType == dpv1alpha1.BackupTypeFull && enableAutoBackup { // disable the automatic backup for other full backup method backupSchedule.Spec.Schedules[i].Enabled = boolptr.False() diff --git a/deploy/helm/crds/apps.kubeblocks.io_clusters.yaml b/deploy/helm/crds/apps.kubeblocks.io_clusters.yaml index a0b50b41612..7ac44eebc41 100644 --- a/deploy/helm/crds/apps.kubeblocks.io_clusters.yaml +++ b/deploy/helm/crds/apps.kubeblocks.io_clusters.yaml @@ -99,6 +99,14 @@ spec: description: Specifies whether automated backup is enabled for the Cluster. type: boolean + incrementalBackupEnabled: + default: false + description: Specifies whether to enable incremental backup. + type: boolean + incrementalCronExpression: + description: The cron expression for the incremental backup schedule. + The timezone is in UTC. See https://en.wikipedia.org/wiki/Cron. + type: string method: description: Specifies the backup method to use, as defined in backupPolicy. @@ -16377,6 +16385,14 @@ spec: description: Specifies whether automated backup is enabled for the Cluster. type: boolean + incrementalBackupEnabled: + default: false + description: Specifies whether to enable incremental backup. + type: boolean + incrementalCronExpression: + description: The cron expression for the incremental backup schedule. + The timezone is in UTC. See https://en.wikipedia.org/wiki/Cron. + type: string method: description: Specifies the backup method to use, as defined in backupPolicy. diff --git a/docs/developer_docs/api-reference/cluster.md b/docs/developer_docs/api-reference/cluster.md index 9a533f64a12..1fb5b6f1892 100644 --- a/docs/developer_docs/api-reference/cluster.md +++ b/docs/developer_docs/api-reference/cluster.md @@ -2533,6 +2533,30 @@ bool
Specifies whether to enable point-in-time recovery.
+incrementalBackupEnabled
Specifies whether to enable incremental backup.
+incrementalCronExpression
The cron expression for the incremental backup schedule. The timezone is in UTC. See https://en.wikipedia.org/wiki/Cron.
+Specifies whether to enable point-in-time recovery.
+incrementalBackupEnabled
Specifies whether to enable incremental backup.
+incrementalCronExpression
The cron expression for the incremental backup schedule. The timezone is in UTC. See https://en.wikipedia.org/wiki/Cron.
+