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
36 serviceAccountName: {{ include "common.fullname" (dict "suffix" "read" "dot" . )}}
37 {{ include "common.podSecurityContext" . | indent 10 | trim}}
39 initContainers: {{- include "common.readinessCheck.waitFor" . | nindent 12 }}
40 - name: mariadb-galera-backup-init
41 image: {{ include "repositoryGenerator.image.mariadb" . }}
42 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
44 allowPrivilegeEscalation: false
46 readOnlyRootFilesystem: false
54 echo "Failed" > /backup/backup.log
55 echo "Backup failed!!!"
58 target_dir=/backup/backup-`date +%s`
61 mysqlhost={{ include "common.fullname" . }}-0.{{ include "common.servicename" . }}-headless.{{ include "common.namespace" . }}
63 mariabackup --backup --target-dir=$target_dir --user=root --password=$DB_PASS --host=$mysqlhost
66 if [ $ret_code -ne 0 ]; then
67 remove_dir $target_dir
71 echo "Starting Backup Preparation!!!"
72 mariabackup --prepare --target-dir=$target_dir
74 if [ $ret_code -ne 0 ]; then
75 remove_dir $target_dir
78 echo "Success" > /backup/backup.log
79 echo "Backup Successful!!!"
82 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" (include "common.mariadb.secret.rootPassUID" .) "key" "password") | indent 18 }}
83 resources: {{ include "common.resources" . | nindent 16 }}
88 mountPath: /bitnami/mariadb
90 - name: mariadb-backup-validate
91 image: {{ include "repositoryGenerator.image.mariadb" . }}
92 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
94 allowPrivilegeEscalation: false
96 readOnlyRootFilesystem: false
98 - name: MARIADB_ROOT_PASSWORD
99 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" (include "common.mariadb.secret.rootPassUID" .) "key" "password") | indent 18 }}
107 echo "Validation Failed!!!";
110 backup_result=`cat /backup/backup.log`
111 rm -rf /backup/backup.log
113 if [ "$backup_result" == "Failed" ]; then
114 echo "Backup Failed!!! Validation Failed!!!";
118 target_dir=$(ls -td -- /backup/backup-* | head -n 1)
119 cp -Ra $target_dir/* /bitnami/mariadb/data
121 if [ ! "$(ls -A /bitnami/mariadb/data)" ]; then
122 remove_dir $target_dir
126 /opt/bitnami/scripts/mariadb/entrypoint.sh /opt/bitnami/scripts/mariadb/run.sh &
129 until mysql --user=root --password=$MARIADB_ROOT_PASSWORD -e "SELECT 1";
131 count=`expr $count + 1`;
132 if [ $count -ge 30 ]; then
133 remove_dir $target_dir
138 mysqlcheck -A --user=root --password=$MARIADB_ROOT_PASSWORD > /tmp/output.log
139 error_lines=`cat /tmp/output.log| grep -v "OK" | wc -l`
143 if [ $error_lines -gt 1 ];then
144 remove_dir $target_dir
146 echo "Validation successful!!!"
148 totalFiles=`ls -t | grep "backup-" | wc -l`
149 if [ $totalFiles -gt {{ .Values.backup.retentionPeriod }} ]; then
150 filestoDelete=`expr $totalFiles - {{ .Values.backup.retentionPeriod }}`
151 ls -tr | grep backup | head -$filestoDelete | xargs rm -rf
154 resources: {{ include "common.resources" . | nindent 16 }}
156 - mountPath: /bitnami/mariadb/data
158 - mountPath: /opt/bitnami/mariadb/tmp
160 - mountPath: /etc/localtime
166 - name: {{ include "common.namespace" . }}-docker-registry-key
172 persistentVolumeClaim:
173 {{- if .Values.persistence.existingClaim }}
174 claimName: {{ .Values.persistence.existingClaim }}
176 claimName: {{ include "common.fullname" . }}-{{ include "common.fullname" . }}-0
179 persistentVolumeClaim:
180 claimName: {{ include "common.fullname" . }}-backup-data