2 # Copyright © 2019 Amdocs, Bell Canada, Samsung Electronics
3 # Copyright © 2020 Orange
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 {{- if and .Values.backup.enabled .Values.global.mariadbGalera.useOperator }}
19 {{ include "common.mariadbOpBackup" . }}
21 {{- if and .Values.backup.enabled .Values.persistence.enabled }}
22 apiVersion: batch/v1beta1
25 name: {{ include "common.fullname" . }}-backup
26 namespace: {{ include "common.namespace" . }}
27 labels: {{- include "common.labels" . | nindent 4 }}
29 schedule: {{ .Values.backup.cron | quote }}
30 concurrencyPolicy: Forbid
31 startingDeadlineSeconds: 120
37 # Workarround to exclude K8S API from istio communication
38 # as init-container (readinessCheck) does not work with the
39 # Istio CNI plugin, see:
40 # (https://istio.io/latest/docs/setup/additional-setup/cni/#compatibility-with-application-init-containers)
41 traffic.sidecar.istio.io/excludeOutboundPorts: "443"
43 serviceAccountName: {{ include "common.fullname" (dict "suffix" "read" "dot" . )}}
44 {{ include "common.podSecurityContext" . | indent 10 | trim}}
46 initContainers: {{- include "common.readinessCheck.waitFor" . | nindent 12 }}
47 - name: mariadb-galera-backup-init
48 image: {{ include "repositoryGenerator.image.mariadb" . }}
49 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
51 allowPrivilegeEscalation: false
53 readOnlyRootFilesystem: false
61 echo "Failed" > /backup/backup.log
62 echo "Backup failed!!!"
65 target_dir=/backup/backup-`date +%s`
68 mysqlhost={{ include "common.fullname" . }}-0.{{ include "common.servicename" . }}-headless.{{ include "common.namespace" . }}
70 mariabackup --backup --target-dir=$target_dir --user=root --password=$DB_PASS --host=$mysqlhost
73 if [ $ret_code -ne 0 ]; then
74 remove_dir $target_dir
78 echo "Starting Backup Preparation!!!"
79 mariabackup --prepare --target-dir=$target_dir
81 if [ $ret_code -ne 0 ]; then
82 remove_dir $target_dir
85 echo "Success" > /backup/backup.log
86 echo "Backup Successful!!!"
89 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" (include "common.mariadb.secret.rootPassUID" .) "key" "password") | indent 18 }}
90 resources: {{ include "common.resources" . | nindent 16 }}
95 mountPath: /bitnami/mariadb
97 - name: mariadb-backup-validate
98 image: {{ include "repositoryGenerator.image.mariadb" . }}
99 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
101 allowPrivilegeEscalation: false
103 readOnlyRootFilesystem: false
105 - name: MARIADB_ROOT_PASSWORD
106 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" (include "common.mariadb.secret.rootPassUID" .) "key" "password") | indent 18 }}
114 echo "Validation Failed!!!";
117 backup_result=`cat /backup/backup.log`
118 rm -rf /backup/backup.log
120 if [ "$backup_result" == "Failed" ]; then
121 echo "Backup Failed!!! Validation Failed!!!";
125 target_dir=$(ls -td -- /backup/backup-* | head -n 1)
126 cp -Ra $target_dir/* /bitnami/mariadb/data
128 if [ ! "$(ls -A /bitnami/mariadb/data)" ]; then
129 remove_dir $target_dir
133 /opt/bitnami/scripts/mariadb/entrypoint.sh /opt/bitnami/scripts/mariadb/run.sh &
136 until mysql --user=root --password=$MARIADB_ROOT_PASSWORD -e "SELECT 1";
138 count=`expr $count + 1`;
139 if [ $count -ge 30 ]; then
140 remove_dir $target_dir
145 mysqlcheck -A --user=root --password=$MARIADB_ROOT_PASSWORD > /tmp/output.log
146 error_lines=`cat /tmp/output.log| grep -v "OK" | wc -l`
150 if [ $error_lines -gt 1 ];then
151 remove_dir $target_dir
153 echo "Validation successful!!!"
155 totalFiles=`ls -t | grep "backup-" | wc -l`
156 if [ $totalFiles -gt {{ .Values.backup.retentionPeriod }} ]; then
157 filestoDelete=`expr $totalFiles - {{ .Values.backup.retentionPeriod }}`
158 ls -tr | grep backup | head -$filestoDelete | xargs rm -rf
161 resources: {{ include "common.resources" . | nindent 16 }}
163 - mountPath: /bitnami/mariadb/data
165 - mountPath: /opt/bitnami/mariadb/tmp
167 - mountPath: /etc/localtime
172 {{- include "common.imagePullSecrets" . | nindent 10 }}
178 persistentVolumeClaim:
179 {{- if .Values.persistence.existingClaim }}
180 claimName: {{ .Values.persistence.existingClaim }}
182 claimName: {{ include "common.fullname" . }}-{{ include "common.fullname" . }}-0
185 persistentVolumeClaim:
186 claimName: {{ include "common.fullname" . }}-backup-data