Skip to content

Commit 4a78843

Browse files
committed
K8SPSMDB-1308: Improve physical restore logs
1 parent 22a1238 commit 4a78843

File tree

2 files changed

+66
-15
lines changed

2 files changed

+66
-15
lines changed

build/physical-restore-ps-entry.sh

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,36 @@
11
#!/bin/bash
22

3-
set -Eeuo pipefail
3+
set -e
44
set -o xtrace
55

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
721

822
touch /opt/percona/restore-in-progress
923

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=$!
1229

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

e2e-tests/functions

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,36 @@ simple_data_check() {
337337
fi
338338
}
339339

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+
340370
wait_restore() {
341371
local backup_name=$1
342372
local cluster_name=$2
@@ -359,15 +389,15 @@ wait_restore() {
359389
break
360390
fi
361391
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+
368399
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."
371401
exit 1
372402
fi
373403
done

0 commit comments

Comments
 (0)