2 # Copyright © 2019 Amdocs, Bell Canada
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 {{- if .Values.backup.enabled }}
17 apiVersion: batch/v1beta1
20 name: {{ include "common.fullname" . }}-backup
21 namespace: {{ include "common.namespace" . }}
23 app: {{ include "common.fullname" . }}
24 chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
25 release: {{ .Release.Name }}
26 heritage: {{ .Release.Service }}
28 schedule: {{ .Values.backup.cron | quote }}
29 concurrencyPolicy: Forbid
30 startingDeadlineSeconds: 120
41 - {{ include "common.name" . }}
47 fieldPath: metadata.namespace
48 image: "{{ .Values.global.readinessRepository }}/{{ .Values.global.readinessImage }}"
49 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
50 name: {{ include "common.name" . }}-readiness
51 - name: mariadb-galera-backup-init
52 image: "{{ include "common.repository" . }}/{{ .Values.backupImage }}"
53 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
61 echo "Failed" > /backup/backup.log
62 echo "Backup failed!!!"
65 target_dir=/backup/backup-`date +%s`
68 mysqlhost={{ include "common.fullname" . }}-{{ sub .Values.replicaCount 1 }}.{{ .Values.service.name }}
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!!!"
91 name: {{ include "common.fullname" . }}
97 mountPath: /var/lib/mysql
99 - name: mariadb-backup-validate
100 image: "{{ include "common.repository" . }}/{{ .Values.backupImage }}"
101 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
103 - name: MYSQL_ROOT_PASSWORD
106 name: {{ include "common.fullname" . }}
107 key: db-root-password
115 echo "Validation Failed!!!";
118 backup_result=`cat /backup/backup.log`
119 rm -rf /backup/backup.log
121 if [ "$backup_result" == "Failed" ]; then
122 echo "Backup Failed!!! So Validation Failed!!!";
126 target_dir=$(ls -td -- /backup/backup-* | head -n 1)
127 cp -Ra $target_dir/* /var/lib/mysql/
129 if [ ! "$(ls -A /var/lib/mysql)" ]; then
130 remove_dir $target_dir
134 /docker-entrypoint.sh mysqld &
137 until mysql --user=root --password=$MYSQL_ROOT_PASSWORD -e "SELECT 1";
139 count=`expr $count + 1`;
140 if [ $count -ge 30 ]; then
141 remove_dir $target_dir
146 mysqlcheck -A --user=root --password=$MYSQL_ROOT_PASSWORD > /tmp/output.log
147 error_lines=`cat /tmp/output.log| grep -v "OK" | wc -l`
151 if [ $error_lines -gt 1 ];then
152 remove_dir $target_dir
154 echo "Validation successful!!!"
156 totalFiles=`ls -t | grep "backup-" | wc -l`
157 if [ $totalFiles -gt {{ .Values.backup.retentionPeriod }} ]; then
158 filestoDelete=`expr $totalFiles - {{ .Values.backup.retentionPeriod }}`
159 ls -tr | grep backup | head -$filestoDelete | xargs rm -rf
163 - mountPath: /etc/localtime
173 persistentVolumeClaim:
174 claimName: {{ include "common.fullname" . }}-db-data
176 persistentVolumeClaim:
177 claimName: {{ include "common.fullname" . }}-backup