@@ -5,6 +5,7 @@ function wait_restore_completion_by_cluster_cr() {
55 local max_retries=$1
66 local wait_interval=5
77 local retries=0
8+ local state=0
89
910 while true ; do
1011 cluster_json=$( kubectl get clusters.apps.kubeblocks.io " ${KB_CLUSTER_NAME} " -n " ${KB_NAMESPACE} " -o json 2>&1 )
@@ -25,7 +26,10 @@ function wait_restore_completion_by_cluster_cr() {
2526 echo " INFO: No restore-from-backup annotation, do not need to restore."
2627 return 0
2728 else
28- echo " INFO: Waiting for restore completion..."
29+ if [[ " $state " != " 1" ]]; then
30+ echo " INFO: Waiting for restore completion..."
31+ state=1
32+ fi
2933 sleep $wait_interval
3034 (( retries++ ))
3135 if [[ -n " $max_retries " && " $retries " -ge " $max_retries " ]]; then
@@ -53,16 +57,25 @@ function process_restore_signal() {
5357 local process=" $1 "
5458 local target_signal=" $2 "
5559 local pbm_backupfile=$MONGODB_ROOT /tmp/mongodb_pbm.backup
60+ local last_annotation_value=" "
61+ local last_state=" 0"
5662 restore_signal_cm_name=" $KB_CLUSTER_NAME -restore-signal"
5763 restore_signal_cm_namespace=" $KB_NAMESPACE "
5864 while true ; do
5965 kubectl_get_result=$( kubectl get configmap $restore_signal_cm_name -n $restore_signal_cm_namespace -o json 2>&1 )
6066 kubectl_get_exit_code=$?
6167 if [ " $kubectl_get_exit_code " -ne 0 ]; then
62- echo " INFO: Waiting for restore signal..."
68+ if [[ " $last_state " != " 1" ]]; then
69+ echo " INFO: Waiting for restore signal..."
70+ last_state=" 1"
71+ fi
6372 else
73+ last_state=" 0"
6474 annotation_value=$( echo " $kubectl_get_result " | jq -r ' .metadata.labels["apps.kubeblocks.io/restore-mongodb-shard"] // empty' )
65- echo " INFO: Restore signal is $annotation_value ."
75+ if [[ " $annotation_value " != " $last_annotation_value " ]]; then
76+ echo " INFO: Restore signal is $annotation_value ."
77+ last_annotation_value=" $annotation_value "
78+ fi
6679 if [[ " $annotation_value " == " start" ]]; then
6780 if [[ " $target_signal " == " start" ]]; then
6881 echo " INFO: Restore $annotation_value signal received, starting restore..."
0 commit comments