File tree Expand file tree Collapse file tree 2 files changed +66
-15
lines changed Expand file tree Collapse file tree 2 files changed +66
-15
lines changed Original file line number Diff line number Diff line change 1
1
#! /bin/bash
2
2
3
- set -Eeuo pipefail
3
+ set -e
4
4
set -o xtrace
5
5
6
- log=/tmp/pbm-agent.log
6
+ PBM_AGENT_LOG=/tmp/pbm-agent.log
7
+ MONGOD_LOG=/tmp/mongod.log
8
+ PHYSICAL_RESTORE_DIR=/data/db/pbm-restore-logs
9
+
10
+ function handle_sigterm() {
11
+ echo " Received SIGTERM, cleaning up..."
12
+
13
+ mkdir ${PHYSICAL_RESTORE_DIR}
14
+ mv pbm.restore.log.* ${PBM_AGENT_LOG} ${MONGOD_LOG} ${PHYSICAL_RESTORE_DIR} /
15
+
16
+ echo " Restore finished, you can find logs in ${PHYSICAL_RESTORE_DIR} "
17
+ exit 0
18
+ }
19
+
20
+ trap ' handle_sigterm' 15
7
21
8
22
touch /opt/percona/restore-in-progress
9
23
10
- /opt/percona/pbm-agent 1>&2 2> ${log} &
11
- /opt/percona/ps-entry.sh " $@ " 1>&2 2> /tmp/mongod.log
24
+ /opt/percona/pbm-agent > ${PBM_AGENT_LOG} 2>&1 &
25
+ pbm_pid=$!
26
+
27
+ /opt/percona/ps-entry.sh " $@ " > ${MONGOD_LOG} 2>&1 &
28
+ mongod_pid=$!
12
29
13
- echo " Physical restore in progress"
14
- tail -n +1 -f ${log}
15
- sleep infinity
30
+ set +o xtrace
31
+ echo " Physical restore in progress... pbm-agent logs: ${PBM_AGENT_LOG} mongod logs: ${MONGOD_LOG} "
32
+ echo " Script PID: $$ , pbm-agent PID: $pbm_pid , mongod PID: $mongod_pid "
33
+ while true ; do
34
+ echo " Still in progress at $( date) "
35
+ sleep 10
36
+ done
Original file line number Diff line number Diff line change @@ -337,6 +337,36 @@ simple_data_check() {
337
337
fi
338
338
}
339
339
340
+ get_mongod_pods () {
341
+ local cluster=$1
342
+
343
+ kubectl_bin get pod \
344
+ --no-headers \
345
+ -l app.kubernetes.io/instance=${cluster} \
346
+ -l app.kubernetes.io/component=mongod
347
+
348
+ }
349
+
350
+ collect_physical_restore_logs () {
351
+ local cluster=$1
352
+ local restore=$2
353
+
354
+ for pod in $( get_mongod_pods ${cluster} ) ; do
355
+ desc " pbm-agent logs from ${pod} "
356
+ kubectl_bin exec -it ${pod} -- cat /tmp/pbm-agent.log || true
357
+ done
358
+ }
359
+
360
+ is_physical_backup () {
361
+ local backup=$1
362
+
363
+ if [[ $( kubectl_bin get psmdb-backup ${backup} -o jsonpath={.status.type}) == " physical" ]]; then
364
+ return 0
365
+ fi
366
+
367
+ return 1
368
+ }
369
+
340
370
wait_restore () {
341
371
local backup_name=$1
342
372
local cluster_name=$2
@@ -359,15 +389,15 @@ wait_restore() {
359
389
break
360
390
fi
361
391
if [[ $retry -ge $wait_time || ${current_state} == ' error' ]]; then
362
- kubectl_bin logs ${OPERATOR_NS: +-n $OPERATOR_NS } $( get_operator_pod) \
363
- | grep -v ' level=info' \
364
- | grep -v ' level=debug' \
365
- | grep -v ' Getting tasks for pod' \
366
- | grep -v ' Getting pods from source' \
367
- | tail -100
392
+ desc " operator logs:"
393
+ kubectl_bin logs ${OPERATOR_NS: +-n $OPERATOR_NS } $( get_operator_pod) | tail -100
394
+
395
+ if is_physical_backup ${backup_name} ; then
396
+ collect_physical_restore_logs
397
+ fi
398
+
368
399
kubectl_bin get psmdb-restore restore-${backup_name} -o yaml
369
- echo " Restore object restore-${backup_name} is in ${current_state} state."
370
- echo something went wrong with operator or kubernetes cluster
400
+ log " Restore object restore-${backup_name} is in ${current_state} state."
371
401
exit 1
372
402
fi
373
403
done
You can’t perform that action at this time.
0 commit comments