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: "cassandra-backup-init"
52 image: "{{ .Values.global.readinessRepository }}/{{ .Values.global.readinessImage }}"
53 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
60 echo "Clearing snapshots!!!"
61 command="nodetool clearsnapshot -t $curr_time"
62 /root/exec.py -p "cassandra" -c "$command"
70 {{ range $i, $e := until (int .Values.replicaCount) }}
71 target_dir=/backup/temp/cassandra-{{ $i }}
73 cp -Ra /onap-data/cassandra-{{ $i }}/data/ $target_dir/
76 echo "Executing cleanup!!"
77 command="nodetool cleanup"
78 /root/exec.py -p "cassandra" -c "$command"
79 echo "Cleaned Node!! Backing up database now!!!"
81 command="nodetool snapshot -t $curr_time"
82 /root/exec.py -p "cassandra" -c "$command"
84 if [ $retCode -ne 0 ]; then
85 echo "Backup Failed!!!"
87 clearSnapshot $curr_time
88 echo "Failed" > /backup/backup.log
92 backup_dir=/backup/temp
93 {{ range $i, $e := until (int .Values.replicaCount) }}
94 for d in $backup_dir/cassandra-{{ $i }}/data/*/ ; do
95 d=$(echo $d | sed 's:/*$::')
96 keyspace_name=$(echo "$d" | awk -F/ '{ print $NF }')
97 if [ 1 ] {{- range $t, $keyspace := $root.Values.backup.keyspacesToSkip }} && [ "{{ $keyspace.name }}" != "$keyspace_name" ] {{- end }}; then
98 /root/restore.sh -b $backup_dir/cassandra-{{ $i }}/data -s /onap-data/cassandra-{{ $i }}/data/$keyspace_name -k $keyspace_name -t $curr_time &
106 if [ $? -ne 0 ]; then
108 echo "Creation of Backup Failed!!!"
109 clearSnapshot $curr_time
110 echo "Failed" > /backup/backup.log
115 clearSnapshot $curr_time
118 if [ $exit_code -ne 0 ]; then
120 echo "Backup Failed!!!"
121 echo "Failed" > /backup/backup.log
125 mv /backup/temp /backup/backup-${curr_time}
126 echo "Success" > /backup/backup.log
127 echo "Cassandra Backup Succeeded"
133 fieldPath: metadata.namespace
135 - mountPath: /etc/localtime
138 - mountPath: /onap-data
143 mountPath: /root/restore.sh
146 mountPath: /root/exec.py
149 - name: cassandra-backup-validate
150 image: "{{ .Values.image }}"
151 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
161 backup_result=`cat /backup/backup.log`
162 rm -rf /backup/backup.log
164 if [ "$backup_result" == "Failed" ]; then
165 echo "Backup Failed!!! So Validation Failed!!!";
169 target_dir=$(ls -td -- /backup/*/ | head -n 1)
170 chown -R cassandra.cassandra $target_dir
172 {{ range $i, $e := until (int .Values.replicaCount) }}
173 dbSize=$(du -ks $target_dir/cassandra-{{ $i }}/data|awk -F " " '{ printf $1 }')
174 minDbSize={{ (int $root.Values.backup.dbSize) }}
175 if [ $dbSize -lt $minDbSize ]; then
176 remove_dir $target_dir
177 echo "Validation Failed!!! dbSize ($dbSize) is less than minimum size (1)!!!"
180 rm -rf /var/lib/cassandra/*
181 cp -Ra $target_dir/cassandra-{{ $i }}/data /var/lib/cassandra
182 export CASSANDRA_LISTEN_ADDRESS="127.0.0.1"
183 /docker-entrypoint.sh -Dcassandra.ignore_dc=true -Dcassandra.ignore_rack=true &
187 for d in $target_dir/cassandra-{{ $i }}/data/*/; do
188 d=$(echo $d | sed 's:/*$::')
189 keyspace_name=$(echo "$d" | awk -F/ '{ print $NF }')
190 if [ 1 ] {{- range $t, $keyspace := $root.Values.backup.keyspacesToSkip }} && [ "{{ $keyspace.name }}" != "$keyspace_name" ] {{- end }}; then
191 echo "Verifying the data for $keyspace_name "
192 nodetool verify -e $keyspace_name
194 if [ $ret -ne 0 ]; then
195 remove_dir $target_dir
196 echo "Validation Failed!!!"
203 echo "Validation Successful!!!"
205 totalFiles=`ls -t | grep "backup-" | wc -l`
206 if [ $totalFiles -gt {{ .Values.backup.retentionPeriod }} ]; then
207 filestoDelete=`expr $totalFiles - {{ .Values.backup.retentionPeriod }}`
208 ls -tr | grep backup | head -$filestoDelete | xargs rm -rf
211 - name: CASSANDRA_CLUSTER_NAME
212 value: {{ .Values.config.clusterName }}
213 - name: MAX_HEAP_SIZE
214 value: {{ .Values.config.heap.max }}
216 value: {{ .Values.config.heap.min }}
220 fieldPath: status.podIP
225 mountPath: /etc/localtime
233 name: {{ include "common.fullname" $ }}-configmap
236 persistentVolumeClaim:
237 claimName: {{ include "common.fullname" . }}-db-data
239 persistentVolumeClaim:
240 claimName: {{ include "common.fullname" . }}-backup-data