Skip to content

Commit 9a3a04d

Browse files
committed
chore(mysql-cluster): add backup
1 parent 16ced04 commit 9a3a04d

4 files changed

Lines changed: 113 additions & 2 deletions

File tree

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{{- /*
2+
Copyright Drycc Community.
3+
SPDX-License-Identifier: APACHE-2.0
4+
*/}}
5+
{{- if .Values.backup.enabled }}
6+
apiVersion: {{ include "common.capabilities.cronjob.apiVersion" . }}
7+
kind: CronJob
8+
metadata:
9+
name: {{ include "mysql.cluster.fullname" . }}-backup
10+
namespace: {{ include "common.names.namespace" . | quote }}
11+
labels: {{- include "common.labels.standard" . | nindent 4 }}
12+
app.kubernetes.io/component: primary
13+
{{- if .Values.commonLabels }}
14+
{{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
15+
{{- end }}
16+
{{- if .Values.commonAnnotations }}
17+
annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
18+
{{- end }}
19+
20+
spec:
21+
schedule: {{ .Values.backup.schedule| quote }}
22+
concurrencyPolicy: Forbid
23+
failedJobsHistoryLimit: 1
24+
jobTemplate:
25+
metadata:
26+
spec:
27+
template:
28+
spec:
29+
restartPolicy: OnFailure
30+
initContainers:
31+
- name: backup-wait
32+
image: registry.drycc.cc/drycc/python-dev:latest
33+
imagePullPolicy: {{.Values.imagePullPolicy}}
34+
args:
35+
- netcat
36+
- -v
37+
- -u
38+
- mysql://$(MYSQL_HOST):$(MYSQL_PORT_NUMBER)
39+
40+
env:
41+
- name: MYSQL_HOST
42+
value: {{ include "mysql.router.fullname" . }}
43+
- name: MYSQL_PORT_NUMBER
44+
value: {{ .Values.router.service.portro | quote }}
45+
46+
containers:
47+
- name: backup-cron
48+
image: {{ include "cluster.image" . }}
49+
imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
50+
{{- if .Values.primary.containerSecurityContext.enabled }}
51+
securityContext: {{- omit .Values.primary.containerSecurityContext "enabled" | toYaml | nindent 14 }}
52+
{{- end }}
53+
command:
54+
- /bin/bash
55+
- -ec
56+
- |
57+
# create file
58+
echo "
59+
import os
60+
from datetime import datetime, timezone, timedelta
61+
62+
now_utc = datetime.now(timezone.utc)
63+
cst_timezone = timezone(timedelta(hours=8))
64+
now_cst = now_utc.astimezone(cst_timezone)
65+
now_str = now_cst.strftime('%Y%m%d%H%M')
66+
endpoint=os.getenv('AWS_ENDPOINT_URL')
67+
bucket_name=os.getenv('AWS_BUCKET_NAME')
68+
69+
util.dump_instance(now_str, {'s3BucketName': bucket_name, 's3EndpointOverride': endpoint, 'threads': 4, 'compatibility': ['strip_restricted_grants', 'strip_definers', 'ignore_missing_pks'] ,'excludeSchemas': ['mysql_innodb_cluster_metadata','sys','information_schema','performance_schema','mondb'],'compatibility':['strip_restricted_grants', 'strip_definers', 'ignore_missing_pks'] })
70+
" > /tmp/dump_instance.py
71+
72+
mysqlsh --uri=${MYSQL_ROOT_USER}@${MYSQL_HOST}:${MYSQL_PORT_NUMBER} -p${MYSQL_ROOT_PASSWORD} --py < /tmp/dump_instance.py
73+
74+
env:
75+
- name: MYSQL_HOST
76+
value: {{ include "mysql.router.fullname" . }}
77+
- name: MYSQL_PORT_NUMBER
78+
value: {{ .Values.router.service.portro | quote }}
79+
- name: MYSQL_ROOT_USER
80+
value: "root"
81+
- name: MYSQL_ROOT_PASSWORD
82+
valueFrom:
83+
secretKeyRef:
84+
name: {{ template "mysql.secretName" . }}
85+
key: mysql-root-password
86+
- name: AWS_ENDPOINT_URL
87+
value: {{ .Values.backup.s3.endpoint | quote }}
88+
- name: AWS_BUCKET_NAME
89+
value: {{ .Values.backup.s3.bucketName | quote }}
90+
- name: AWS_ACCESS_KEY_ID
91+
value: {{ .Values.backup.s3.accessKey | quote }}
92+
- name: AWS_SECRET_ACCESS_KEY
93+
value: {{ .Values.backup.s3.secretKey | quote }}
94+
- name: AWS_DEFAULT_REGION
95+
value: {{ .Values.backup.s3.region | quote }}
96+
{{- end }}

addons/mysql-cluster/8.0/chart/mysql-cluster/templates/networkpolicy.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ spec:
2828
- port: {{ .Values.router.service.portro }}
2929
- port: 24901
3030
- port: 33061
31+
- port: 6446
32+
- port: 6447
3133
{{- if and .Values.metrics.enabled }}
3234
- port: {{ .Values.metrics.service.port }}
3335
{{- end }}

addons/mysql-cluster/8.0/chart/mysql-cluster/values.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,8 @@ cluster:
592592

593593
image:
594594
registry: registry.drycc.cc
595-
repository: drycc-addons/mysqlshell
596-
tag: 8.0.34
595+
repository: drycc-addons/mysql-shell
596+
tag: "8.0"
597597
digest: ""
598598
pullPolicy: IfNotPresent
599599

@@ -1245,3 +1245,13 @@ metrics:
12451245
## summary: MariaDB instance is down
12461246
##
12471247
rules: []
1248+
1249+
backup:
1250+
enabled: false
1251+
schedule: ""
1252+
s3:
1253+
endpoint: ""
1254+
bucketName: ""
1255+
accessKey: ""
1256+
secretKey: ""
1257+
region: us-west-1

addons/mysql-cluster/8.0/meta.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ allow_parameters:
2424
- name: "router.configuration"
2525
required: false
2626
description: "router config for values.yaml"
27+
- name: "backup"
28+
required: false
29+
description: "backup config for values.yaml"
2730
archive: false

0 commit comments

Comments
 (0)