Skip to content

Commit

Permalink
fix: supports incremental backup config in cluster CR (#8788)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnolong authored Jan 10, 2025
1 parent 4760c20 commit d9173ee
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 0 deletions.
11 changes: 11 additions & 0 deletions apis/apps/v1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions apis/apps/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions apis/apps/v1alpha1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions apis/apps/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions config/crd/bases/apps.kubeblocks.io_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions controllers/apps/cluster/transformer_cluster_backup_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down
16 changes: 16 additions & 0 deletions deploy/helm/crds/apps.kubeblocks.io_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
48 changes: 48 additions & 0 deletions docs/developer_docs/api-reference/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -2533,6 +2533,30 @@ bool
<p>Specifies whether to enable point-in-time recovery.</p>
</td>
</tr>
<tr>
<td>
<code>incrementalBackupEnabled</code><br/>
<em>
bool
</em>
</td>
<td>
<em>(Optional)</em>
<p>Specifies whether to enable incremental backup.</p>
</td>
</tr>
<tr>
<td>
<code>incrementalCronExpression</code><br/>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>The cron expression for the incremental backup schedule. The timezone is in UTC. See <a href="https://en.wikipedia.org/wiki/Cron">https://en.wikipedia.org/wiki/Cron</a>.</p>
</td>
</tr>
</tbody>
</table>
<h3 id="apps.kubeblocks.io/v1.ClusterComponentConfig">ClusterComponentConfig
Expand Down Expand Up @@ -14954,6 +14978,30 @@ bool
<p>Specifies whether to enable point-in-time recovery.</p>
</td>
</tr>
<tr>
<td>
<code>incrementalBackupEnabled</code><br/>
<em>
bool
</em>
</td>
<td>
<em>(Optional)</em>
<p>Specifies whether to enable incremental backup.</p>
</td>
</tr>
<tr>
<td>
<code>incrementalCronExpression</code><br/>
<em>
string
</em>
</td>
<td>
<em>(Optional)</em>
<p>The cron expression for the incremental backup schedule. The timezone is in UTC. See <a href="https://en.wikipedia.org/wiki/Cron">https://en.wikipedia.org/wiki/Cron</a>.</p>
</td>
</tr>
</tbody>
</table>
<h3 id="apps.kubeblocks.io/v1alpha1.ClusterComponentConfig">ClusterComponentConfig
Expand Down

0 comments on commit d9173ee

Please sign in to comment.