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.
17 {{- if .Values.backup.enabled }}
18 apiVersion: batch/v1beta1
21 name: {{ include "common.fullname" . }}-backup
22 namespace: {{ include "common.namespace" . }}
23 labels: {{- include "common.labels" . | nindent 4 }}
25 schedule: {{ .Values.backup.cron | quote }}
26 concurrencyPolicy: Forbid
27 startingDeadlineSeconds: 120
32 labels: {{- include "common.labels" . | nindent 12 }}
33 annotations: {{- include "common.tplValue" (dict "value" .Values.podAnnotations "context" .) | nindent 12 }}
34 name: {{ include "common.name" . }}
42 - {{ include "common.name" . }}
48 fieldPath: metadata.namespace
49 image: "{{ .Values.global.readinessRepository }}/{{ .Values.global.readinessImage }}"
50 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
51 name: {{ include "common.name" . }}-readiness
52 - name: "cassandra-backup-init"
53 image: "{{ .Values.global.readinessRepository }}/{{ .Values.global.readinessImage }}"
54 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
61 echo "Clearing snapshots!!!"
62 command="nodetool clearsnapshot -t $curr_time"
63 /root/exec.py -p "cassandra" -c "$command"
71 {{ range $i, $e := until (int .Values.replicaCount) }}
72 target_dir=/backup/temp/cassandra-{{ $i }}
74 cp -Ra /onap-data/cassandra-{{ $i }}/data/ $target_dir/
77 echo "Executing cleanup!!"
78 command="nodetool cleanup"
79 /root/exec.py -p "cassandra" -c "$command"
80 echo "Cleaned Node!! Backing up database now!!!"
82 command="nodetool snapshot -t $curr_time"
83 /root/exec.py -p "cassandra" -c "$command"
85 if [ $retCode -ne 0 ]; then
86 echo "Backup Failed!!!"
88 clearSnapshot $curr_time
89 echo "Failed" > /backup/backup.log
93 backup_dir=/backup/temp
94 {{ range $i, $e := until (int .Values.replicaCount) }}
95 for d in $backup_dir/cassandra-{{ $i }}/data/*/ ; do
96 d=$(echo $d | sed 's:/*$::')
97 keyspace_name=$(echo "$d" | awk -F/ '{ print $NF }')
98 if [ 1 ] {{- range $t, $keyspace := $root.Values.backup.keyspacesToSkip }} && [ "{{ $keyspace.name }}" != "$keyspace_name" ] {{- end }}; then
99 /root/restore.sh -b $backup_dir/cassandra-{{ $i }}/data -s /onap-data/cassandra-{{ $i }}/data/$keyspace_name -k $keyspace_name -t $curr_time &
107 if [ $? -ne 0 ]; then
109 echo "Creation of Backup Failed!!!"
110 clearSnapshot $curr_time
111 echo "Failed" > /backup/backup.log
116 clearSnapshot $curr_time
119 if [ $exit_code -ne 0 ]; then
121 echo "Backup Failed!!!"
122 echo "Failed" > /backup/backup.log
126 mv /backup/temp /backup/backup-${curr_time}
127 echo "Success" > /backup/backup.log
128 echo "Cassandra Backup Succeeded"
134 fieldPath: metadata.namespace
136 - mountPath: /etc/localtime
139 {{- range $i := until (int .Values.replicaCount)}}
140 - mountPath: /onap-data/cassandra-{{ $i }}
141 name: data-dir-{{ $i }}
146 mountPath: /root/restore.sh
149 mountPath: /root/exec.py
152 - name: cassandra-backup-validate
153 image: "{{ .Values.image }}"
154 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
164 backup_result=`cat /backup/backup.log`
165 rm -rf /backup/backup.log
167 if [ "$backup_result" == "Failed" ]; then
168 echo "Backup Failed!!! So Validation Failed!!!";
172 target_dir=$(ls -td -- /backup/*/ | head -n 1)
173 chown -R cassandra.cassandra $target_dir
175 {{ range $i, $e := until (int .Values.replicaCount) }}
176 dbSize=$(du -ks $target_dir/cassandra-{{ $i }}/data|awk -F " " '{ printf $1 }')
177 minDbSize={{ (int $root.Values.backup.dbSize) }}
178 if [ $dbSize -lt $minDbSize ]; then
179 remove_dir $target_dir
180 echo "Validation Failed!!! dbSize ($dbSize) is less than minimum size (1)!!!"
183 rm -rf /var/lib/cassandra/*
184 cp -Ra $target_dir/cassandra-{{ $i }}/data /var/lib/cassandra
185 export CASSANDRA_LISTEN_ADDRESS="127.0.0.1"
186 /docker-entrypoint.sh -Dcassandra.ignore_dc=true -Dcassandra.ignore_rack=true &
190 for d in $target_dir/cassandra-{{ $i }}/data/*/; do
191 d=$(echo $d | sed 's:/*$::')
192 keyspace_name=$(echo "$d" | awk -F/ '{ print $NF }')
193 if [ 1 ] {{- range $t, $keyspace := $root.Values.backup.keyspacesToSkip }} && [ "{{ $keyspace.name }}" != "$keyspace_name" ] {{- end }}; then
194 echo "Verifying the data for $keyspace_name "
195 nodetool verify -e $keyspace_name
197 if [ $ret -ne 0 ]; then
198 remove_dir $target_dir
199 echo "Validation Failed!!!"
206 echo "Validation Successful!!!"
208 totalFiles=`ls -t | grep "backup-" | wc -l`
209 if [ $totalFiles -gt {{ .Values.backup.retentionPeriod }} ]; then
210 filestoDelete=`expr $totalFiles - {{ .Values.backup.retentionPeriod }}`
211 ls -tr | grep backup | head -$filestoDelete | xargs rm -rf
214 - name: CASSANDRA_CLUSTER_NAME
215 value: {{ .Values.config.clusterName }}
216 - name: MAX_HEAP_SIZE
217 value: {{ .Values.config.heap.max }}
219 value: {{ .Values.config.heap.min }}
223 fieldPath: status.podIP
228 mountPath: /etc/localtime
236 name: {{ include "common.fullname" . }}-configmap
238 {{- range $i := until (int .Values.replicaCount)}}
239 - name: data-dir-{{ $i }}
240 persistentVolumeClaim:
241 claimName: {{ include "common.fullname" $global }}-data-{{ include "common.fullname" $global }}-{{ $i }}
244 persistentVolumeClaim:
245 claimName: {{ include "common.fullname" . }}-backup-data