Skip to content

Commit f19a56f

Browse files
mysql backup struct for schedule information
1 parent 334e546 commit f19a56f

1 file changed

Lines changed: 57 additions & 2 deletions

File tree

controllers/config_template.go

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ import (
77
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
88
)
99

10+
type BackupSchedule struct {
11+
BackupSchedule string
12+
MysqlName string
13+
UserName string
14+
Password string
15+
}
16+
1017
func NewMySQLStatefulSet(name string, namespace string, SecretName string) *appsv1.StatefulSet {
1118
statefulSet := &appsv1.StatefulSet{
1219
ObjectMeta: metav1.ObjectMeta{
@@ -66,6 +73,54 @@ func NewMySQLSecret(name string, namespace string, rootPwd string, clusteradminP
6673
return secret
6774
}
6875

69-
func NewMySQLBackupCronJob(name string, namespace string, username string, password string) *beta1.CronJob {
70-
return nil
76+
func NewMySQLBackupCronJob(backupObject BackupSchedule, namespace string) *beta1.CronJob {
77+
78+
cronJob := &beta1.CronJob{
79+
ObjectMeta: metav1.ObjectMeta{
80+
Name: backupObject.MysqlName,
81+
Namespace: namespace,
82+
Labels: map[string]string{
83+
"app": backupObject.MysqlName,
84+
},
85+
},
86+
Spec: beta1.CronJobSpec{
87+
Schedule: backupObject.BackupSchedule,
88+
JobTemplate: beta1.JobTemplateSpec{
89+
Spec: beta1.JobSpec{
90+
Template: corev1.PodTemplateSpec{
91+
Spec: corev1.PodSpec{
92+
Containers: []corev1.Container{
93+
{
94+
Name: "backup-container",
95+
Image: "mysql:latest",
96+
ImagePullPolicy: corev1.PullAlways,
97+
Command: []string{
98+
"/bin/bash",
99+
"-c",
100+
"mysqldump -h mysql-prd-0.mysql-prd -u <mysql-username> -p<mysql-password> <database-name> > /backup/db_backup.sql",
101+
},
102+
VolumeMounts: []corev1.VolumeMount{
103+
{
104+
Name: "backup-volume",
105+
MountPath: "/backup",
106+
},
107+
},
108+
},
109+
},
110+
Volumes: []corev1.Volume{
111+
{
112+
Name: "backup-volume",
113+
VolumeSource: corev1.VolumeSource{
114+
EmptyDir: &corev1.EmptyDirVolumeSource{},
115+
},
116+
},
117+
},
118+
},
119+
},
120+
},
121+
},
122+
},
123+
}
124+
125+
return cronJob
71126
}

0 commit comments

Comments
 (0)