From 3d364be6628eb4e0adc7873e97bc9eb874e971e5 Mon Sep 17 00:00:00 2001 From: wanglong <46259301+gnolong@users.noreply.github.com> Date: Mon, 2 Dec 2024 10:45:03 +0800 Subject: [PATCH] fix: add Selective backupType (#8553) --- apis/dataprotection/v1alpha1/actionset_types.go | 6 ++++-- .../crd/bases/dataprotection.kubeblocks.io_actionsets.yaml | 3 +++ .../helm/crds/dataprotection.kubeblocks.io_actionsets.yaml | 3 +++ docs/developer_docs/api-reference/backup.md | 4 ++++ pkg/dataprotection/backup/request.go | 2 +- pkg/dataprotection/restore/utils.go | 2 +- pkg/testutil/dataprotection/utils.go | 1 + 7 files changed, 17 insertions(+), 4 deletions(-) diff --git a/apis/dataprotection/v1alpha1/actionset_types.go b/apis/dataprotection/v1alpha1/actionset_types.go index 42cd81a6bf5..f10c032d0b8 100644 --- a/apis/dataprotection/v1alpha1/actionset_types.go +++ b/apis/dataprotection/v1alpha1/actionset_types.go @@ -29,10 +29,11 @@ type ActionSetSpec struct { // - `Incremental` back up data that have changed since the last backup (either full or incremental). // - `Differential` back up data that has changed since the last full backup. // - `Continuous` back up transaction logs continuously, such as MySQL binlog, PostgreSQL WAL, etc. + // - `Selective` back up data more precisely, use custom parameters, such as specific databases or tables. // // Continuous backup is essential for implementing Point-in-Time Recovery (PITR). // - // +kubebuilder:validation:Enum={Full,Incremental,Differential,Continuous} + // +kubebuilder:validation:Enum={Full,Incremental,Differential,Continuous,Selective} // +kubebuilder:default=Full // +kubebuilder:validation:Required BackupType BackupType `json:"backupType"` @@ -91,7 +92,7 @@ type ActionSetStatus struct { // BackupType the backup type. // +enum -// +kubebuilder:validation:Enum={Full,Incremental,Differential,Continuous} +// +kubebuilder:validation:Enum={Full,Incremental,Differential,Continuous,Selective} type BackupType string const ( @@ -99,6 +100,7 @@ const ( BackupTypeIncremental BackupType = "Incremental" BackupTypeDifferential BackupType = "Differential" BackupTypeContinuous BackupType = "Continuous" + BackupTypeSelective BackupType = "Selective" ) type BackupActionSpec struct { diff --git a/config/crd/bases/dataprotection.kubeblocks.io_actionsets.yaml b/config/crd/bases/dataprotection.kubeblocks.io_actionsets.yaml index 71b5f38182c..70f0c913412 100644 --- a/config/crd/bases/dataprotection.kubeblocks.io_actionsets.yaml +++ b/config/crd/bases/dataprotection.kubeblocks.io_actionsets.yaml @@ -282,11 +282,13 @@ spec: - Incremental - Differential - Continuous + - Selective - enum: - Full - Incremental - Differential - Continuous + - Selective default: Full description: |- Specifies the backup type. Supported values include: @@ -296,6 +298,7 @@ spec: - `Incremental` back up data that have changed since the last backup (either full or incremental). - `Differential` back up data that has changed since the last full backup. - `Continuous` back up transaction logs continuously, such as MySQL binlog, PostgreSQL WAL, etc. + - `Selective` back up data more precisely, use custom parameters, such as specific databases or tables. Continuous backup is essential for implementing Point-in-Time Recovery (PITR). diff --git a/deploy/helm/crds/dataprotection.kubeblocks.io_actionsets.yaml b/deploy/helm/crds/dataprotection.kubeblocks.io_actionsets.yaml index 71b5f38182c..70f0c913412 100644 --- a/deploy/helm/crds/dataprotection.kubeblocks.io_actionsets.yaml +++ b/deploy/helm/crds/dataprotection.kubeblocks.io_actionsets.yaml @@ -282,11 +282,13 @@ spec: - Incremental - Differential - Continuous + - Selective - enum: - Full - Incremental - Differential - Continuous + - Selective default: Full description: |- Specifies the backup type. Supported values include: @@ -296,6 +298,7 @@ spec: - `Incremental` back up data that have changed since the last backup (either full or incremental). - `Differential` back up data that has changed since the last full backup. - `Continuous` back up transaction logs continuously, such as MySQL binlog, PostgreSQL WAL, etc. + - `Selective` back up data more precisely, use custom parameters, such as specific databases or tables. Continuous backup is essential for implementing Point-in-Time Recovery (PITR). diff --git a/docs/developer_docs/api-reference/backup.md b/docs/developer_docs/api-reference/backup.md index e4a3d1c1773..ec66150f503 100644 --- a/docs/developer_docs/api-reference/backup.md +++ b/docs/developer_docs/api-reference/backup.md @@ -102,6 +102,7 @@ BackupType
  • Incremental back up data that have changed since the last backup (either full or incremental).
  • Differential back up data that has changed since the last full backup.
  • Continuous back up transaction logs continuously, such as MySQL binlog, PostgreSQL WAL, etc.
  • +
  • Selective back up data more precisely, use custom parameters, such as specific databases or tables.
  • Continuous backup is essential for implementing Point-in-Time Recovery (PITR).

    @@ -1348,6 +1349,7 @@ BackupType
  • Incremental back up data that have changed since the last backup (either full or incremental).
  • Differential back up data that has changed since the last full backup.
  • Continuous back up transaction logs continuously, such as MySQL binlog, PostgreSQL WAL, etc.
  • +
  • Selective back up data more precisely, use custom parameters, such as specific databases or tables.
  • Continuous backup is essential for implementing Point-in-Time Recovery (PITR).

    @@ -3773,6 +3775,8 @@ Kubernetes meta/v1.Time

    "Incremental"

    +

    "Selective"

    +

    BaseJobActionSpec diff --git a/pkg/dataprotection/backup/request.go b/pkg/dataprotection/backup/request.go index 93b72b4cfcd..1d7c46b78fc 100644 --- a/pkg/dataprotection/backup/request.go +++ b/pkg/dataprotection/backup/request.go @@ -170,7 +170,7 @@ func (r *Request) buildBackupDataAction(targetPod *corev1.Pod, name string) (act backupDataAct := r.ActionSet.Spec.Backup.BackupData switch r.ActionSet.Spec.BackupType { - case dpv1alpha1.BackupTypeFull: + case dpv1alpha1.BackupTypeFull, dpv1alpha1.BackupTypeSelective: podSpec, err := r.BuildJobActionPodSpec(targetPod, BackupDataContainerName, &backupDataAct.JobActionSpec) if err != nil { return nil, fmt.Errorf("failed to build job action pod spec: %w", err) diff --git a/pkg/dataprotection/restore/utils.go b/pkg/dataprotection/restore/utils.go index 0e9281f023e..92835d5132a 100644 --- a/pkg/dataprotection/restore/utils.go +++ b/pkg/dataprotection/restore/utils.go @@ -275,7 +275,7 @@ func ValidateAndInitRestoreMGR(reqCtx intctrlutil.RequestCtx, // build backupActionSets of prepareData and postReady stage based on the specified backup's type. switch backupType { - case dpv1alpha1.BackupTypeFull: + case dpv1alpha1.BackupTypeFull, dpv1alpha1.BackupTypeSelective: restoreMgr.SetBackupSets(*backupSet) case dpv1alpha1.BackupTypeIncremental: err = restoreMgr.BuildIncrementalBackupActionSets(reqCtx, cli, *backupSet) diff --git a/pkg/testutil/dataprotection/utils.go b/pkg/testutil/dataprotection/utils.go index 386aefeccb6..3199605eae7 100644 --- a/pkg/testutil/dataprotection/utils.go +++ b/pkg/testutil/dataprotection/utils.go @@ -171,6 +171,7 @@ func MockActionSetWithSchema(testCtx *testutil.TestContext, actionSet *dpv1alpha } as.Spec.Backup.WithParameters = []string{ParameterString, ParameterArray} as.Spec.Restore.WithParameters = []string{ParameterString, ParameterArray} + as.Spec.BackupType = dpv1alpha1.BackupTypeSelective })).Should(Succeed()) By("the actionSet should be available") Eventually(testapps.CheckObj(testCtx, client.ObjectKeyFromObject(actionSet),