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 {{- if .Values.global.cassandra.useOperator }}
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 labels: {{- include "common.labels" . | nindent 12 }}
34 annotations: {{- include "common.tplValue" (dict "value" .Values.podAnnotations "context" .) | nindent 12 }}
35 name: {{ include "common.name" . }}
43 - {{ include "common.name" . }}
49 fieldPath: metadata.namespace
50 image: {{ include "repositoryGenerator.image.readiness" . }}
51 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
52 name: {{ include "common.name" . }}-readiness
60 - name: "cassandra-backup-init"
61 image: {{ include "repositoryGenerator.image.readiness" . }}
62 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
76 echo "Clearing snapshots!!!"
77 command="nodetool clearsnapshot -t $curr_time"
78 /app/exec.py -p "{{ include "common.name" . }}" -c "$command"
86 {{ range $i, $e := until (int .Values.replicaCount) }}
87 target_dir=/backup/temp/cassandra-{{ $i }}
89 cp -Ra /onap-data/cassandra-{{ $i }}/data/ $target_dir/
92 echo "Executing cleanup!!"
93 command="nodetool cleanup"
94 /app/exec.py -p "{{ include "common.name" . }}" -c "$command"
95 echo "Cleaned Node!! Backing up database now!!!"
97 command="nodetool snapshot -t $curr_time"
98 /app/exec.py -p "{{ include "common.name" . }}" -c "$command"
100 if [ $retCode -ne 0 ]; then
101 echo "Backup Failed!!!"
103 clearSnapshot $curr_time
104 echo "Failed" > /backup/backup.log
108 backup_dir=/backup/temp
109 {{ range $i, $e := until (int .Values.replicaCount) }}
110 for d in $backup_dir/cassandra-{{ $i }}/data/*/ ; do
111 d=$(echo $d | sed 's:/*$::')
112 keyspace_name=$(echo "$d" | awk -F/ '{ print $NF }')
113 if [ 1 ] {{- range $t, $keyspace := $root.Values.backup.keyspacesToSkip }} && [ "{{ $keyspace.name }}" != "$keyspace_name" ] {{- end }}; then
114 /app/restore.sh -b $backup_dir/cassandra-{{ $i }}/data -s /onap-data/cassandra-{{ $i }}/data/$keyspace_name -k $keyspace_name -t $curr_time &
122 if [ $? -ne 0 ]; then
124 echo "Creation of Backup Failed!!!"
125 clearSnapshot $curr_time
126 echo "Failed" > /backup/backup.log
131 clearSnapshot $curr_time
134 if [ $exit_code -ne 0 ]; then
136 echo "Backup Failed!!!"
137 echo "Failed" > /backup/backup.log
141 mv /backup/temp /backup/backup-${curr_time}
142 echo "Success" > /backup/backup.log
143 echo "Cassandra Backup Succeeded"
149 fieldPath: metadata.namespace
151 - mountPath: /etc/localtime
154 {{- range $i := until (int .Values.replicaCount)}}
155 - mountPath: /onap-data/cassandra-{{ $i }}
156 name: data-dir-{{ $i }}
161 mountPath: /app/restore.sh
164 mountPath: /app/exec.py
167 - name: cassandra-backup-validate
168 image: {{ include "repositoryGenerator.dockerHubRepository" . }}/{{ .Values.image }}
169 imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
179 backup_result=`cat /backup/backup.log`
180 rm -rf /backup/backup.log
182 if [ "$backup_result" == "Failed" ]; then
183 echo "Backup Failed!!! So Validation Failed!!!";
187 target_dir=$(ls -td -- /backup/*/ | head -n 1)
188 chown -R cassandra.cassandra $target_dir
190 {{ range $i, $e := until (int .Values.replicaCount) }}
191 dbSize=$(du -ks $target_dir/cassandra-{{ $i }}/data|awk -F " " '{ printf $1 }')
192 minDbSize={{ (int $root.Values.backup.dbSize) }}
193 if [ $dbSize -lt $minDbSize ]; then
194 remove_dir $target_dir
195 echo "Validation Failed!!! dbSize ($dbSize) is less than minimum size (1)!!!"
198 rm -rf /var/lib/cassandra/*
199 cp -Ra $target_dir/cassandra-{{ $i }}/data /var/lib/cassandra
200 export CASSANDRA_LISTEN_ADDRESS="127.0.0.1"
201 /docker-entrypoint.sh -Dcassandra.ignore_dc=true -Dcassandra.ignore_rack=true &
205 for d in $target_dir/cassandra-{{ $i }}/data/*/; do
206 d=$(echo $d | sed 's:/*$::')
207 keyspace_name=$(echo "$d" | awk -F/ '{ print $NF }')
208 if [ 1 ] {{- range $t, $keyspace := $root.Values.backup.keyspacesToSkip }} && [ "{{ $keyspace.name }}" != "$keyspace_name" ] {{- end }}; then
209 echo "Verifying the data for $keyspace_name "
210 nodetool verify -e $keyspace_name
212 if [ $ret -ne 0 ]; then
213 remove_dir $target_dir
214 echo "Validation Failed!!!"
221 echo "Validation Successful!!!"
223 totalFiles=`ls -t | grep "backup-" | wc -l`
224 if [ $totalFiles -gt {{ .Values.backup.retentionPeriod }} ]; then
225 filestoDelete=`expr $totalFiles - {{ .Values.backup.retentionPeriod }}`
226 ls -tr | grep backup | head -$filestoDelete | xargs rm -rf
229 - name: CASSANDRA_CLUSTER_NAME
230 value: {{ .Values.config.clusterName }}
231 - name: MAX_HEAP_SIZE
232 value: {{ .Values.config.heap.max }}
234 value: {{ .Values.config.heap.min }}
238 fieldPath: status.podIP
243 mountPath: /etc/localtime
251 name: {{ include "common.fullname" . }}-configmap
253 {{- range $i := until (int .Values.replicaCount)}}
254 - name: data-dir-{{ $i }}
255 persistentVolumeClaim:
256 claimName: {{ include "common.fullname" . }}-data-{{ $i }}
259 persistentVolumeClaim:
260 claimName: {{ include "common.fullname" . }}-backup-data