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" . }}
22 labels: {{- include "common.labels" . | nindent 4 }}
24 schedule: {{ .Values.backup.cron | quote }}
25 concurrencyPolicy: Forbid
26 startingDeadlineSeconds: 120
31 labels: {{- include "common.labels" . | nindent 12 }}
32 annotations: {{- include "common.tplValue" (dict "value" .Values.podAnnotations "context" .) | nindent 12 }}
33 name: {{ include "common.name" . }}
41 - {{ include "common.name" . }}
47 fieldPath: metadata.namespace
48 image: "{{ include "common.repository" . }}/{{ .Values.global.readinessImage }}"
49 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
50 name: {{ include "common.name" . }}-readiness
51 - name: "cassandra-backup-init"
52 image: "{{ include "common.repository" . }}/{{ .Values.global.readinessImage }}"
53 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
60 echo "Clearing snapshots!!!"
61 command="nodetool clearsnapshot -t $curr_time"
62 /app/exec.py -p "{{ include "common.name" . }}" -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 /app/exec.py -p "{{ include "common.name" . }}" -c "$command"
79 echo "Cleaned Node!! Backing up database now!!!"
81 command="nodetool snapshot -t $curr_time"
82 /app/exec.py -p "{{ include "common.name" . }}" -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 /app/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 {{- range $i := until (int .Values.replicaCount)}}
139 - mountPath: /onap-data/cassandra-{{ $i }}
140 name: data-dir-{{ $i }}
145 mountPath: /app/restore.sh
148 mountPath: /app/exec.py
151 - name: cassandra-backup-validate
152 image: "{{ include "common.repository" . }}/{{ .Values.image }}"
153 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
163 backup_result=`cat /backup/backup.log`
164 rm -rf /backup/backup.log
166 if [ "$backup_result" == "Failed" ]; then
167 echo "Backup Failed!!! So Validation Failed!!!";
171 target_dir=$(ls -td -- /backup/*/ | head -n 1)
172 chown -R cassandra.cassandra $target_dir
174 {{ range $i, $e := until (int .Values.replicaCount) }}
175 dbSize=$(du -ks $target_dir/cassandra-{{ $i }}/data|awk -F " " '{ printf $1 }')
176 minDbSize={{ (int $root.Values.backup.dbSize) }}
177 if [ $dbSize -lt $minDbSize ]; then
178 remove_dir $target_dir
179 echo "Validation Failed!!! dbSize ($dbSize) is less than minimum size (1)!!!"
182 rm -rf /var/lib/cassandra/*
183 cp -Ra $target_dir/cassandra-{{ $i }}/data /var/lib/cassandra
184 export CASSANDRA_LISTEN_ADDRESS="127.0.0.1"
185 /docker-entrypoint.sh -Dcassandra.ignore_dc=true -Dcassandra.ignore_rack=true &
189 for d in $target_dir/cassandra-{{ $i }}/data/*/; do
190 d=$(echo $d | sed 's:/*$::')
191 keyspace_name=$(echo "$d" | awk -F/ '{ print $NF }')
192 if [ 1 ] {{- range $t, $keyspace := $root.Values.backup.keyspacesToSkip }} && [ "{{ $keyspace.name }}" != "$keyspace_name" ] {{- end }}; then
193 echo "Verifying the data for $keyspace_name "
194 nodetool verify -e $keyspace_name
196 if [ $ret -ne 0 ]; then
197 remove_dir $target_dir
198 echo "Validation Failed!!!"
205 echo "Validation Successful!!!"
207 totalFiles=`ls -t | grep "backup-" | wc -l`
208 if [ $totalFiles -gt {{ .Values.backup.retentionPeriod }} ]; then
209 filestoDelete=`expr $totalFiles - {{ .Values.backup.retentionPeriod }}`
210 ls -tr | grep backup | head -$filestoDelete | xargs rm -rf
213 - name: CASSANDRA_CLUSTER_NAME
214 value: {{ .Values.config.clusterName }}
215 - name: MAX_HEAP_SIZE
216 value: {{ .Values.config.heap.max }}
218 value: {{ .Values.config.heap.min }}
222 fieldPath: status.podIP
227 mountPath: /etc/localtime
235 name: {{ include "common.fullname" . }}-configmap
237 {{- range $i := until (int .Values.replicaCount)}}
238 - name: data-dir-{{ $i }}
239 persistentVolumeClaim:
240 claimName: {{ include "common.fullname" . }}-data-{{ $i }}
243 persistentVolumeClaim:
244 claimName: {{ include "common.fullname" . }}-backup-data