Skip to content

Commit d5d4981

Browse files
drivebyercndoit18
authored andcommitted
feat: disable recurrent backup by set BackupSchedule to empty string
1 parent 58c35d1 commit d5d4981

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
88
### Added
99
* `MysqlDatabase` `MysqlUser` Add delete policy
1010
* Add `PtHeartbeatResources` in `.Spec.PodSpec` to allow the user specifying resources for pt-heartbeat.
11+
* Set `MysqlCluter.Spec.BackupSchedule` to empty string to disable recurrent backups
1112
### Changed
1213
* Set default MySQL server version to `5.7.35`
1314
### Removed

docs/cluster-recurrent-backups.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,21 @@ Crontab takes 6 arguments from the traditional 5. The additional argument is a s
4242
| 0 0 0 * * 0 | @weekly | Run once a week, midnight between Sat/Sun, 0 second |
4343
| 0 0 0 * * * | @daily (or @midnight) | Run once a day, midnight, 0 second, 0 second |
4444
| 0 0 * * * * | @hourly | Run once an hour, beginning of hour, 0 second |
45+
46+
47+
### Disable recurrent backups for MySQL cluster
48+
49+
50+
``` yaml
51+
apiVersion: mysql.presslabs.org/v1alpha1
52+
kind: MysqlCluster
53+
metadata:
54+
name: my-cluster
55+
spec:
56+
secretName: the-secret
57+
58+
backupSchedule: "" # set to empty string will disables recurrent backups
59+
backupURL: gs://bucket_name/path/
60+
backupSecretName: backup-secret
61+
backupRemoteDeletePolicy: retain|delete
62+
```

pkg/controller/mysqlbackupcron/mysqlbackupcron_controller.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,11 @@ func (r *ReconcileMysqlBackup) Reconcile(ctx context.Context, request reconcile.
134134
return reconcile.Result{}, err
135135
}
136136

137-
// if spec.backupScheduler is not set then don't do anything
137+
// if Spec.BackupSchedule is not set, here are two cases:
138+
// 1. change to empty string, call unregisterCluster, it will remove the cron job
139+
// 2. remain empty string, call unregisterCluster, it will do nothing
138140
if len(cluster.Spec.BackupSchedule) == 0 {
141+
r.unregisterCluster(request.NamespacedName)
139142
return reconcile.Result{}, nil
140143
}
141144

pkg/controller/mysqlbackupcron/mysqlbackupcron_controller_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,19 @@ var _ = Describe("MysqlBackupCron controller", func() {
155155
Expect(cron.Entries()).To(haveCronJob(cluster.Name, newSchedule))
156156
})
157157

158+
It("should remove entry after set schedule to empty", func() {
159+
// update cluster scheduler
160+
cluster.Spec.BackupSchedule = ""
161+
162+
Expect(c.Update(context.TODO(), cluster)).To(Succeed())
163+
164+
// expect an reconcile event
165+
Eventually(requests, timeout).Should(Receive(Equal(expectedRequest)))
166+
167+
// check cron entry for right scheduler
168+
Expect(cron.Entries()).ToNot(haveCronJob(cluster.Name, schedule))
169+
})
170+
158171
It("should be just one entry for a cluster", func() {
159172
// update cluster spec
160173
cluster.Spec.MysqlConf = map[string]intstr.IntOrString{

0 commit comments

Comments
 (0)