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.persistence.enabled }}
19 apiVersion: batch/v1beta1
22 name: {{ include "common.fullname" . }}-backup
23 namespace: {{ include "common.namespace" . }}
24 labels: {{- include "common.labels" . | nindent 4 }}
26 schedule: {{ .Values.backup.cron | quote }}
27 concurrencyPolicy: Forbid
28 startingDeadlineSeconds: 120
33 serviceAccountName: {{ include "common.fullname" (dict "suffix" "read" "dot" . )}}
34 {{ include "common.podSecurityContext" . | indent 10 | trim}}
36 initContainers: {{- include "common.readinessCheck.waitFor" . | nindent 12 }}
37 - name: mariadb-galera-backup-init
38 image: {{ include "repositoryGenerator.image.mariadb" . }}
39 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
41 allowPrivilegeEscalation: false
43 readOnlyRootFilesystem: false
51 echo "Failed" > /backup/backup.log
52 echo "Backup failed!!!"
55 target_dir=/backup/backup-`date +%s`
58 mysqlhost={{ include "common.fullname" . }}-0.{{ include "common.servicename" . }}-headless.{{ include "common.namespace" . }}
60 mariabackup --backup --target-dir=$target_dir --user=root --password=$DB_PASS --host=$mysqlhost
63 if [ $ret_code -ne 0 ]; then
64 remove_dir $target_dir
68 echo "Starting Backup Preparation!!!"
69 mariabackup --prepare --target-dir=$target_dir
71 if [ $ret_code -ne 0 ]; then
72 remove_dir $target_dir
75 echo "Success" > /backup/backup.log
76 echo "Backup Successful!!!"
79 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" (include "common.mariadb.secret.rootPassUID" .) "key" "password") | indent 18 }}
80 resources: {{ include "common.resources" . | nindent 12 }}
85 mountPath: /bitnami/mariadb
87 - name: mariadb-backup-validate
88 image: {{ include "repositoryGenerator.image.mariadb" . }}
89 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
91 allowPrivilegeEscalation: false
93 readOnlyRootFilesystem: false
95 - name: MARIADB_ROOT_PASSWORD
96 {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" (include "common.mariadb.secret.rootPassUID" .) "key" "password") | indent 18 }}
104 echo "Validation Failed!!!";
107 backup_result=`cat /backup/backup.log`
108 rm -rf /backup/backup.log
110 if [ "$backup_result" == "Failed" ]; then
111 echo "Backup Failed!!! Validation Failed!!!";
115 target_dir=$(ls -td -- /backup/backup-* | head -n 1)
116 cp -Ra $target_dir/* /bitnami/mariadb/data
118 if [ ! "$(ls -A /bitnami/mariadb/data)" ]; then
119 remove_dir $target_dir
123 /opt/bitnami/scripts/mariadb/entrypoint.sh /opt/bitnami/scripts/mariadb/run.sh &
126 until mysql --user=root --password=$MARIADB_ROOT_PASSWORD -e "SELECT 1";
128 count=`expr $count + 1`;
129 if [ $count -ge 30 ]; then
130 remove_dir $target_dir
135 mysqlcheck -A --user=root --password=$MARIADB_ROOT_PASSWORD > /tmp/output.log
136 error_lines=`cat /tmp/output.log| grep -v "OK" | wc -l`
140 if [ $error_lines -gt 1 ];then
141 remove_dir $target_dir
143 echo "Validation successful!!!"
145 totalFiles=`ls -t | grep "backup-" | wc -l`
146 if [ $totalFiles -gt {{ .Values.backup.retentionPeriod }} ]; then
147 filestoDelete=`expr $totalFiles - {{ .Values.backup.retentionPeriod }}`
148 ls -tr | grep backup | head -$filestoDelete | xargs rm -rf
151 resources: {{ include "common.resources" . | nindent 12 }}
153 - mountPath: /bitnami/mariadb/data
155 - mountPath: /opt/bitnami/mariadb/tmp
157 - mountPath: /etc/localtime
163 - name: {{ include "common.namespace" . }}-docker-registry-key
169 persistentVolumeClaim:
170 {{- if .Values.persistence.existingClaim }}
171 claimName: {{ .Values.persistence.existingClaim }}
173 claimName: {{ include "common.fullname" . }}-{{ include "common.fullname" . }}-0
176 persistentVolumeClaim:
177 claimName: {{ include "common.fullname" . }}-backup-data