diff --git a/addons/mongodb/dataprotection/common-scripts.sh b/addons/mongodb/dataprotection/common-scripts.sh index ae59d8e6c1..ff92ca69bb 100644 --- a/addons/mongodb/dataprotection/common-scripts.sh +++ b/addons/mongodb/dataprotection/common-scripts.sh @@ -23,22 +23,9 @@ function DP_error_log() { echo "${curr_date} ERROR: $msg" } -function buildJsonString() { - local jsonString=${1} - local key=${2} - local value=${3} - if [ ! -z "$jsonString" ];then - jsonString="${jsonString}," - fi - echo "${jsonString}\"${key}\":\"${value}\"" -} - # Save backup status info file for syncing progress. # timeFormat: %Y-%m-%dT%H:%M:%SZ function DP_save_backup_status_info() { - export PATH="$PATH:$DP_DATASAFED_BIN_PATH" - export DATASAFED_BACKEND_BASE_PATH="$DP_BACKUP_BASE_PATH" - local totalSize=$1 local startTime=$2 local stopTime=$3 @@ -153,72 +140,14 @@ function set_backup_config_env() { DP_log "storage config have been extracted." } -# config backup agent -generate_endpoints() { - local fqdns=$1 - local port=$2 - - if [ -z "$fqdns" ]; then - echo "ERROR: No FQDNs provided for endpoints." >&2 - exit 1 - fi - - IFS=',' read -ra fqdn_array <<< "$fqdns" - local endpoints=() - - for fqdn in "${fqdn_array[@]}"; do - trimmed_fqdn=$(echo "$fqdn" | xargs) - if [[ -n "$trimmed_fqdn" ]]; then - endpoints+=("${trimmed_fqdn}:${port}") - fi - done - - IFS=','; echo "${endpoints[*]}" -} - -function export_pbm_env_vars() { - export PBM_AGENT_MONGODB_USERNAME="$MONGODB_USER" - export PBM_AGENT_MONGODB_PASSWORD="$MONGODB_PASSWORD" - - cfg_server_endpoints="$(generate_endpoints "$CFG_SERVER_POD_FQDN_LIST" "$CFG_SERVER_INTERNAL_PORT")" - export PBM_MONGODB_URI="mongodb://$PBM_AGENT_MONGODB_USERNAME:$PBM_AGENT_MONGODB_PASSWORD@$cfg_server_endpoints/?authSource=admin&replSetName=$CFG_SERVER_REPLICA_SET_NAME" -} - -function export_pbm_env_vars_for_rs() { - export PBM_AGENT_MONGODB_USERNAME="$MONGODB_USER" - export PBM_AGENT_MONGODB_PASSWORD="$MONGODB_PASSWORD" - - mongodb_endpoints="$(generate_endpoints "$MONGODB_POD_FQDN_LIST" "$KB_SERVICE_PORT")" - export PBM_MONGODB_URI="mongodb://$PBM_AGENT_MONGODB_USERNAME:$PBM_AGENT_MONGODB_PASSWORD@$mongodb_endpoints/?authSource=admin&replSetName=$MONGODB_REPLICA_SET_NAME" -} - -function sync_pbm_storage_config() { - echo "INFO: Checking if PBM storage config exists" - pbm_config_exists=true - check_config=$(pbm config --mongodb-uri "$PBM_MONGODB_URI" -o json) || { - pbm_config_exists=false - echo "INFO: PBM storage config does not exist." - } - if [ "$pbm_config_exists" = "true" ]; then - # check_config=$(pbm config --mongodb-uri "$PBM_MONGODB_URI" -o json) - current_endpoint=$(echo "$check_config" | jq -r '.storage.s3.endpointUrl') - current_region=$(echo "$check_config" | jq -r '.storage.s3.region') - current_bucket=$(echo "$check_config" | jq -r '.storage.s3.bucket') - current_prefix=$(echo "$check_config" | jq -r '.storage.s3.prefix') - current_force_path_style=$(echo "$check_config" | jq -r '.storage.s3.forcePathStyle') - echo "INFO: Current PBM storage endpoint: $current_endpoint" - echo "INFO: Current PBM storage region: $current_region" - echo "INFO: Current PBM storage bucket: $current_bucket" - echo "INFO: Current PBM storage prefix: $current_prefix" - echo "INFO: Current PBM storage forcePathStyle: $current_force_path_style" - if [ "$current_prefix" = "$S3_PREFIX" ] && [ "$current_region" = "$S3_REGION" ] && [ "$current_bucket" = "$S3_BUCKET" ] && [ "$current_endpoint" = "$S3_ENDPOINT" ] && [ "$current_force_path_style" = "${S3_FORCE_PATH_STYLE:-false}" ]; then - echo "INFO: PBM storage config already exists." - else - pbm_config_exists=false - fi +function write_pbm_storage_config_file() { + local file=$1 + if [ -z "$file" ]; then + echo "ERROR: PBM storage config file path is empty" + exit 1 fi - if [ "$pbm_config_exists" = "false" ]; then - cat < /dev/null + mkdir -p "$(dirname "$file")" + cat > "$file" < /dev/null) - local purged_logs=$(echo "$pbm_logs" | awk -v start="$PBM_LOGS_START_TIME" '$1 >= start') - if [ -z "$purged_logs" ]; then +function target_syncer_host() { + if [ -n "${DP_DB_HOST:-}" ] && [ -z "${DP_TARGET_POD_NAME:-}" ]; then + echo "$DP_DB_HOST" return fi - echo "$purged_logs" - # echo "INFO: PBM logs by event: $pbm_event printed." -} -function print_pbm_tail_logs() { - echo "INFO: Printing PBM tail logs" - pbm logs --tail 20 --mongodb-uri "$PBM_MONGODB_URI" + local pod_name="${DP_TARGET_POD_NAME:-${POD_NAME:-}}" + local component_name="${CLUSTER_COMPONENT_NAME:-${KB_CLUSTER_COMP_NAME:-}}" + local namespace="${CLUSTER_NAMESPACE:-${KB_NAMESPACE:-${POD_NAMESPACE:-}}}" + local cluster_domain="${KUBERNETES_CLUSTER_DOMAIN:-cluster.local}" + if [ -z "$pod_name" ] || [ -z "$component_name" ] || [ -z "$namespace" ]; then + echo "ERROR: Cannot build target syncer host, pod=$pod_name component=$component_name namespace=$namespace" >&2 + exit 1 + fi + echo "${pod_name}.${component_name}-headless.${namespace}.svc.${cluster_domain}" } -function handle_backup_exit() { - exit_code=$? - set +e - if [ $exit_code -ne 0 ]; then - print_pbm_tail_logs +function syncerctl_cmd() { + local host + host=$(target_syncer_host) + local port="${SYNCER_SERVICE_PORT:-3601}" + syncerctl --host "$host" --port "$port" "$@" +} - echo "failed with exit code $exit_code" - touch "${DP_BACKUP_INFO_FILE}.exit" +function prepare_pbm_operation_storage_config() { + local mount_dir="${MOUNT_DIR:-}" + if [ -z "$mount_dir" ] || [[ "$mount_dir" != /* ]]; then + echo "ERROR: MOUNT_DIR must be an absolute target PVC mount path" exit 1 fi -} -function handle_restore_exit() { - exit_code=$? - set +e - if [ $exit_code -ne 0 ]; then - print_pbm_tail_logs + local input_dir="$mount_dir/tmp/pbm-restore-input" + PBM_STORAGE_CONFIG_TOKEN=$(tr -d '-' < /proc/sys/kernel/random/uuid) + if [[ ! "$PBM_STORAGE_CONFIG_TOKEN" =~ ^[A-Za-z0-9_-]{32,128}$ ]]; then + echo "ERROR: Failed to generate PBM storage config token" + exit 1 + fi + PBM_STORAGE_CONFIG_FILE="$input_dir/$PBM_STORAGE_CONFIG_TOKEN" - echo "failed with exit code $exit_code" + umask 077 + mkdir -p "$input_dir" + chmod 0700 "$input_dir" + if ! (set -o noclobber; write_pbm_storage_config_file "$PBM_STORAGE_CONFIG_FILE"); then + echo "ERROR: Failed to create PVC-backed PBM storage config" exit 1 fi + chmod 0600 "$PBM_STORAGE_CONFIG_FILE" + export PBM_STORAGE_CONFIG_FILE PBM_STORAGE_CONFIG_TOKEN } -function handle_pitr_exit() { - exit_code=$? - set +e - if [[ "$PBM_DISABLE_PITR_WHEN_EXIT" == "true" ]]; then - disable_pitr - fi +function prepare_restore_storage_config() { + prepare_pbm_operation_storage_config + RESTORE_STORAGE_CONFIG_FILE="$PBM_STORAGE_CONFIG_FILE" + RESTORE_STORAGE_CONFIG_TOKEN="$PBM_STORAGE_CONFIG_TOKEN" + RESTORE_REQUEST_ACCEPTED=false + RESTORE_COMPLETED=false + export RESTORE_STORAGE_CONFIG_FILE RESTORE_STORAGE_CONFIG_TOKEN RESTORE_REQUEST_ACCEPTED RESTORE_COMPLETED +} - if [ $exit_code -ne 0 ]; then - print_pbm_tail_logs +function wait_for_syncer_backup_completion() { + local backup_name=$1 + local retry_interval=${SYNCER_PBM_WAIT_INTERVAL_SECONDS:-5} + describe_result="" + while true; do + describe_result=$(syncerctl_cmd backup status --option "op_id=$backup_name") + local found + local status + found=$(echo "$describe_result" | jq -r '.found // false') + status=$(echo "$describe_result" | jq -r '.status // empty') + echo "INFO: Backup $backup_name status: found=$found status=$status" + if [ "$found" = "true" ] && [ "$status" = "done" ]; then + return 0 + fi + if [ "$status" = "error" ] || [ "$status" = "failed" ]; then + echo "ERROR: Backup $backup_name failed: $(echo "$describe_result" | jq -r '.error // empty')" + exit 1 + fi + sleep "$retry_interval" + done +} - echo "failed with exit code $exit_code" - touch "${DP_BACKUP_INFO_FILE}.exit" - exit 1 +function save_syncer_backup_info() { + local response=$1 + local available + available=$(echo "$response" | jq -r '.backup_info.available // false') + if [ "$available" != "true" ]; then + echo "INFO: Syncer reports no backup range available." + return 1 fi + local total_size start_time end_time extras + total_size=$(echo "$response" | jq -r '.backup_info.total_size // 0') + start_time=$(echo "$response" | jq -r '.backup_info.start_time // empty') + end_time=$(echo "$response" | jq -r '.backup_info.end_time // empty') + extras=$(echo "$response" | jq -c '.backup_info.extras // {}') + DP_save_backup_status_info "$total_size" "$start_time" "$end_time" "" "$extras" } -function wait_for_other_operations() { - status_result=$(pbm status --mongodb-uri "$PBM_MONGODB_URI" -o json) || { - echo "INFO: PBM is not configured." - return - } - local except_type=$1 - local running_status=$(echo "$status_result" | jq -r '.running') - local retry_count=0 - local max_retries=60 - while [ -n "$running_status" ] && [ "$running_status" != "{}" ] && [ $retry_count -lt $max_retries ]; do - retry_count=$((retry_count+1)) - local running_type=$(echo "$running_status" | jq -r '.type') - if [ -n "$running_type" ] && [ "$running_type" = "$except_type" ]; then - break +function wait_for_syncer_restore_completion() { + local request_id=$1 + local retry_interval=${SYNCER_RESTORE_WAIT_INTERVAL_SECONDS:-1} + local last_phase="" + if [ -z "$request_id" ]; then + echo "ERROR: Syncer restore start did not return request_id." + exit 1 + fi + while true; do + local restore_status + set +e + restore_status=$(syncerctl_cmd restore status --option "request_id=$request_id" 2>&1) + local status_exit=$? + set -e + if [ $status_exit -eq 0 ]; then + local status + local phase + status=$(echo "$restore_status" | jq -r '.status // empty') + phase=$(echo "$restore_status" | jq -r '.phase // empty') + if [ -n "$phase" ] && [ "$phase" != "$last_phase" ]; then + echo "INFO: Restore request $request_id phase=$phase" + last_phase="$phase" + fi + if [ "$status" = "done" ]; then + return 0 + fi + if [ "$status" = "failed" ] || [ "$status" = "error" ]; then + echo "ERROR: Syncer restore failed: $(echo "$restore_status" | jq -r '.error // empty')" + exit 1 + fi + else + echo "INFO: Waiting for syncer restore status: $restore_status" fi - echo "INFO: Other operation $running_type is running, waiting... ($retry_count/$max_retries)" - sleep 5 - running_status=$(pbm status --mongodb-uri "$PBM_MONGODB_URI" -o json | jq -r '.running') + sleep "$retry_interval" done - if [ $retry_count -ge $max_retries ]; then - echo "ERROR: Other operations are still running after $max_retries retries" +} + +function run_pbm_full_backup() { + set_backup_config_env + prepare_pbm_operation_storage_config + + echo "INFO: Starting $PBM_BACKUP_TYPE backup for MongoDB through syncer..." + backup_result=$(syncerctl_cmd backup start --option "type=$PBM_BACKUP_TYPE" --option "compression=$PBM_COMPRESSION" --option "storage_config_token=$PBM_STORAGE_CONFIG_TOKEN") + rm -f "$PBM_STORAGE_CONFIG_FILE" + PBM_STORAGE_CONFIG_FILE="" + PBM_STORAGE_CONFIG_TOKEN="" + backup_name=$(echo "$backup_result" | jq -r '.op_id // empty') + if [ -z "$backup_name" ] || [ "$backup_name" = "null" ]; then + echo "ERROR: syncer backup start did not return op_id: $backup_result" exit 1 fi -} + echo "INFO: Backup name: $backup_name" -function export_logs_start_time_env() { - local logs_start_time=$(date +"%Y-%m-%dT%H:%M:%SZ") - export PBM_LOGS_START_TIME="${logs_start_time}" + wait_for_syncer_backup_completion "$backup_name" + + echo "INFO: Backup status result:" + echo "$(echo "$describe_result" | jq)" + save_syncer_backup_info "$describe_result" } -function sync_pbm_config_from_storage() { - echo "INFO: Syncing PBM config from storage..." +function run_pbm_full_restore() { + prepare_restore_storage_config - wait_for_other_operations + extras=$(cat /dp_downward/status_extras) + backup_name=$(echo "$extras" | jq -r '.[0].backup_name // empty') + backup_type=$(echo "$extras" | jq -r '.[0].backup_type // empty') - pbm config --force-resync --mongodb-uri "$PBM_MONGODB_URI" - # print_pbm_logs_by_event "resync" + if [ -z "$backup_type" ] || [ -z "$backup_name" ]; then + echo "ERROR: Backup type or backup name is empty, skip restore." + exit 1 + fi - # resync wait flag might don't work - wait_for_other_operations + echo "INFO: Starting syncer physical restore..." + if ! restore_result=$(syncerctl_cmd restore start --option "backup_name=$backup_name" --option type=physical --option "storage_config_token=$RESTORE_STORAGE_CONFIG_TOKEN" 2>&1); then + echo "ERROR: Syncer restore start failed: $restore_result" + exit 1 + fi + RESTORE_REQUEST_ACCEPTED=true + echo "INFO: Syncer restore start result: $restore_result" + request_id=$(echo "$restore_result" | jq -r '.request_id // empty') - echo "INFO: PBM config synced from storage." + wait_for_syncer_restore_completion "$request_id" + RESTORE_COMPLETED=true + echo "INFO: Restore completed." } -function wait_for_backup_completion() { - describe_result="" - local retry_interval=5 - local attempt=1 - local max_retries=12 - set +e - while true; do - describe_result=$(pbm describe-backup --mongodb-uri "$PBM_MONGODB_URI" "$backup_name" -o json 2>&1) - if [ $? -eq 0 ] && [ -n "$describe_result" ]; then - backup_status=$(echo "$describe_result" | jq -r '.status') - if [ "$backup_status" = "starting" ] || [ "$backup_status" = "running" ]; then - echo "INFO: Backup status is $backup_status, retrying in ${retry_interval}s..." - elif [ "$backup_status" = "" ]; then - echo "INFO: Backup status is $backup_status, retrying in ${retry_interval}s..." - attempt=$((attempt+1)) - elif [ "$backup_status" = "done" ]; then - echo "INFO: Backup status is done." - break - else - echo "ERROR: Backup failed with status: $backup_status" - exit 1 - fi - elif echo "$describe_result" | grep -q "not found"; then - echo "INFO: Backup metadata not found, retrying in ${retry_interval}s..." - attempt=$((attempt+1)) - else - echo "ERROR: Unexpected: $describe_result" - exit 1 +function ensure_pbm_pitr_enabled() { + local current_pitr_conf + current_pitr_conf=$(syncerctl_cmd pitr status) + local current_pitr_enabled + local current_oplog_span_min + local current_pitr_compression + local current_purge_interval_seconds + current_pitr_enabled=$(echo "$current_pitr_conf" | jq -r '.enabled // false') + current_oplog_span_min=$(echo "$current_pitr_conf" | jq -r '.oplog_span_min // empty') + current_pitr_compression=$(echo "$current_pitr_conf" | jq -r '.compression // empty') + current_purge_interval_seconds=$(echo "$current_pitr_conf" | jq -r '.purge_interval_seconds // empty') + + if [ -n "${PBM_STORAGE_CONFIG_TOKEN:-}" ] || [ "$current_pitr_enabled" != "true" ] || [ "$current_oplog_span_min" != "$PBM_OPLOG_SPAN_MIN_MINUTES" ] || [ "$current_pitr_compression" != "$PBM_COMPRESSION" ] || [ "$current_purge_interval_seconds" != "$PBM_PURGE_INTERVAL_SECONDS" ]; then + echo "INFO: Applying desired PITR configuration through syncer..." + local args=(pitr enable --option "oplog_span_min=$PBM_OPLOG_SPAN_MIN_MINUTES" --option "compression=$PBM_COMPRESSION" --option "purge_interval_seconds=$PBM_PURGE_INTERVAL_SECONDS") + if [ -n "${PBM_STORAGE_CONFIG_TOKEN:-}" ]; then + args+=(--option "storage_config_token=$PBM_STORAGE_CONFIG_TOKEN") fi - sleep $retry_interval - if [ $attempt -gt $max_retries ]; then - echo "ERROR: Failed to get backup status after $max_retries attempts" - exit 1 + syncerctl_cmd "${args[@]}" + if [ -n "${PBM_STORAGE_CONFIG_FILE:-}" ]; then + rm -f "$PBM_STORAGE_CONFIG_FILE" + PBM_STORAGE_CONFIG_FILE="" + PBM_STORAGE_CONFIG_TOKEN="" fi - done - set -e - - backup_status=$(echo "$describe_result" | jq -r '.status') - if [ "$backup_status" != "done" ]; then - echo "ERROR: Backup did not complete successfully, final status: $backup_status" - exit 1 + echo "INFO: PITR config updated." fi } -function create_restore_signal() { - phase=$1 - kubectl apply -f - <&1) - kubectl_get_exit_code=$? - set -e - # Wait for the restore signal ConfigMap to be created or updated - if [[ "$kubectl_get_exit_code" -ne 0 ]]; then - if [[ "$kubectl_get_result" == *"not found"* ]]; then - create_restore_signal "start" - fi - else - annotation_value=$(echo "$kubectl_get_result" | jq -r '.metadata.labels["apps.kubeblocks.io/restore-mongodb-shard"] // empty') - if [[ "$annotation_value" == "start" ]]; then - break - elif [[ "$annotation_value" == "end" ]]; then - echo "INFO: Restore completed, exiting." - exit 0 - else - echo "INFO: Restore start signal is $annotation_value, updating..." - create_restore_signal "start" - fi - fi - sleep 1 - done - sleep 5 - echo "INFO: Prepare restore start signal completed." +function run_pbm_pitr_backup() { + set_backup_config_env + + # Apply storage once through the first PITR enable call. Re-applying storage in + # the loop clears PBM PITR settings and restarts slicing before chunks mature. + prepare_pbm_operation_storage_config + + while true; do + ensure_pbm_pitr_enabled + upload_pbm_continuous_backup_info + sleep 30 + done } -function process_restore_end_signal() { - echo "INFO: Waiting for prepare restore end signal..." - sleep 5 - dp_cm_name="$CLUSTER_NAME-restore-signal" - dp_cm_namespace="$CLUSTER_NAMESPACE" - while true; do - set +e - kubectl_get_result=$(kubectl get configmap $dp_cm_name -n $dp_cm_namespace -o json 2>&1) - kubectl_get_exit_code=$? - set -e - # Wait for the restore signal ConfigMap to be created or updated - if [[ "$kubectl_get_exit_code" -ne 0 ]]; then - if [[ "$kubectl_get_result" == *"not found"* ]]; then - create_restore_signal "end" - fi - else - annotation_value=$(echo "$kubectl_get_result" | jq -r '.metadata.labels["apps.kubeblocks.io/restore-mongodb-shard"] // empty') - if [[ "$annotation_value" == "end" ]]; then - break - else - echo "INFO: Restore end signal is $annotation_value, updating..." - create_restore_signal "end" - fi - fi - sleep 1 - done - echo "INFO: Prepare restore end signal completed." +function run_pbm_pitr_restore() { + prepare_restore_storage_config + + recovery_target_time=$(date -d "@${DP_RESTORE_TIMESTAMP}" +"%Y-%m-%dT%H:%M:%S") + echo "INFO: Recovery target time: $recovery_target_time" + + echo "INFO: Starting syncer PITR restore..." + if ! restore_result=$(syncerctl_cmd restore start --option "pitr_target=$recovery_target_time" --option type=physical --option "storage_config_token=$RESTORE_STORAGE_CONFIG_TOKEN" 2>&1); then + echo "ERROR: Syncer restore start failed: $restore_result" + exit 1 + fi + RESTORE_REQUEST_ACCEPTED=true + echo "INFO: Syncer restore start result: $restore_result" + request_id=$(echo "$restore_result" | jq -r '.request_id // empty') + + wait_for_syncer_restore_completion "$request_id" + RESTORE_COMPLETED=true + echo "INFO: Restore completed." } -function get_describe_backup_info() { - describe_result="" - local max_retries=60 - local retry_interval=5 - local attempt=1 +function handle_pbm_backup_exit() { + exit_code=$? set +e - while [ $attempt -le $max_retries ]; do - describe_result=$(pbm describe-backup --mongodb-uri "$PBM_MONGODB_URI" "$backup_name" -o json 2>&1) - if [ $? -eq 0 ] && [ -n "$describe_result" ]; then - break - elif echo "$describe_result" | grep -q "not found"; then - echo "INFO: Attempt $attempt: backup $backup_name not found, retrying in ${retry_interval}s..." - if [ $((attempt % 30)) -eq 29 ]; then - echo "INFO: Sync PBM config from storage again." - sync_pbm_config_from_storage - fi - sleep $retry_interval - ((attempt++)) - continue - else - echo "ERROR: Failed to get backup metadata: $describe_result" - exit 1 - fi - done - set -e - - if [ -z "$describe_result" ] || echo "$describe_result" | grep -q "not found"; then - echo "ERROR: Failed to get backup metadata after $max_retries attempts" - exit 1 + if [ -n "${PBM_STORAGE_CONFIG_FILE:-}" ]; then + rm -f "$PBM_STORAGE_CONFIG_FILE" + fi + if [ $exit_code -ne 0 ]; then + echo "failed with exit code $exit_code" + touch "${DP_BACKUP_INFO_FILE}.exit" + exit 1 fi } -function wait_for_restoring() { - local cnf_file="${MOUNT_DIR}/tmp/pbm_restore.cnf" - cat < ${MOUNT_DIR}/tmp/pbm_restore.cnf -storage: - type: s3 - s3: - region: ${S3_REGION} - bucket: ${S3_BUCKET} - prefix: ${S3_PREFIX} - endpointUrl: ${S3_ENDPOINT} - forcePathStyle: ${S3_FORCE_PATH_STYLE:-false} - credentials: - access-key-id: ${S3_ACCESS_KEY} - secret-access-key: ${S3_SECRET_KEY} -EOF - local attempt=0 - local max_retries=12 - local try_interval=5 - while true; do - restore_status=$(pbm describe-restore "$restore_name" -c $cnf_file -o json | jq -r '.status') - echo "INFO: Restore $restore_name status: $restore_status, retrying in ${try_interval}s..." - if [ "$restore_status" = "done" ]; then - rm $cnf_file - break - elif [ "$restore_status" = "starting" ] || [ "$restore_status" = "running" ]; then - sleep $try_interval - elif [ "$restore_status" = "" ]; then - sleep $try_interval - attempt=$((attempt+1)) - if [ $attempt -gt $max_retries ]; then - echo "ERROR: Restore $restore_name status is still empty after $max_retries retries" - rm $cnf_file - exit 1 - fi - else - rm $cnf_file - exit 1 - fi - done +function handle_restore_exit() { + exit_code=$? + set +e + if [ -n "${RESTORE_STORAGE_CONFIG_FILE:-}" ] && { [ "${RESTORE_REQUEST_ACCEPTED:-false}" != "true" ] || [ "${RESTORE_COMPLETED:-false}" = "true" ]; }; then + rm -f "$RESTORE_STORAGE_CONFIG_FILE" + fi + if [ $exit_code -ne 0 ]; then + echo "failed with exit code $exit_code" + exit 1 + fi } diff --git a/addons/mongodb/dataprotection/pbm-full-backup.sh b/addons/mongodb/dataprotection/pbm-full-backup.sh new file mode 100644 index 0000000000..0b21e00f59 --- /dev/null +++ b/addons/mongodb/dataprotection/pbm-full-backup.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -e +set -o pipefail +# syncerctl is delivered through the target data PVC at ${MOUNT_DIR}/tmp/bin. +export PATH="$PATH:${MOUNT_DIR}/tmp/bin" + +trap handle_pbm_backup_exit EXIT +run_pbm_full_backup diff --git a/addons/mongodb/dataprotection/pbm-full-restore.sh b/addons/mongodb/dataprotection/pbm-full-restore.sh new file mode 100644 index 0000000000..1349064f04 --- /dev/null +++ b/addons/mongodb/dataprotection/pbm-full-restore.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -e +set -o pipefail +# syncerctl is delivered through the target data PVC at $MOUNT_DIR/tmp/bin. +export PATH="$PATH:$MOUNT_DIR/tmp/bin" + +set_backup_config_env + +trap handle_restore_exit EXIT +run_pbm_full_restore diff --git a/addons/mongodb/dataprotection/pbm-pitr-backup.sh b/addons/mongodb/dataprotection/pbm-pitr-backup.sh new file mode 100644 index 0000000000..bca2d6397d --- /dev/null +++ b/addons/mongodb/dataprotection/pbm-pitr-backup.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# For PITR with PBM physical backups, create a fresh base backup whenever new collections must be included by restore. +# PBM only writes data to existing collections and does not support creating new ones during PITR, so a new +# (sharded) collection needs a new backup to be included. Shared by replica-set and sharded deployments. +# Ref: https://docs.percona.com/percona-backup-mongodb/usage/pitr-physical.html#post-restore-steps +set -e +set -o pipefail +# syncerctl is delivered through the target data PVC at ${MOUNT_DIR}/tmp/bin. +export PATH="$PATH:${MOUNT_DIR}/tmp/bin" + +trap handle_pbm_backup_exit EXIT +run_pbm_pitr_backup diff --git a/addons/mongodb/dataprotection/pbm-pitr-restore.sh b/addons/mongodb/dataprotection/pbm-pitr-restore.sh new file mode 100644 index 0000000000..896e373237 --- /dev/null +++ b/addons/mongodb/dataprotection/pbm-pitr-restore.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -e +set -o pipefail +# syncerctl is delivered through the target data PVC at $MOUNT_DIR/tmp/bin. +export PATH="$PATH:$MOUNT_DIR/tmp/bin" + +set_backup_config_env + +trap handle_restore_exit EXIT +run_pbm_pitr_restore diff --git a/addons/mongodb/dataprotection/rs-pbm-full-backup.sh b/addons/mongodb/dataprotection/rs-pbm-full-backup.sh deleted file mode 100644 index 346194415e..0000000000 --- a/addons/mongodb/dataprotection/rs-pbm-full-backup.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash -set -e -set -o pipefail -export PATH="$PATH:$DP_DATASAFED_BIN_PATH" -export DATASAFED_BACKEND_BASE_PATH="$DP_BACKUP_BASE_PATH" - -trap handle_exit EXIT - -export_pbm_env_vars_for_rs - -set_backup_config_env - -export_logs_start_time_env - -trap handle_backup_exit EXIT - -wait_for_other_operations - -sync_pbm_storage_config - -wait_for_other_operations - -echo "INFO: Starting $PBM_BACKUP_TYPE backup for MongoDB..." -backup_result=$(pbm backup --type=$PBM_BACKUP_TYPE --mongodb-uri "$PBM_MONGODB_URI" --compression=$PBM_COMPRESSION --wait -o json) -backup_name=$(echo "$backup_result" | jq -r '.name') -extras=$(buildJsonString "" "backup_name" "$backup_name") -extras=$(buildJsonString $extras "backup_type" "$PBM_BACKUP_TYPE") -echo "INFO: Backup name: $backup_name" - -wait_for_backup_completion - -echo "INFO: Backup description result:" -echo "$(echo $describe_result | jq)" -last_write_time=$(echo "$describe_result" | jq -r '.last_write_time') -extras=$(buildJsonString $extras "last_write_time" "$last_write_time") -start_time=$(echo "$describe_result" | jq -r '.name') -end_unix_time=$(echo "$describe_result" | jq -r '.last_write_ts') -# used for pitr -end_time=$(date -u -d "@$((end_unix_time + 2))" +"%Y-%m-%dT%H:%M:%SZ") -total_size=$(echo "$describe_result" | jq -r '.size') -DP_save_backup_status_info "$total_size" "$start_time" "$end_time" "" "{$extras}" - -print_pbm_logs_by_event "backup" diff --git a/addons/mongodb/dataprotection/rs-pbm-full-restore.sh b/addons/mongodb/dataprotection/rs-pbm-full-restore.sh deleted file mode 100644 index 5d641ec385..0000000000 --- a/addons/mongodb/dataprotection/rs-pbm-full-restore.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash -set -e -set -o pipefail -export PATH="$PATH:$DP_DATASAFED_BIN_PATH:$MOUNT_DIR/tmp/bin" -export DATASAFED_BACKEND_BASE_PATH="$DP_BACKUP_BASE_PATH" - -export_pbm_env_vars_for_rs - -set_backup_config_env - -export_logs_start_time_env - -trap handle_restore_exit EXIT - -wait_for_other_operations - -sync_pbm_storage_config - -sync_pbm_config_from_storage - -extras=$(cat /dp_downward/status_extras) -backup_name=$(echo "$extras" | jq -r '.[0].backup_name') -backup_type=$(echo "$extras" | jq -r '.[0].backup_type') - -if [ -z "$backup_type" ] || [ -z "$backup_name" ]; then - echo "ERROR: Backup type or backup name is empty, skip restore." - exit 1 -fi - -get_describe_backup_info - -rs_name=$(echo "$describe_result" | jq -r '.replsets[0].name') -mappings="$MONGODB_REPLICA_SET_NAME=$rs_name" -echo "INFO: Replica set mappings: $mappings" - -process_restore_start_signal - -wait_for_other_operations - -restore_name=$(pbm restore $backup_name --mongodb-uri "$PBM_MONGODB_URI" --replset-remapping "$mappings" -o json | jq -r '.name') - -wait_for_restoring - -process_restore_end_signal diff --git a/addons/mongodb/dataprotection/rs-pbm-pitr-backup.sh b/addons/mongodb/dataprotection/rs-pbm-pitr-backup.sh deleted file mode 100644 index 82048ad019..0000000000 --- a/addons/mongodb/dataprotection/rs-pbm-pitr-backup.sh +++ /dev/null @@ -1,136 +0,0 @@ -#!/bin/bash - -# When doing point-in-time recovery for deployments with sharded collections, PBM only writes data to existing ones and doesn’t support creating new collections. -# Therefore, whenever you create a new sharded collection, make a new backup for it to be included there. Ref: https://docs.percona.com/percona-backup-mongodb/usage/pitr-physical.html#post-restore-steps -set -e -set -o pipefail -export PATH="$PATH:$DP_DATASAFED_BIN_PATH" -export DATASAFED_BACKEND_BASE_PATH="$DP_BACKUP_BASE_PATH" - -trap handle_exit EXIT - -function enable_pitr() { - local current_pitr_conf=$(pbm config --mongodb-uri "$PBM_MONGODB_URI" -o json | jq -r '.pitr') - local current_pitr_enabled=$(echo $current_pitr_conf | jq -r '.enabled') - local current_oplog_span_min=$(echo $current_pitr_conf | jq -r '.oplogSpanMin') - local current_pitr_compression=$(echo $current_pitr_conf | jq -r '.compression') - - if [ "$current_pitr_enabled" != "true" ] || [ "$current_oplog_span_min" != "$PBM_OPLOG_SPAN_MIN_MINUTES" ] || [ "$current_pitr_compression" != "$PBM_COMPRESSION" ]; then - echo "INFO: Pitr config is not equal to the current config, updating..." - wait_for_other_operations "backup" - - pbm config --mongodb-uri "$PBM_MONGODB_URI" --set pitr.enabled=true --set pitr.oplogSpanMin=$PBM_OPLOG_SPAN_MIN_MINUTES --set pitr.compression=$PBM_COMPRESSION - echo "INFO: Pitr config updated." - fi -} - -function disable_pitr() { - echo "INFO: Disabling Pitr..." - pbm config --set pitr.enabled=false --mongodb-uri "$PBM_MONGODB_URI" - echo "INFO: Pitr disabled." -} - -function upload_continuous_backup_info() { - local status_result=$(pbm status --mongodb-uri "$PBM_MONGODB_URI" -o json) - echo "INFO: Uploading continuous backup info..." - local pitr_chunks_result=$(echo "$status_result" | jq -r '.backups.pitrChunks') - echo "INFO: Continuous backup result:" - echo "$(echo $pitr_chunks_result | jq)" - local pitr_chunks_arr=$(echo "$pitr_chunks_result" | jq -r '.pitrChunks') - if [ -z "$pitr_chunks_arr" ] || [ "$pitr_chunks_arr" = "null" ] || [ "$pitr_chunks_arr" = "[]" ]; then - echo "INFO: No oplog found." - return - fi - local filtered_sorted_chunks=$(echo "$pitr_chunks_arr" | jq 'map(select(.noBaseSnapshot != true)) | sort_by(.range.end)') - if [ -z "$filtered_sorted_chunks" ] || [ "$filtered_sorted_chunks" = "null" ] || [ "$filtered_sorted_chunks" = "[]" ]; then - echo "INFO: No oplog found." - return - fi - local last_chunk=$(echo "$filtered_sorted_chunks" | jq -r '.[-1].range') - local start_unix_time=$(echo "$last_chunk" | jq -r '.start') - local end_unix_time=$(echo "$last_chunk" | jq -r '.end') - local start_time=$(date -u -d "@${start_unix_time}" +"%Y-%m-%dT%H:%M:%SZ") - local end_time=$(date -u -d "@${end_unix_time}" +"%Y-%m-%dT%H:%M:%SZ") - local total_size=$(echo "$pitr_chunks_result" | jq -r '.size') - - local backup_type="continuous" - local extras=$(buildJsonString "" "backup_type" "$backup_type") - extras=$(buildJsonString $extras "replicaset" "$MONGODB_REPLICA_SET_NAME") - - DP_save_backup_status_info "$total_size" "$start_time" "$end_time" "" "{$extras}" - echo "INFO: Continuous backup info uploaded." -} - -function purge_pitr_chunks() { - current_time=$(date +%s) - - # Initialize last_global_purge_time if not set - if [ -z "$last_global_purge_time" ]; then - last_global_purge_time=0 - fi - - time_diff=$((current_time - last_global_purge_time)) - - if [ $time_diff -lt $(( ${PBM_PURGE_INTERVAL_SECONDS:-86400} )) ]; then - return - fi - - # Update last purge time - last_global_purge_time=$current_time - - echo "INFO: Purging PBM chunks..." - wait_for_other_operations "backup" - - pbm config --force-resync --mongodb-uri "$PBM_MONGODB_URI" - - # resync wait flag might don't work - wait_for_other_operations "backup" - - local pitr_chunks_result=$(pbm status --mongodb-uri "$PBM_MONGODB_URI" -o json | jq -r '.backups.pitrChunks') - local pitr_chunks_arr=$(echo "$pitr_chunks_result" | jq -r '.pitrChunks') - if [ -z "$pitr_chunks_arr" ] || [ "$pitr_chunks_arr" = "null" ] || [ "$pitr_chunks_arr" = "[]" ]; then - echo "INFO: No no base snapshot chunks found." - return - fi - local filtered_sorted_chunks=$(echo "$pitr_chunks_arr" | jq -e 'map(select(.noBaseSnapshot == true)) | sort_by(.range.end)') - if [ -z "$filtered_sorted_chunks" ] || [ "$filtered_sorted_chunks" = "null" ] || [ "$filtered_sorted_chunks" = "[]" ]; then - echo "INFO: No no base snapshot chunks." - return - fi - echo "INFO: No base snapshot chunks:" - echo "$(echo $filtered_sorted_chunks | jq)" - local first_chunk_end=$(echo "$filtered_sorted_chunks" | jq -r '.[0].range.end') - purge_time=$(date -u -d "@${first_chunk_end}" +"%Y-%m-%dT%H:%M:%S") - pbm cleanup --older-than $purge_time --mongodb-uri "$PBM_MONGODB_URI" --wait --yes - echo "INFO: No base snapshot chunks cleaned up." -} - -export_pbm_env_vars_for_rs - -set_backup_config_env - -export_logs_start_time_env - -trap handle_pitr_exit EXIT - -sync_pbm_storage_config - -sync_pbm_config_from_storage - -while true; do - wait_for_other_operations "backup" - - sync_pbm_storage_config - - enable_pitr - - purge_pitr_chunks - - upload_continuous_backup_info - - print_pbm_logs_by_event "pitr" - - export_logs_start_time_env - - sleep 30 -done \ No newline at end of file diff --git a/addons/mongodb/dataprotection/rs-pbm-pitr-restore.sh b/addons/mongodb/dataprotection/rs-pbm-pitr-restore.sh deleted file mode 100644 index f9d1f26353..0000000000 --- a/addons/mongodb/dataprotection/rs-pbm-pitr-restore.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash -set -e -set -o pipefail -export PATH="$PATH:$DP_DATASAFED_BIN_PATH:$MOUNT_DIR/tmp/bin" -export DATASAFED_BACKEND_BASE_PATH="$DP_BACKUP_BASE_PATH" - -export_pbm_env_vars_for_rs - -set_backup_config_env - -export_logs_start_time_env - -trap handle_restore_exit EXIT - -wait_for_other_operations - -sync_pbm_storage_config - -sync_pbm_config_from_storage - -process_restore_start_signal - -extras=$(cat /dp_downward/status_extras) -rs_name=$(echo "$extras" | jq -r '.[0].replicaset') -mappings="$MONGODB_REPLICA_SET_NAME=$rs_name" -echo "INFO: Replica set mappings: $mappings" - -recovery_target_time=$(date -d "@${DP_RESTORE_TIMESTAMP}" +"%Y-%m-%dT%H:%M:%S") -echo "INFO: Recovery target time: $recovery_target_time" - -echo "INFO: Starting restore..." - -wait_for_other_operations - -restore_name=$(pbm restore --time="$recovery_target_time" --mongodb-uri "$PBM_MONGODB_URI" --replset-remapping "$mappings" -o json | jq -r '.name') - -wait_for_restoring - -process_restore_end_signal - -echo "INFO: Restore completed." diff --git a/addons/mongodb/dataprotection/rs-pbm-restore-prepare.sh b/addons/mongodb/dataprotection/rs-pbm-restore-prepare.sh deleted file mode 100644 index d99caf0326..0000000000 --- a/addons/mongodb/dataprotection/rs-pbm-restore-prepare.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -set -e -set -o pipefail - -mkdir -p ${MOUNT_DIR}/tmp - -cd ${MOUNT_DIR}/tmp && touch mongodb_pbm.backup \ No newline at end of file diff --git a/addons/mongodb/dataprotection/shard-pbm-full-backup.sh b/addons/mongodb/dataprotection/shard-pbm-full-backup.sh deleted file mode 100644 index 0f0aa7f4c2..0000000000 --- a/addons/mongodb/dataprotection/shard-pbm-full-backup.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash -set -e -set -o pipefail -export PATH="$PATH:$DP_DATASAFED_BIN_PATH" -export DATASAFED_BACKEND_BASE_PATH="$DP_BACKUP_BASE_PATH" - -trap handle_exit EXIT - -export_pbm_env_vars - -set_backup_config_env - -export_logs_start_time_env - -trap handle_backup_exit EXIT - -wait_for_other_operations - -sync_pbm_storage_config - -wait_for_other_operations - -echo "INFO: Starting $PBM_BACKUP_TYPE backup for MongoDB..." -backup_result=$(pbm backup --type=$PBM_BACKUP_TYPE --mongodb-uri "$PBM_MONGODB_URI" --compression=$PBM_COMPRESSION --wait -o json) -backup_name=$(echo "$backup_result" | jq -r '.name') -extras=$(buildJsonString "" "backup_name" "$backup_name") -extras=$(buildJsonString $extras "backup_type" "$PBM_BACKUP_TYPE") -echo "INFO: Backup name: $backup_name" - -wait_for_backup_completion - -echo "INFO: Backup description result:" -echo "$(echo $describe_result | jq)" -last_write_time=$(echo "$describe_result" | jq -r '.last_write_time') -extras=$(buildJsonString $extras "last_write_time" "$last_write_time") -start_time=$(echo "$describe_result" | jq -r '.name') -end_unix_time=$(echo "$describe_result" | jq -r '.last_write_ts') -# used for pitr -end_time=$(date -u -d "@$((end_unix_time + 2))" +"%Y-%m-%dT%H:%M:%SZ") -total_size=$(echo "$describe_result" | jq -r '.size') -DP_save_backup_status_info "$total_size" "$start_time" "$end_time" "" "{$extras}" - -print_pbm_logs_by_event "backup" diff --git a/addons/mongodb/dataprotection/shard-pbm-full-restore.sh b/addons/mongodb/dataprotection/shard-pbm-full-restore.sh deleted file mode 100644 index 375b8587e7..0000000000 --- a/addons/mongodb/dataprotection/shard-pbm-full-restore.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/bash -set -e -set -o pipefail -export PATH="$PATH:$DP_DATASAFED_BIN_PATH:$MOUNT_DIR/tmp/bin" -export DATASAFED_BACKEND_BASE_PATH="$DP_BACKUP_BASE_PATH" - -export_pbm_env_vars - -set_backup_config_env - -export_logs_start_time_env - -trap handle_restore_exit EXIT - -wait_for_other_operations - -sync_pbm_storage_config - -sync_pbm_config_from_storage - -extras=$(cat /dp_downward/status_extras) -backup_name=$(echo "$extras" | jq -r '.[0].backup_name') -backup_type=$(echo "$extras" | jq -r '.[0].backup_type') - -if [ -z "$backup_type" ] || [ -z "$backup_name" ]; then - echo "ERROR: Backup type or backup name is empty, skip restore." - exit 1 -fi - -get_describe_backup_info - -configsvr_name=$(echo "$describe_result" | jq -r '.replsets[] | select(.configsvr == true) | .name') -echo "INFO: Config server replica set name: $configsvr_name" -shardsvr_names=$(echo "$describe_result" | jq -r '[.replsets[] | select(.configsvr != true) | .name] | join(",")') -echo "INFO: Shard replica set names: $shardsvr_names" -mappings="" -IFS="," read -r -a shardsvr_array <<< "$shardsvr_names" -shardsvr_count=${#shardsvr_array[@]} -if [ $shardsvr_count -lt 1 ]; then - echo "ERROR: No shard replica set found in the backup." - exit 1 -fi -IFS="." read -r -a new_shardsvr_array <<< "$MONGODB_SHARD_REPLICA_SET_NAME_LIST" -new_shardsvr_count=${#new_shardsvr_array[@]} -if [ $new_shardsvr_count -ne $shardsvr_count ]; then - echo "ERROR: The number of shard replica sets is not equal to the number of new shard replica sets." - exit 1 -fi -for i in "${!shardsvr_array[@]}"; do - # Get the part before "@" in new_shardsvr_array - if [ $shardsvr_count -gt 1 ]; then - shard_name="$CLUSTER_NAME-${new_shardsvr_array[i]%%@*}" - else - shard_name="${new_shardsvr_array[i]%%,*}" - fi - echo "INFO: Mapping shard ${shardsvr_array[i]} to $shard_name" - if [ $i -eq 0 ]; then - mappings="${shard_name}=${shardsvr_array[i]}" - else - mappings="$mappings,${shard_name}=${shardsvr_array[i]}" - fi -done -# If the config server name is not empty, add it to the mappings -echo "INFO: Mapping config server $configsvr_name to $CFG_SERVER_REPLICA_SET_NAME" -mappings="$mappings,$CFG_SERVER_REPLICA_SET_NAME=$configsvr_name" -echo "INFO: Shard mappings: $mappings" - -process_restore_start_signal - -wait_for_other_operations - -restore_name=$(pbm restore $backup_name --mongodb-uri "$PBM_MONGODB_URI" --replset-remapping "$mappings" -o json | jq -r '.name') - -wait_for_restoring - -process_restore_end_signal diff --git a/addons/mongodb/dataprotection/shard-pbm-pitr-backup.sh b/addons/mongodb/dataprotection/shard-pbm-pitr-backup.sh deleted file mode 100644 index 9ca07e1dce..0000000000 --- a/addons/mongodb/dataprotection/shard-pbm-pitr-backup.sh +++ /dev/null @@ -1,161 +0,0 @@ -#!/bin/bash - -# When doing point-in-time recovery for deployments with sharded collections, PBM only writes data to existing ones and doesn’t support creating new collections. -# Therefore, whenever you create a new sharded collection, make a new backup for it to be included there. Ref: https://docs.percona.com/percona-backup-mongodb/usage/pitr-physical.html#post-restore-steps -set -e -set -o pipefail -export PATH="$PATH:$DP_DATASAFED_BIN_PATH" -export DATASAFED_BACKEND_BASE_PATH="$DP_BACKUP_BASE_PATH" - -trap handle_exit EXIT - -function enable_pitr() { - local current_pitr_conf=$(pbm config --mongodb-uri "$PBM_MONGODB_URI" -o json | jq -r '.pitr') - local current_pitr_enabled=$(echo $current_pitr_conf | jq -r '.enabled') - local current_oplog_span_min=$(echo $current_pitr_conf | jq -r '.oplogSpanMin') - local current_pitr_compression=$(echo $current_pitr_conf | jq -r '.compression') - - if [ "$current_pitr_enabled" != "true" ] || [ "$current_oplog_span_min" != "$PBM_OPLOG_SPAN_MIN_MINUTES" ] || [ "$current_pitr_compression" != "$PBM_COMPRESSION" ]; then - echo "INFO: Pitr config is not equal to the current config, updating..." - wait_for_other_operations "backup" - - pbm config --mongodb-uri "$PBM_MONGODB_URI" --set pitr.enabled=true --set pitr.oplogSpanMin=$PBM_OPLOG_SPAN_MIN_MINUTES --set pitr.compression=$PBM_COMPRESSION - echo "INFO: Pitr config updated." - fi -} - -function disable_pitr() { - echo "INFO: Disabling Pitr..." - pbm config --set pitr.enabled=false --mongodb-uri "$PBM_MONGODB_URI" - echo "INFO: Pitr disabled." -} - -function upload_continuous_backup_info() { - local status_result=$(pbm status --mongodb-uri "$PBM_MONGODB_URI" -o json) - echo "INFO: Uploading continuous backup info..." - local pitr_chunks_result=$(echo "$status_result" | jq -r '.backups.pitrChunks') - echo "INFO: Continuous backup result:" - echo "$(echo $pitr_chunks_result | jq)" - local pitr_chunks_arr=$(echo "$pitr_chunks_result" | jq -r '.pitrChunks') - if [ -z "$pitr_chunks_arr" ] || [ "$pitr_chunks_arr" = "null" ] || [ "$pitr_chunks_arr" = "[]" ]; then - echo "INFO: No oplog found." - return - fi - local filtered_sorted_chunks=$(echo "$pitr_chunks_arr" | jq 'map(select(.noBaseSnapshot != true)) | sort_by(.range.end)') - if [ -z "$filtered_sorted_chunks" ] || [ "$filtered_sorted_chunks" = "null" ] || [ "$filtered_sorted_chunks" = "[]" ]; then - echo "INFO: No oplog found." - return - fi - local last_chunk=$(echo "$filtered_sorted_chunks" | jq -r '.[-1].range') - local start_unix_time=$(echo "$last_chunk" | jq -r '.start') - local end_unix_time=$(echo "$last_chunk" | jq -r '.end') - local start_time=$(date -u -d "@${start_unix_time}" +"%Y-%m-%dT%H:%M:%SZ") - local end_time=$(date -u -d "@${end_unix_time}" +"%Y-%m-%dT%H:%M:%SZ") - local total_size=$(echo "$pitr_chunks_result" | jq -r '.size') - - local backup_type="continuous" - local extras=$(buildJsonString "" "backup_type" "$backup_type") - - local pitr_nodes=$(echo "$status_result" | jq -r '.pitr.nodes?[]?') - local shardsvr="" - local configsvr="" - while IFS= read -r node; do - if [[ -n "$node" ]]; then - # Extract the text before the first "/" - local node_name=${node%%/*} - if [[ "$node" == *"config"* ]]; then - configsvr="$node_name" - else - if [ -z "$shardsvr" ]; then - shardsvr="$node_name" - else - shardsvr="$shardsvr,$node_name" - fi - fi - fi - done <<< "$pitr_nodes" - if [ -z "$shardsvr" ]; then - shardsvr=$(echo "$status_result" | jq -r '[.cluster[].rs | select(contains("config-server") | not)] | join(",")') - fi - if [ -z "$configsvr" ]; then - configsvr=$(echo "$status_result" | jq -r '[.cluster[].rs | select(contains("config-server"))] | join(",")') - fi - extras=$(buildJsonString $extras "shardsvr" "$shardsvr") - extras=$(buildJsonString $extras "configsvr" "$configsvr") - DP_save_backup_status_info "$total_size" "$start_time" "$end_time" "" "{$extras}" - echo "INFO: Continuous backup info uploaded." -} - -function purge_pitr_chunks() { - current_time=$(date +%s) - - # Initialize last_global_purge_time if not set - if [ -z "$last_global_purge_time" ]; then - last_global_purge_time=0 - fi - - time_diff=$((current_time - last_global_purge_time)) - - if [ $time_diff -lt $(( ${PBM_PURGE_INTERVAL_SECONDS:-86400} )) ]; then - return - fi - - # Update last purge time - last_global_purge_time=$current_time - - echo "INFO: Purging PBM chunks..." - wait_for_other_operations "backup" - - pbm config --force-resync --mongodb-uri "$PBM_MONGODB_URI" - - # resync wait flag might don't work - wait_for_other_operations "backup" - - local pitr_chunks_result=$(pbm status --mongodb-uri "$PBM_MONGODB_URI" -o json | jq -r '.backups.pitrChunks') - local pitr_chunks_arr=$(echo "$pitr_chunks_result" | jq -r '.pitrChunks') - if [ -z "$pitr_chunks_arr" ] || [ "$pitr_chunks_arr" = "null" ] || [ "$pitr_chunks_arr" = "[]" ]; then - echo "INFO: No no base snapshot chunks found." - return - fi - local filtered_sorted_chunks=$(echo "$pitr_chunks_arr" | jq -e 'map(select(.noBaseSnapshot == true)) | sort_by(.range.end)') - if [ -z "$filtered_sorted_chunks" ] || [ "$filtered_sorted_chunks" = "null" ] || [ "$filtered_sorted_chunks" = "[]" ]; then - echo "INFO: No no base snapshot chunks." - return - fi - echo "INFO: No base snapshot chunks:" - echo "$(echo $filtered_sorted_chunks | jq)" - local first_chunk_end=$(echo "$filtered_sorted_chunks" | jq -r '.[0].range.end') - purge_time=$(date -u -d "@${first_chunk_end}" +"%Y-%m-%dT%H:%M:%S") - pbm cleanup --older-than $purge_time --mongodb-uri "$PBM_MONGODB_URI" --wait --yes - echo "INFO: No base snapshot chunks cleaned up." -} - -export_pbm_env_vars - -set_backup_config_env - -export_logs_start_time_env - -trap handle_pitr_exit EXIT - -sync_pbm_storage_config - -sync_pbm_config_from_storage - -while true; do - wait_for_other_operations "backup" - - sync_pbm_storage_config - - enable_pitr - - purge_pitr_chunks - - upload_continuous_backup_info - - print_pbm_logs_by_event "pitr" - - export_logs_start_time_env - - sleep 30 -done \ No newline at end of file diff --git a/addons/mongodb/dataprotection/shard-pbm-pitr-restore.sh b/addons/mongodb/dataprotection/shard-pbm-pitr-restore.sh deleted file mode 100644 index 49ae89c743..0000000000 --- a/addons/mongodb/dataprotection/shard-pbm-pitr-restore.sh +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/bash -set -e -set -o pipefail -export PATH="$PATH:$DP_DATASAFED_BIN_PATH:$MOUNT_DIR/tmp/bin" -export DATASAFED_BACKEND_BASE_PATH="$DP_BACKUP_BASE_PATH" - -export_pbm_env_vars - -set_backup_config_env - -export_logs_start_time_env - -trap handle_restore_exit EXIT - -wait_for_other_operations - -sync_pbm_storage_config - -sync_pbm_config_from_storage - -extras=$(cat /dp_downward/status_extras) -configsvr_name=$(echo "$extras" | jq -r '.[0].configsvr') -echo "INFO: Config server replica set name: $configsvr_name" -shardsvr_names=$(echo "$extras" | jq -r '.[0].shardsvr') -echo "INFO: Shard replica set names: $shardsvr_names" -mappings="" -IFS="," read -r -a shardsvr_array <<< "$shardsvr_names" -shardsvr_count=${#shardsvr_array[@]} -if [ $shardsvr_count -lt 1 ]; then - echo "ERROR: No shard replica set found in the backup." - exit 1 -fi -IFS="." read -r -a new_shardsvr_array <<< "$MONGODB_SHARD_REPLICA_SET_NAME_LIST" -new_shardsvr_count=${#new_shardsvr_array[@]} -if [ $new_shardsvr_count -ne $shardsvr_count ]; then - echo "ERROR: The number of shard replica sets is not equal to the number of new shard replica sets." - exit 1 -fi -for i in "${!shardsvr_array[@]}"; do - # Get the part before "@" in new_shardsvr_array - if [ $shardsvr_count -gt 1 ]; then - shard_name="$CLUSTER_NAME-${new_shardsvr_array[i]%%@*}" - else - shard_name="${new_shardsvr_array[i]%%,*}" - fi - echo "INFO: Mapping shard ${shardsvr_array[i]} to $shard_name" - if [ $i -eq 0 ]; then - mappings="${shard_name}=${shardsvr_array[i]}" - else - mappings="$mappings,${shard_name}=${shardsvr_array[i]}" - fi -done -# If the config server name is not empty, add it to the mappings -echo "INFO: Mapping config server $configsvr_name to $CFG_SERVER_REPLICA_SET_NAME" -mappings="$mappings,$CFG_SERVER_REPLICA_SET_NAME=$configsvr_name" -echo "INFO: Shard mappings: $mappings" - -process_restore_start_signal - -recovery_target_time=$(date -d "@${DP_RESTORE_TIMESTAMP}" +"%Y-%m-%dT%H:%M:%S") -echo "INFO: Recovery target time: $recovery_target_time" - - -echo "INFO: Starting restore..." - -wait_for_other_operations - -restore_name=$(pbm restore --time="$recovery_target_time" --mongodb-uri "$PBM_MONGODB_URI" --replset-remapping "$mappings" -o json | jq -r '.name') - -wait_for_restoring - -process_restore_end_signal - -echo "INFO: Restore completed." diff --git a/addons/mongodb/dataprotection/shard-pbm-pre-backup.sh b/addons/mongodb/dataprotection/shard-pbm-pre-backup.sh deleted file mode 100644 index ef2a5c5f3e..0000000000 --- a/addons/mongodb/dataprotection/shard-pbm-pre-backup.sh +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/bash -set -e -set -o pipefail - -client_path=$(whereis mongosh | awk '{print $2}') -CLIENT="mongosh" -if [ -z "$client_path" ]; then - CLIENT="mongo" -fi -CLUSTER_MONGO="$CLIENT --host $MONGOS_INTERNAL_HOST --port $MONGOS_INTERNAL_PORT -u $MONGODB_USER -p $MONGODB_PASSWORD --quiet --eval" - -# Wait for the mongos process to be ready -MAX_RETRIES=300 -retry_count=0 -set +e -while [ $retry_count -lt $MAX_RETRIES ]; do - result=$($CLUSTER_MONGO "db.adminCommand({ ping: 1 })" 2>/dev/null) - if [[ "$result" == *"ok"* ]]; then - echo "INFO: Mongos is ready." - break - fi - echo "INFO: Waiting for mongos to be ready... (attempt $((retry_count+1))/$MAX_RETRIES)" - retry_count=$((retry_count+1)) - sleep 2 -done -set -e - -if [ $retry_count -eq $MAX_RETRIES ]; then - echo "ERROR: Mongos failed to become ready after $MAX_RETRIES attempts." >&2 - exit 1 -fi - -check_shard_exists() { - # check if the shard exists in the config database - local shardsvr_name=$1 - local shard_exists - shard_exists=$($CLUSTER_MONGO "db.getSiblingDB(\"config\").shards.find({ _id: \"$shardsvr_name\" })") - if [ -n "$shard_exists" ]; then - return 0 # true - else - return 1 - fi -} - -# Check if sharding is ready -IFS="." read -r -a shardsvr_array <<< "$MONGODB_SHARD_REPLICA_SET_NAME_LIST" -shardsvr_count=${#shardsvr_array[@]} -for i in "${!shardsvr_array[@]}"; do - # Get the part before "@" in new_shardsvr_array - if [ $shardsvr_count -gt 1 ]; then - shard_name="$CLUSTER_NAME-${shardsvr_array[i]%%@*}" - else - shard_name="${shardsvr_array[i]%%,*}" - fi - retry_count=0 - while ! check_shard_exists "$shard_name"; do - echo "INFO: Shard $shard_name does not exist, retrying... (attempt $((retry_count+1))/$MAX_RETRIES)" - retry_count=$((retry_count+1)) - if [ $retry_count -ge $MAX_RETRIES ]; then - echo "ERROR: Shard $shard_name failed to become ready after $MAX_RETRIES attempts." >&2 - exit 1 - fi - sleep 2 - done -done -echo "INFO: Sharding is ready." diff --git a/addons/mongodb/dataprotection/shard-pbm-restore-prepare.sh b/addons/mongodb/dataprotection/shard-pbm-restore-prepare.sh deleted file mode 100644 index fc00f779d3..0000000000 --- a/addons/mongodb/dataprotection/shard-pbm-restore-prepare.sh +++ /dev/null @@ -1,80 +0,0 @@ -#!/bin/bash -set -e -set -o pipefail - -client_path=$(whereis mongosh | awk '{print $2}') -CLIENT="mongosh" -if [ -z "$client_path" ]; then - CLIENT="mongo" -fi -CLUSTER_MONGO="$CLIENT --host $MONGOS_INTERNAL_HOST --port $MONGOS_INTERNAL_PORT -u $MONGODB_USER -p $MONGODB_PASSWORD --quiet --eval" - -# Wait for the mongos process to be ready -MAX_RETRIES=300 -retry_count=0 -set +e -while [ $retry_count -lt $MAX_RETRIES ]; do - result=$($CLUSTER_MONGO "db.adminCommand({ ping: 1 })" 2>/dev/null) - if [[ "$result" == *"ok"* ]]; then - echo "INFO: Mongos is ready." - break - fi - echo "INFO: Waiting for mongos to be ready... (attempt $((retry_count+1))/$MAX_RETRIES)" - retry_count=$((retry_count+1)) - sleep 2 -done -set -e - -if [ $retry_count -eq $MAX_RETRIES ]; then - echo "ERROR: Mongos failed to become ready after $MAX_RETRIES attempts." >&2 - exit 1 -fi - -check_shard_exists() { - # check if the shard exists in the config database - local shardsvr_name=$1 - local shard_exists - shard_exists=$($CLUSTER_MONGO "db.getSiblingDB(\"config\").shards.find({ _id: \"$shardsvr_name\" })") - if [ -n "$shard_exists" ]; then - return 0 # true - else - return 1 - fi -} - -# Check if sharding is ready -IFS="." read -r -a shardsvr_array <<< "$MONGODB_SHARD_REPLICA_SET_NAME_LIST" -shardsvr_count=${#shardsvr_array[@]} -for i in "${!shardsvr_array[@]}"; do - # Get the part before "@" in new_shardsvr_array - if [ $shardsvr_count -gt 1 ]; then - shard_name="$CLUSTER_NAME-${shardsvr_array[i]%%@*}" - else - shard_name="${shardsvr_array[i]%%,*}" - fi - retry_count=0 - while ! check_shard_exists "$shard_name"; do - echo "INFO: Shard $shard_name does not exist, retrying... (attempt $((retry_count+1))/$MAX_RETRIES)" - retry_count=$((retry_count+1)) - if [ $retry_count -ge $MAX_RETRIES ]; then - echo "ERROR: Shard $shard_name failed to become ready after $MAX_RETRIES attempts." >&2 - exit 1 - fi - sleep 2 - done -done - -original_balance_status=$($CLUSTER_MONGO "sh.getBalancerState()") -if [ "$original_balance_status" = "true" ]; then - $CLUSTER_MONGO "sh.stopBalancer()" -fi -echo "INFO: Balancer is disabled." -# Starting in MongoDB 6.0.3, automatic chunk splitting is not performed. This is because of balancing policy improvements. -# Auto-splitting commands still exist, but do not perform an operation. -# For details, see Balancing Policy Changes: https://www.mongodb.com/docs/manual/release-notes/6.0/#balancing-policy-changes - -version=$($CLUSTER_MONGO "db.version()") -if [[ "$(echo -e "$version\n6.0.3" | sort -V | head -n1)" != "6.0.3" ]]; then - $CLUSTER_MONGO "sh.disableAutoSplit()" -fi -echo "INFO: AutoSplit is disabled." diff --git a/addons/mongodb/scripts-ut-spec/dataprotection_common_spec.sh b/addons/mongodb/scripts-ut-spec/dataprotection_common_spec.sh index 816545e6f8..cc5c8d6d14 100644 --- a/addons/mongodb/scripts-ut-spec/dataprotection_common_spec.sh +++ b/addons/mongodb/scripts-ut-spec/dataprotection_common_spec.sh @@ -1,6 +1,6 @@ # shellcheck shell=bash -Describe "MongoDB dataprotection common scripts" +Describe "MongoDB dataprotection storage config" setup_config_env() { export DATASAFED_CONFIG_FILE="./datasafed-test-${$}.conf" export PBM_CONFIG_FILE="./pbm-config-${$}.yaml" @@ -74,9 +74,8 @@ EOF The status should be success End - run_sync_pbm_storage_config_with_stale_force_path_style() { + run_write_pbm_storage_config() { source ../dataprotection/common-scripts.sh - export PBM_MONGODB_URI="mongodb://mongodb.example/admin" export S3_REGION="us-east-1" export S3_ENDPOINT="http://minio.example.com" export S3_BUCKET="mongodb-bucket" @@ -85,25 +84,69 @@ EOF export S3_SECRET_KEY="secret-key" export S3_FORCE_PATH_STYLE="true" - pbm() { - if [[ "$*" == *"-o json"* ]]; then - cat <<'EOF' -{"storage":{"s3":{"region":"us-east-1","endpointUrl":"http://minio.example.com","bucket":"mongodb-bucket","prefix":"mongodb-test/pbm","forcePathStyle":false}}} -EOF - else - cat > "$PBM_CONFIG_FILE" - fi - } - - sync_pbm_storage_config + write_pbm_storage_config_file "$PBM_CONFIG_FILE" cat "$PBM_CONFIG_FILE" } - It "rewrites PBM storage config when only forcePathStyle changed" - When call run_sync_pbm_storage_config_with_stale_force_path_style + It "writes forcePathStyle to the PBM storage config file" + When call run_write_pbm_storage_config - The output should include "INFO: Current PBM storage forcePathStyle: false" The output should include "forcePathStyle: true" The status should be success End End + +Describe "MongoDB dataprotection common script" + Include ../dataprotection/common-scripts.sh + + setup_polling() { + POLL_STATE_FILE="$(mktemp)" + echo 0 > "$POLL_STATE_FILE" + export SYNCER_PBM_WAIT_INTERVAL_SECONDS=0 + export SYNCER_RESTORE_WAIT_INTERVAL_SECONDS=0 + } + BeforeEach 'setup_polling' + + cleanup_polling() { + rm -f "$POLL_STATE_FILE" + } + AfterEach 'cleanup_polling' + + sleep() { :; } + + syncerctl_cmd() { + local count + count=$(cat "$POLL_STATE_FILE") + count=$((count + 1)) + echo "$count" > "$POLL_STATE_FILE" + + if [ "$1 $2" = "backup status" ]; then + if [ "$count" -lt 3 ]; then + echo '{"found":true,"status":"running"}' + else + echo '{"found":true,"status":"done"}' + fi + return + fi + + if [ "$count" -lt 3 ]; then + echo '{"status":"running","phase":"in-restore"}' + else + echo '{"status":"done","phase":"done"}' + fi + } + + It "waits for backup completion without a retry limit" + When call wait_for_syncer_backup_completion "backup-1" + The status should be success + The output should include "Backup backup-1 status: found=true status=done" + The contents of file "$POLL_STATE_FILE" should equal 3 + End + + It "waits for restore completion without a retry limit" + When call wait_for_syncer_restore_completion "request-1" + The status should be success + The output should include "Restore request request-1 phase=done" + The contents of file "$POLL_STATE_FILE" should equal 3 + End +End diff --git a/addons/mongodb/scripts-ut-spec/member_leave_spec.sh b/addons/mongodb/scripts-ut-spec/member_leave_spec.sh new file mode 100644 index 0000000000..cd7ea35cfd --- /dev/null +++ b/addons/mongodb/scripts-ut-spec/member_leave_spec.sh @@ -0,0 +1,62 @@ +# shellcheck shell=bash + +Describe "MongoDB member leave script" + setup() { + CALL_LOG="$(mktemp)" + export CALL_LOG + export KB_LEAVE_MEMBER_POD_NAME="mongodb-1" + export SYNCERCTL_BIN="syncerctl" + export PBM_LEAVE_RESULT="success" + + timeout() { + shift + "$@" + } + + syncerctl() { + local port="" + while [ "$#" -gt 0 ]; do + if [ "$1" = "--port" ]; then + port="$2" + break + fi + shift + done + echo "$port" >> "$CALL_LOG" + if [ "$port" = "3361" ] && [ "$PBM_LEAVE_RESULT" = "failure" ]; then + echo "leave member failed: PBM backup task is active" + return 1 + fi + echo "leave member success" + } + } + Before "setup" + + cleanup() { + rm -f "$CALL_LOG" + unset CALL_LOG KB_LEAVE_MEMBER_POD_NAME SYNCERCTL_BIN PBM_LEAVE_RESULT + unset -f timeout syncerctl + } + After "cleanup" + + It "checks and stops the PBM agent before removing the MongoDB member" + When run source ../scripts/mongodb-member-leave.sh + + The status should be success + The contents of file "$CALL_LOG" should equal "3361 +3601" + The output should include "calling pbm-agent memberLeave" + The output should include "calling mongodb memberLeave" + End + + It "does not remove the MongoDB member when the PBM guard fails" + PBM_LEAVE_RESULT="failure" + + When run source ../scripts/mongodb-member-leave.sh + + The status should be failure + The contents of file "$CALL_LOG" should equal "3361" + The output should include "PBM backup task is active" + The stderr should include "pbm-agent memberLeave command failed" + End +End diff --git a/addons/mongodb/scripts-ut-spec/replicaset_setup_spec.sh b/addons/mongodb/scripts-ut-spec/replicaset_setup_spec.sh index ff537a8734..6e1b53c0af 100644 --- a/addons/mongodb/scripts-ut-spec/replicaset_setup_spec.sh +++ b/addons/mongodb/scripts-ut-spec/replicaset_setup_spec.sh @@ -18,23 +18,12 @@ Describe "Mongodb Startup Script Tests" export MONGODB_ROOT=${DATA_VOLUME:-/data/mongodb} POD_NAME="cluster-mongodb-0" - # Create the directory for the dependency script the main script will 'source'. - MOCK_SCRIPTS_DIR="./mock_scripts" - mkdir -p "$MOCK_SCRIPTS_DIR" - # Define a mock 'process_restore_signal' function in our mock common.sh file. - cat > "$MOCK_SCRIPTS_DIR/mongodb-common.sh" <<'EOF' -process_restore_signal() { - echo "Mocked process_restore_signal called with: $2" -} -EOF - SCRIPTS_BASE_PATH="$MOCK_SCRIPTS_DIR" } BeforeAll "init" # Global cleanup. cleanup() { rm -rf "$DATA_VOLUME" - rm -rf "$MOCK_SCRIPTS_DIR" unset MONGODB_ROOT } AfterAll 'cleanup' @@ -142,46 +131,4 @@ EOF The status should be success End End - - # Test Case 3: Restore from PBM backup (mongodb_pbm.backup exists). - Describe "start replicaset with a PBM backup file for restore" - PBM_BACKUPFILE="$MONGODB_ROOT/tmp/mongodb_pbm.backup" - - # In this scenario, create the backup file and mock pbm-agent and mongod. - setup_restore_mocks() { - touch "$PBM_BACKUPFILE" - # Mock pbm-agent-entrypoint. - pbm-agent-entrypoint() { - # echo "Mocked pbm-agent-entrypoint started" - return 0 - } - # Mock mongod (this time it's not called via 'exec', but in the background with '&'). - mongod() { - # shellcheck disable=SC2145 - echo "Mocked mongod started with: $@" - } - } - Before 'setup_restore_mocks' - - # Clean up the backup file and mock functions. - cleanup_restore_mocks() { - rm -f "$PBM_BACKUPFILE" - unset -f pbm-agent-entrypoint - unset -f mongod - } - After 'cleanup_restore_mocks' - - It "should start pbm-agent, mongod, and call restore signals" - When run source ../scripts/replicaset-setup.tpl - - # Assert the output from all mock functions to confirm the correct execution flow. - The output should include "INFO: Startup backup agent for restore." - # The output should include "Mocked pbm-agent-entrypoint started" - The output should include "INFO: Start mongodb for restore." - The output should include "Mocked mongod started with: --bind_ip_all --port 27017 --replSet cluster-mongodb --config /etc/mongodb/mongodb.conf" - The output should include "Mocked process_restore_signal called with: start" - The output should include "Mocked process_restore_signal called with: end" - The status should be success - End - End -End \ No newline at end of file +End diff --git a/addons/mongodb/scripts/backup-agent-setup.sh b/addons/mongodb/scripts/backup-agent-setup.sh deleted file mode 100644 index 03ebc3bda4..0000000000 --- a/addons/mongodb/scripts/backup-agent-setup.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -# shellcheck disable=SC2086 - -export PATH=$PBM_DATA_MOUNT_POINT/tmp/bin:$PATH - -# shellcheck disable=SC1091 -. "/scripts/mongodb-common.sh" - -wait_restore_completion_by_cluster_cr - -exec pbm-agent-entrypoint diff --git a/addons/mongodb/scripts/mongodb-common.sh b/addons/mongodb/scripts/mongodb-common.sh index f9d4c6225d..16280775f5 100644 --- a/addons/mongodb/scripts/mongodb-common.sh +++ b/addons/mongodb/scripts/mongodb-common.sh @@ -1,155 +1,4 @@ #!/bin/bash -# shellcheck disable=SC2086 - -function wait_restore_completion_by_cluster_cr() { - local max_retries=$1 - local wait_interval=5 - local retries=0 - local state=0 - - while true; do - cluster_json=$(kubectl get clusters.apps.kubeblocks.io "${CLUSTER_NAME}" -n "${CLUSTER_NAMESPACE}" -o json 2>&1) - kubectl_get_exit_code=$? - if [ "$kubectl_get_exit_code" -ne 0 ]; then - echo "INFO: Cluster ${CLUSTER_NAME} not found, sleep $wait_interval second and retry..." - sleep $wait_interval - ((retries++)) - if [[ -n "$max_retries" && "$retries" -ge "$max_retries" ]]; then - echo "ERROR: Reached maximum retries ($max_retries) while waiting for cluster." - exit 1 - fi - continue - fi - - if ! is_restore_cluster "$cluster_json"; then - # echo "INFO: No restore spec, do not need to restore." - return 0 - fi - - restore_status=$(echo "$cluster_json" | jq -r '.status.conditions[]? | select(.type=="Restore") | .status' | head -n 1) - if [ "$restore_status" = "True" ]; then - echo "INFO: Restore completed." - return 0 - elif [ "$restore_status" = "False" ]; then - restore_message=$(echo "$cluster_json" | jq -r '.status.conditions[]? | select(.type=="Restore") | .message // empty' | head -n 1) - echo "ERROR: Restore failed. $restore_message" - exit 1 - else - if [[ "$state" != "1" ]]; then - echo "INFO: Waiting for restore completion..." - state=1 - fi - sleep $wait_interval - ((retries++)) - if [[ -n "$max_retries" && "$retries" -ge "$max_retries" ]]; then - echo "ERROR: Reached maximum retries ($max_retries) while waiting for restore completion." - exit 1 - fi - fi - done - return 0 -} - -function kill_process() { - local process_name="$1" - local process_pid=$(pgrep -x "$process_name") - if [ -z "$process_pid" ]; then - process_pid=$(pgrep -f "$process_name") - fi - if [ -n "$process_pid" ]; then - kill -9 $process_pid - echo "INFO: kill $process_name with pid $process_pid" - fi -} - -function is_restore_cluster() { - local cluster_json="$1" - local restore_source_name - restore_source_name=$(echo "$cluster_json" | jq -r '.spec.restore.source.name // empty') - [ -n "$restore_source_name" ] -} - -function process_restore_signal() { - local process="$1" - local target_signal="$2" - local pbm_backupfile=$MONGODB_ROOT/tmp/mongodb_pbm.backup - local last_annotation_value="" - local last_state="0" - restore_signal_cm_name="$CLUSTER_NAME-restore-signal" - restore_signal_cm_namespace="$CLUSTER_NAMESPACE" - while true; do - kubectl_get_result=$(kubectl get configmap $restore_signal_cm_name -n $restore_signal_cm_namespace -o json 2>&1) - kubectl_get_exit_code=$? - if [ "$kubectl_get_exit_code" -ne 0 ]; then - if [[ "$last_state" != "1" ]]; then - echo "INFO: Waiting for restore signal..." - last_state="1" - fi - else - last_state="0" - annotation_value=$(echo "$kubectl_get_result" | jq -r '.metadata.labels["apps.kubeblocks.io/restore-mongodb-shard"] // empty') - if [[ "$annotation_value" != "$last_annotation_value" ]]; then - echo "INFO: Restore signal is $annotation_value." - last_annotation_value="$annotation_value" - fi - if [[ "$annotation_value" == "start" ]]; then - if [[ "$target_signal" == "start" ]]; then - echo "INFO: Restore $annotation_value signal received, starting restore..." - break - fi - elif [[ "$annotation_value" == "end" ]]; then - echo "INFO: Restore completed, exiting." - if [[ "$process" == mongos* ]]; then - kill_process "mongos" - else - kill_process "pbm-agent-entrypoint" - kill_process "pbm-agent" - kill_process "mongod" - fi - wait - if [ -f "$pbm_backupfile" ]; then - echo "INFO: Removing backup file $pbm_backupfile" - rm "$pbm_backupfile" - fi - exec $process - exit 0 - else - echo "INFO: Restore signal is $annotation_value, bad signal, exiting." - exit 1 - fi - fi - sleep 1 - done -} - -function boot_or_enter_restore() { - local process="$1" - local wait_interval=5 - local max_retries=12 - local retry_count=0 - while [ $retry_count -lt $max_retries ]; do - cluster_json=$(kubectl get clusters.apps.kubeblocks.io ${CLUSTER_NAME} -n ${CLUSTER_NAMESPACE} -o json 2>&1) - kubectl_get_exit_code=$? - if [ "$kubectl_get_exit_code" -ne 0 ]; then - echo "INFO: Cluster ${CLUSTER_NAME} not found, sleep $wait_interval second and retry... ($((retry_count+1))/$max_retries)" - sleep $wait_interval - retry_count=$((retry_count+1)) - continue - fi - - if ! is_restore_cluster "$cluster_json"; then - # echo "INFO: No restore spec, do not need to restore." - exec $process - exit 0 - else - break - fi - done - if [ $retry_count -ge $max_retries ]; then - echo "ERROR: Cluster ${CLUSTER_NAME} not found after $max_retries retries, exiting." - exit 1 - fi -} generate_endpoints() { local fqdns=$1 diff --git a/addons/mongodb/scripts/mongodb-member-leave.sh b/addons/mongodb/scripts/mongodb-member-leave.sh index b742d7b784..53b5a04d09 100644 --- a/addons/mongodb/scripts/mongodb-member-leave.sh +++ b/addons/mongodb/scripts/mongodb-member-leave.sh @@ -1,8 +1,41 @@ #!/bin/bash +set -euo pipefail -if [[ "$(timeout 5s /tools/syncerctl getrole)" == "primary" ]]; then - echo "current member role is primary." - exit 1 +member_name="${KB_LEAVE_MEMBER_POD_NAME:-}" +if [ -z "$member_name" ]; then + echo "KB_LEAVE_MEMBER_POD_NAME is required" >&2 + exit 1 fi -/tools/syncerctl leave --instance "$KB_LEAVE_MEMBER_POD_NAME" \ No newline at end of file +syncerctl_bin="${SYNCERCTL_BIN:-/tools/syncerctl}" +main_port="${SYNCER_MAIN_SERVICE_PORT:-3601}" +pbm_agent_port="${PBM_AGENT_SYNCER_SERVICE_PORT:-3361}" +call_timeout="${SYNCER_MEMBER_LEAVE_CALL_TIMEOUT:-60s}" + +call_leave() { + local port="$1" + local target="$2" + local output + local exit_code + echo "calling ${target} memberLeave for ${member_name} on 127.0.0.1:${port}" + set +e + output=$(timeout "$call_timeout" "$syncerctl_bin" --host 127.0.0.1 --port "$port" leave --instance "$member_name" 2>&1) + exit_code=$? + set -e + echo "$output" + if [ "$exit_code" -ne 0 ]; then + echo "${target} memberLeave command failed with exit code ${exit_code}" >&2 + return "$exit_code" + fi + if echo "$output" | grep -q "leave member failed"; then + echo "${target} memberLeave failed" >&2 + return 1 + fi + if ! echo "$output" | grep -q "leave member success"; then + echo "${target} memberLeave returned unexpected output" >&2 + return 1 + fi +} + +call_leave "$pbm_agent_port" "pbm-agent" +call_leave "$main_port" "mongodb" diff --git a/addons/mongodb/scripts/mongodb-mongos-setup.sh b/addons/mongodb/scripts/mongodb-mongos-setup.sh index 068dd078b2..c5444df39c 100644 --- a/addons/mongodb/scripts/mongodb-mongos-setup.sh +++ b/addons/mongodb/scripts/mongodb-mongos-setup.sh @@ -10,11 +10,4 @@ export PATH=$MONGODB_ROOT/tmp/bin:$PATH cfg_server_endpoints="$(generate_endpoints "$CFG_SERVER_POD_FQDN_LIST" "$CFG_SERVER_INTERNAL_PORT")" process="mongos --bind_ip_all --port $MONGOS_PORT --configdb $CFG_SERVER_REPLICA_SET_NAME/$cfg_server_endpoints --config /etc/mongodb/mongos.conf" - -boot_or_enter_restore "$process" - -$process & - -process_restore_signal "$process" "start" - -process_restore_signal "$process" "end" \ No newline at end of file +exec $process diff --git a/addons/mongodb/scripts/mongodb-shard-setup.sh b/addons/mongodb/scripts/mongodb-shard-setup.sh index cf6dcfe627..9aec3defc2 100644 --- a/addons/mongodb/scripts/mongodb-shard-setup.sh +++ b/addons/mongodb/scripts/mongodb-shard-setup.sh @@ -8,17 +8,5 @@ mkdir -p $MONGODB_ROOT/logs mkdir -p $MONGODB_ROOT/tmp export PATH=$MONGODB_ROOT/tmp/bin:$PATH -. "/scripts/mongodb-common.sh" - process="mongod --bind_ip_all --port $PORT --replSet $CLUSTER_COMPONENT_NAME --config /etc/mongodb/mongodb.conf" -boot_or_enter_restore "$process" - -echo "INFO: Startup backup agent for restore." -pbm-agent-entrypoint >> $MONGODB_ROOT/tmp/pbm_agent_restore.log 2>&1 & - -echo "INFO: Start mongodb for restore." -$process & - -process_restore_signal "$process" "start" - -process_restore_signal "$process" "end" +exec $process diff --git a/addons/mongodb/scripts/replicaset-setup.tpl b/addons/mongodb/scripts/replicaset-setup.tpl index ad1d7c6416..f7ae2abcd5 100644 --- a/addons/mongodb/scripts/replicaset-setup.tpl +++ b/addons/mongodb/scripts/replicaset-setup.tpl @@ -8,10 +8,6 @@ mkdir -p $MONGODB_ROOT/logs mkdir -p $MONGODB_ROOT/tmp export PATH=$MONGODB_ROOT/tmp/bin:$PATH -# Allow the test framework to pass in a mock path to override the default /scripts. -SCRIPTS_BASE_PATH=${SCRIPTS_BASE_PATH:-/scripts} -. "$SCRIPTS_BASE_PATH/mongodb-common.sh" - # Restore from datafile BACKUPFILE=$MONGODB_ROOT/db/mongodb.backup PORT_FOR_RESTORE=27027 @@ -33,21 +29,5 @@ then rm $BACKUPFILE fi -# Restore from pbm -PBM_BACKUPFILE=$MONGODB_ROOT/tmp/mongodb_pbm.backup process="mongod --bind_ip_all --port $PORT --replSet $RPL_SET_NAME --config /etc/mongodb/mongodb.conf" -if [ ! -f $PBM_BACKUPFILE ] -then - exec $process - exit 0 -fi - -echo "INFO: Startup backup agent for restore." -pbm-agent-entrypoint >> $MONGODB_ROOT/tmp/pbm_agent_restore.log 2>&1 & - -echo "INFO: Start mongodb for restore." -$process & - -process_restore_signal "$process" "start" - -process_restore_signal "$process" "end" +exec $process diff --git a/addons/mongodb/templates/actionset-rs-pbm-physical.yaml b/addons/mongodb/templates/actionset-rs-pbm-physical.yaml index 9059fa9ec3..fd646c30b0 100644 --- a/addons/mongodb/templates/actionset-rs-pbm-physical.yaml +++ b/addons/mongodb/templates/actionset-rs-pbm-physical.yaml @@ -7,8 +7,6 @@ metadata: {{- include "mongodb.labels" . | nindent 4 }} spec: env: - - name: DATA_DIR - value: {{ .Values.dataMountPath }}/db - name: MOUNT_DIR value: {{ .Values.dataMountPath }} - name: PBM_BACKUP_DIR_NAME @@ -21,8 +19,6 @@ spec: value: "4" - name: PBM_IMAGE_TAG value: {{ .Values.image.percona.backup.tag }} - - name: PSM_IMAGE_TAG - value: {{ .Values.image.tag }} backupType: Full backup: preBackup: [] @@ -38,7 +34,7 @@ spec: - -c - | {{- .Files.Get "dataprotection/common-scripts.sh" | nindent 10 }} - {{- .Files.Get "dataprotection/rs-pbm-full-backup.sh" | nindent 10 }} + {{- .Files.Get "dataprotection/pbm-full-backup.sh" | nindent 10 }} preDelete: image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.percona.backup.repository }}:$(PBM_IMAGE_TAG) command: @@ -47,13 +43,6 @@ spec: - | {{- .Files.Get "dataprotection/pbm-backup-delete.sh" | nindent 10 }} restore: - prepareData: - image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.percona.backup.repository }}:$(PBM_IMAGE_TAG) - command: - - bash - - -c - - | - {{- .Files.Get "dataprotection/rs-pbm-restore-prepare.sh" | nindent 8 }} postReady: - job: image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.percona.backup.repository }}:$(PBM_IMAGE_TAG) @@ -63,4 +52,4 @@ spec: - -c - | {{- .Files.Get "dataprotection/common-scripts.sh" | nindent 12 }} - {{- .Files.Get "dataprotection/rs-pbm-full-restore.sh" | nindent 12 }} \ No newline at end of file + {{- .Files.Get "dataprotection/pbm-full-restore.sh" | nindent 12 }} \ No newline at end of file diff --git a/addons/mongodb/templates/actionset-rs-pbm-pitr.yaml b/addons/mongodb/templates/actionset-rs-pbm-pitr.yaml index dd24322616..af1227feb4 100644 --- a/addons/mongodb/templates/actionset-rs-pbm-pitr.yaml +++ b/addons/mongodb/templates/actionset-rs-pbm-pitr.yaml @@ -10,8 +10,6 @@ metadata: dataprotection.kubeblocks.io/skip-base-backup-restore-in-pitr: "true" spec: env: - - name: DATA_DIR - value: {{ .Values.dataMountPath }}/db - name: MOUNT_DIR value: {{ .Values.dataMountPath }} - name: PBM_BACKUP_DIR_NAME @@ -30,10 +28,6 @@ spec: value: "false" - name: PBM_IMAGE_TAG value: {{ .Values.image.percona.backup.tag }} - - name: PSM_IMAGE_TAG - value: {{ .Values.image.tag }} - - name: PBM_DISABLE_PITR_WHEN_EXIT - value: "false" backupType: Continuous backup: preBackup: [] @@ -49,7 +43,7 @@ spec: - -c - | {{- .Files.Get "dataprotection/common-scripts.sh" | nindent 10 }} - {{- .Files.Get "dataprotection/rs-pbm-pitr-backup.sh" | nindent 10 }} + {{- .Files.Get "dataprotection/pbm-pitr-backup.sh" | nindent 10 }} preDelete: image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.percona.backup.repository }}:$(PBM_IMAGE_TAG) command: @@ -59,13 +53,6 @@ spec: {{- .Files.Get "dataprotection/pbm-backup-delete.sh" | nindent 10 }} restore: - prepareData: - image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.percona.backup.repository }}:$(PBM_IMAGE_TAG) - command: - - bash - - -c - - | - {{- .Files.Get "dataprotection/rs-pbm-restore-prepare.sh" | nindent 8 }} postReady: - job: image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.percona.backup.repository }}:$(PBM_IMAGE_TAG) @@ -75,4 +62,4 @@ spec: - -c - | {{- .Files.Get "dataprotection/common-scripts.sh" | nindent 12 }} - {{- .Files.Get "dataprotection/rs-pbm-pitr-restore.sh" | nindent 12 }} \ No newline at end of file + {{- .Files.Get "dataprotection/pbm-pitr-restore.sh" | nindent 12 }} \ No newline at end of file diff --git a/addons/mongodb/templates/actionset-shard-pbm-logical.yaml b/addons/mongodb/templates/actionset-shard-pbm-logical.yaml index 832b32b733..9be3f0fb42 100644 --- a/addons/mongodb/templates/actionset-shard-pbm-logical.yaml +++ b/addons/mongodb/templates/actionset-shard-pbm-logical.yaml @@ -7,8 +7,6 @@ metadata: {{- include "mongodb.labels" . | nindent 4 }} spec: env: - - name: DATA_DIR - value: {{ .Values.dataMountPath }}/db - name: MOUNT_DIR value: {{ .Values.dataMountPath }} - name: PBM_BACKUP_DIR_NAME @@ -21,19 +19,9 @@ spec: value: "4" - name: PBM_IMAGE_TAG value: {{ .Values.image.percona.backup.tag }} - - name: PSM_IMAGE_TAG - value: {{ .Values.image.tag }} backupType: Full backup: - preBackup: - - job: - image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:$(PSM_IMAGE_TAG) - runOnTargetPodNode: false - command: - - bash - - -c - - | - {{- .Files.Get "dataprotection/shard-pbm-pre-backup.sh" | nindent 12 }} + preBackup: [] postBackup: [] backupData: image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.percona.backup.repository }}:$(PBM_IMAGE_TAG) @@ -46,7 +34,7 @@ spec: - -c - | {{- .Files.Get "dataprotection/common-scripts.sh" | nindent 10 }} - {{- .Files.Get "dataprotection/shard-pbm-full-backup.sh" | nindent 10 }} + {{- .Files.Get "dataprotection/pbm-full-backup.sh" | nindent 10 }} preDelete: image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.percona.backup.repository }}:$(PBM_IMAGE_TAG) command: @@ -57,14 +45,6 @@ spec: restore: postReady: - - job: - image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:$(PSM_IMAGE_TAG) - runOnTargetPodNode: false - command: - - bash - - -c - - | - {{- .Files.Get "dataprotection/shard-pbm-restore-prepare.sh" | nindent 12 }} - job: image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.percona.backup.repository }}:$(PBM_IMAGE_TAG) runOnTargetPodNode: true @@ -73,4 +53,4 @@ spec: - -c - | {{- .Files.Get "dataprotection/common-scripts.sh" | nindent 12 }} - {{- .Files.Get "dataprotection/shard-pbm-full-restore.sh" | nindent 12 }} \ No newline at end of file + {{- .Files.Get "dataprotection/pbm-full-restore.sh" | nindent 12 }} \ No newline at end of file diff --git a/addons/mongodb/templates/actionset-shard-pbm-physical.yaml b/addons/mongodb/templates/actionset-shard-pbm-physical.yaml index bf86232f54..176d4b1fd5 100644 --- a/addons/mongodb/templates/actionset-shard-pbm-physical.yaml +++ b/addons/mongodb/templates/actionset-shard-pbm-physical.yaml @@ -7,8 +7,6 @@ metadata: {{- include "mongodb.labels" . | nindent 4 }} spec: env: - - name: DATA_DIR - value: {{ .Values.dataMountPath }}/db - name: MOUNT_DIR value: {{ .Values.dataMountPath }} - name: PBM_BACKUP_DIR_NAME @@ -21,19 +19,9 @@ spec: value: "4" - name: PBM_IMAGE_TAG value: {{ .Values.image.percona.backup.tag }} - - name: PSM_IMAGE_TAG - value: {{ .Values.image.tag }} backupType: Full backup: - preBackup: - - job: - image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:$(PSM_IMAGE_TAG) - runOnTargetPodNode: false - command: - - bash - - -c - - | - {{- .Files.Get "dataprotection/shard-pbm-pre-backup.sh" | nindent 12 }} + preBackup: [] postBackup: [] backupData: image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.percona.backup.repository }}:$(PBM_IMAGE_TAG) @@ -46,7 +34,7 @@ spec: - -c - | {{- .Files.Get "dataprotection/common-scripts.sh" | nindent 10 }} - {{- .Files.Get "dataprotection/shard-pbm-full-backup.sh" | nindent 10 }} + {{- .Files.Get "dataprotection/pbm-full-backup.sh" | nindent 10 }} preDelete: image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.percona.backup.repository }}:$(PBM_IMAGE_TAG) command: @@ -56,14 +44,6 @@ spec: {{- .Files.Get "dataprotection/pbm-backup-delete.sh" | nindent 10 }} restore: postReady: - - job: - image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:$(PSM_IMAGE_TAG) - runOnTargetPodNode: false - command: - - bash - - -c - - | - {{- .Files.Get "dataprotection/shard-pbm-restore-prepare.sh" | nindent 12 }} - job: image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.percona.backup.repository }}:$(PBM_IMAGE_TAG) runOnTargetPodNode: true @@ -72,4 +52,4 @@ spec: - -c - | {{- .Files.Get "dataprotection/common-scripts.sh" | nindent 12 }} - {{- .Files.Get "dataprotection/shard-pbm-full-restore.sh" | nindent 12 }} \ No newline at end of file + {{- .Files.Get "dataprotection/pbm-full-restore.sh" | nindent 12 }} diff --git a/addons/mongodb/templates/actionset-shard-pbm-pitr.yaml b/addons/mongodb/templates/actionset-shard-pbm-pitr.yaml index d3e65ddf3b..fda8aaa0bf 100644 --- a/addons/mongodb/templates/actionset-shard-pbm-pitr.yaml +++ b/addons/mongodb/templates/actionset-shard-pbm-pitr.yaml @@ -10,8 +10,6 @@ metadata: dataprotection.kubeblocks.io/skip-base-backup-restore-in-pitr: "true" spec: env: - - name: DATA_DIR - value: {{ .Values.dataMountPath }}/db - name: MOUNT_DIR value: {{ .Values.dataMountPath }} - name: PBM_BACKUP_DIR_NAME @@ -30,21 +28,9 @@ spec: value: "false" - name: PBM_IMAGE_TAG value: {{ .Values.image.percona.backup.tag }} - - name: PSM_IMAGE_TAG - value: {{ .Values.image.tag }} - - name: PBM_DISABLE_PITR_WHEN_EXIT - value: "false" backupType: Continuous backup: - preBackup: - - job: - image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:$(PSM_IMAGE_TAG) - runOnTargetPodNode: false - command: - - bash - - -c - - | - {{- .Files.Get "dataprotection/shard-pbm-pre-backup.sh" | nindent 12 }} + preBackup: [] postBackup: [] backupData: image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.percona.backup.repository }}:$(PBM_IMAGE_TAG) @@ -57,7 +43,7 @@ spec: - -c - | {{- .Files.Get "dataprotection/common-scripts.sh" | nindent 10 }} - {{- .Files.Get "dataprotection/shard-pbm-pitr-backup.sh" | nindent 10 }} + {{- .Files.Get "dataprotection/pbm-pitr-backup.sh" | nindent 10 }} preDelete: image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.percona.backup.repository }}:$(PBM_IMAGE_TAG) command: @@ -68,14 +54,6 @@ spec: restore: postReady: - - job: - image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:$(PSM_IMAGE_TAG) - runOnTargetPodNode: false - command: - - bash - - -c - - | - {{- .Files.Get "dataprotection/shard-pbm-restore-prepare.sh" | nindent 12 }} - job: image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.percona.backup.repository }}:$(PBM_IMAGE_TAG) runOnTargetPodNode: true @@ -84,4 +62,4 @@ spec: - -c - | {{- .Files.Get "dataprotection/common-scripts.sh" | nindent 12 }} - {{- .Files.Get "dataprotection/shard-pbm-pitr-restore.sh" | nindent 12 }} \ No newline at end of file + {{- .Files.Get "dataprotection/pbm-pitr-restore.sh" | nindent 12 }} diff --git a/addons/mongodb/templates/backuppolicytemplate-shard.yaml b/addons/mongodb/templates/backuppolicytemplate-shard.yaml index 3624d7d09f..d8f49b7051 100644 --- a/addons/mongodb/templates/backuppolicytemplate-shard.yaml +++ b/addons/mongodb/templates/backuppolicytemplate-shard.yaml @@ -13,6 +13,9 @@ spec: account: root backupMethods: - name: dump + target: + role: primary + account: root snapshotVolumes: false actionSetName: mongodb-shard-pbm-logical env: @@ -25,28 +28,14 @@ spec: mappedValue: "2.10.0" - serviceVersions: ["5.0", "4.4", "4.2", "4.0"] mappedValue: "2.5.0-multi" - - name: PSM_IMAGE_TAG - valueFrom: - versionMapping: - - serviceVersions: ["8.0"] - mappedValue: "8.0.17" - - serviceVersions: ["7.0"] - mappedValue: "7.0.28" - - serviceVersions: ["6.0"] - mappedValue: "6.0.27" - - serviceVersions: ["5.0"] - mappedValue: "5.0.29-multi" - - serviceVersions: ["4.4"] - mappedValue: "4.4.29-multi" - - serviceVersions: ["4.2"] - mappedValue: "4.2.25" - - serviceVersions: ["4.0"] - mappedValue: "4.0.28" targetVolumes: volumeMounts: - name: data mountPath: {{ .Values.dataMountPath }} - name: pbm-physical + target: + role: primary + account: root snapshotVolumes: false actionSetName: mongodb-shard-pbm-physical env: @@ -59,28 +48,14 @@ spec: mappedValue: "2.10.0" - serviceVersions: ["5.0", "4.4", "4.2", "4.0"] mappedValue: "2.5.0-multi" - - name: PSM_IMAGE_TAG - valueFrom: - versionMapping: - - serviceVersions: ["8.0"] - mappedValue: "8.0.17" - - serviceVersions: ["7.0"] - mappedValue: "7.0.28" - - serviceVersions: ["6.0"] - mappedValue: "6.0.27" - - serviceVersions: ["5.0"] - mappedValue: "5.0.29-multi" - - serviceVersions: ["4.4"] - mappedValue: "4.4.29-multi" - - serviceVersions: ["4.2"] - mappedValue: "4.2.25" - - serviceVersions: ["4.0"] - mappedValue: "4.0.28" targetVolumes: volumeMounts: - name: data mountPath: {{ .Values.dataMountPath }} - name: pbm-pitr + target: + role: primary + account: root snapshotVolumes: false actionSetName: mongodb-shard-pbm-pitr env: @@ -93,23 +68,6 @@ spec: mappedValue: "2.10.0" - serviceVersions: ["5.0", "4.4", "4.2", "4.0"] mappedValue: "2.5.0-multi" - - name: PSM_IMAGE_TAG - valueFrom: - versionMapping: - - serviceVersions: ["8.0"] - mappedValue: "8.0.17" - - serviceVersions: ["7.0"] - mappedValue: "7.0.28" - - serviceVersions: ["6.0"] - mappedValue: "6.0.27" - - serviceVersions: ["5.0"] - mappedValue: "5.0.29-multi" - - serviceVersions: ["4.4"] - mappedValue: "4.4.29-multi" - - serviceVersions: ["4.2"] - mappedValue: "4.2.25" - - serviceVersions: ["4.0"] - mappedValue: "4.0.28" targetVolumes: volumeMounts: - name: data @@ -139,4 +97,4 @@ spec: - backupMethod: archive-oplog enabled: false cronExpression: "*/5 * * * *" - retentionPeriod: 8d \ No newline at end of file + retentionPeriod: 8d diff --git a/addons/mongodb/templates/backuppolicytemplate.yaml b/addons/mongodb/templates/backuppolicytemplate.yaml index 64a0801d48..56f65108da 100644 --- a/addons/mongodb/templates/backuppolicytemplate.yaml +++ b/addons/mongodb/templates/backuppolicytemplate.yaml @@ -57,6 +57,9 @@ spec: snapshotVolumes: false actionSetName: mongodb-pitr - name: pbm-physical + target: + role: primary + account: root snapshotVolumes: false actionSetName: mongodb-rs-pbm-physical env: @@ -74,6 +77,9 @@ spec: - name: data mountPath: {{ .Values.dataMountPath }} - name: pbm-pitr + target: + role: primary + account: root snapshotVolumes: false actionSetName: mongodb-rs-pbm-pitr env: @@ -114,4 +120,4 @@ spec: - backupMethod: pbm-pitr enabled: false cronExpression: "*/5 * * * *" - retentionPeriod: 8d \ No newline at end of file + retentionPeriod: 8d diff --git a/addons/mongodb/templates/cmpd-config-server.yaml b/addons/mongodb/templates/cmpd-config-server.yaml index a0dfeabb1d..287dcac5b1 100644 --- a/addons/mongodb/templates/cmpd-config-server.yaml +++ b/addons/mongodb/templates/cmpd-config-server.yaml @@ -65,6 +65,7 @@ spec: - /bin/sh - -c - /scripts/mongodb-member-leave.sh > /tmp/member-leave.log 2>&1 + timeoutSeconds: -1 switchover: exec: container: mongodb @@ -77,28 +78,19 @@ spec: # percona-server-mongodb needs run as root to have privilege to access to keyfile runAsUser: 0 initContainers: - - command: - - cp - - -r - - /bin/syncer - - /bin/syncerctl - - /tools/ - image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.syncer.repository }}:{{ .Values.image.syncer.tag }} - imagePullPolicy: {{ default "IfNotPresent" .Values.image.pullPolicy }} - name: init-syncer - volumeMounts: - - mountPath: /tools - name: tools - command: - sh - -c - | mkdir -p {{ .Values.dataMountPath }}/tmp/bin - cp -r /opt/bitnami/kubectl/bin/kubectl {{ .Values.dataMountPath }}/tmp/bin - image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.kubectl.repository }}:{{ .Values.image.kubectl.tag }} + cp -r /bin/syncer /bin/syncerctl /tools/ + cp -r /bin/syncerctl {{ .Values.dataMountPath }}/tmp/bin + image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.syncer.repository }}:{{ .Values.image.syncer.tag }} imagePullPolicy: {{ default "IfNotPresent" .Values.image.pullPolicy }} - name: init-kubectl + name: init-syncer volumeMounts: + - mountPath: /tools + name: tools - mountPath: {{ .Values.dataMountPath }} name: data - command: @@ -107,7 +99,6 @@ spec: - | cp -r /usr/bin/pbm /tools cp -r /usr/bin/pbm-agent /tools - cp -r /usr/bin/pbm-agent-entrypoint /tools image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.percona.backup.repository }}:{{ .Values.image.percona.backup.tag }} imagePullPolicy: {{ default "IfNotPresent" .Values.image.pullPolicy }} name: init-pbm-agent @@ -154,6 +145,14 @@ spec: value: /tools/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin - name: KB_SERVICE_CHARACTER_TYPE value: mongodb + - name: SYNCER_BACKUP_ENABLED + value: "true" + - name: PBM_BIN + value: /tools/pbm + - name: PBM_AGENT_BIN + value: /tools/pbm-agent + - name: PBM_DATA_MOUNT_POINT + value: {{ .Values.dataMountPath }} - name: SERVICE_PORT value: $(KB_SERVICE_PORT) - name: MONGODB_ROOT_USER @@ -162,14 +161,6 @@ spec: value: $(MONGODB_PASSWORD) - name: MONGODB_GRANT_ANYACTION_PRIVILEGE value: "true" - - name: PBM_MONGODB_REPLICA_SET - value: $(CLUSTER_COMPONENT_NAME) - - name: PBM_AGENT_SIDECAR - value: "true" - - name: PBM_AGENT_SIDECAR_SLEEP - value: "5" - - name: SHARDED - value: "TRUE" - name: PBM_AGENT_MONGODB_USERNAME value: $(MONGODB_USER) - name: PBM_AGENT_MONGODB_PASSWORD @@ -195,34 +186,51 @@ spec: - name: mongodb-backup-agent image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.percona.backup.repository }}:{{ .Values.image.percona.backup.tag }} imagePullPolicy: {{ default "IfNotPresent" .Values.image.pullPolicy }} + ports: + - name: pbm-agent-ha + protocol: TCP + containerPort: 3361 command: - - /bin/bash - - -c - - /scripts/backup-agent-setup.sh + - /tools/syncer + - -- + - /tools/pbm-agent env: + - name: POD_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.name + - name: POD_NAMESPACE + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.namespace + - name: POD_IP + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: status.podIP - name: PATH value: /tools/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin - - name: PBM_MONGODB_REPLICA_SET - value: $(CLUSTER_COMPONENT_NAME) - - name: PBM_AGENT_SIDECAR + - name: KB_SERVICE_CHARACTER_TYPE + value: mongodb + - name: KB_WORKLOAD_TYPE + value: pbm-agent + - name: SYNCER_IGNORE_HA value: "true" - - name: PBM_AGENT_SIDECAR_SLEEP - value: "5" - - name: SHARDED - value: "TRUE" + - name: SYNCER_BACKUP_ENABLED + value: "true" + - name: SYNCER_SERVICE_PORT + value: "3361" - name: PBM_AGENT_MONGODB_USERNAME value: $(MONGODB_USER) - name: PBM_AGENT_MONGODB_PASSWORD value: $(MONGODB_PASSWORD) - name: PBM_MONGODB_URI value: mongodb://$(PBM_AGENT_MONGODB_USERNAME):$(PBM_AGENT_MONGODB_PASSWORD)@localhost:$(KB_SERVICE_PORT)/?authSource=admin - - name: PBM_DATA_MOUNT_POINT - value: {{ .Values.dataMountPath }} volumeMounts: - mountPath: {{ .Values.dataMountPath }} name: data - - name: scripts - mountPath: /scripts - mountPath: /tools name: tools - name: exporter diff --git a/addons/mongodb/templates/cmpd-mongodb-shard.yaml b/addons/mongodb/templates/cmpd-mongodb-shard.yaml index 49c149bc61..e232d4f278 100644 --- a/addons/mongodb/templates/cmpd-mongodb-shard.yaml +++ b/addons/mongodb/templates/cmpd-mongodb-shard.yaml @@ -89,6 +89,7 @@ spec: - /bin/sh - -c - /scripts/mongodb-member-leave.sh > /tmp/member-leave.log 2>&1 + timeoutSeconds: -1 switchover: exec: container: mongodb @@ -106,6 +107,7 @@ spec: targetPodSelector: Role matchingKey: primary preCondition: RuntimeReady + timeoutSeconds: -1 retryPolicy: maxRetries: 10 runtime: @@ -113,28 +115,19 @@ spec: # percona-server-mongodb needs run as root to have privilege to access to keyfile runAsUser: 0 initContainers: - - command: - - cp - - -r - - /bin/syncer - - /bin/syncerctl - - /tools/ - image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.syncer.repository }}:{{ .Values.image.syncer.tag }} - imagePullPolicy: {{ default "IfNotPresent" .Values.image.pullPolicy }} - name: init-syncer - volumeMounts: - - mountPath: /tools - name: tools - command: - sh - -c - | mkdir -p {{ .Values.dataMountPath }}/tmp/bin - cp -r /opt/bitnami/kubectl/bin/kubectl {{ .Values.dataMountPath }}/tmp/bin - image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.kubectl.repository }}:{{ .Values.image.kubectl.tag }} + cp -r /bin/syncer /bin/syncerctl /tools/ + cp -r /bin/syncerctl {{ .Values.dataMountPath }}/tmp/bin + image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.syncer.repository }}:{{ .Values.image.syncer.tag }} imagePullPolicy: {{ default "IfNotPresent" .Values.image.pullPolicy }} - name: init-kubectl + name: init-syncer volumeMounts: + - mountPath: /tools + name: tools - mountPath: {{ .Values.dataMountPath }} name: data - command: @@ -143,7 +136,6 @@ spec: - | cp -r /usr/bin/pbm /tools cp -r /usr/bin/pbm-agent /tools - cp -r /usr/bin/pbm-agent-entrypoint /tools image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.percona.backup.repository }}:{{ .Values.image.percona.backup.tag }} imagePullPolicy: {{ default "IfNotPresent" .Values.image.pullPolicy }} name: init-pbm-agent @@ -190,6 +182,14 @@ spec: value: /tools/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin - name: KB_SERVICE_CHARACTER_TYPE value: mongodb + - name: SYNCER_BACKUP_ENABLED + value: "true" + - name: PBM_BIN + value: /tools/pbm + - name: PBM_AGENT_BIN + value: /tools/pbm-agent + - name: PBM_DATA_MOUNT_POINT + value: {{ .Values.dataMountPath }} - name: SERVICE_PORT value: $(KB_SERVICE_PORT) - name: MONGODB_ROOT_USER @@ -202,14 +202,6 @@ spec: value: $(MONGODB_ADMIN_USER) - name: PBM_AGENT_MONGODB_PASSWORD value: $(MONGODB_ADMIN_PASSWORD) - - name: PBM_MONGODB_REPLICA_SET - value: $(CLUSTER_COMPONENT_NAME) - - name: PBM_AGENT_SIDECAR - value: "true" - - name: PBM_AGENT_SIDECAR_SLEEP - value: "5" - - name: SHARDED - value: "TRUE" - name: PBM_MONGODB_URI value: mongodb://$(PBM_AGENT_MONGODB_USERNAME):$(PBM_AGENT_MONGODB_PASSWORD)@localhost:$(KB_SERVICE_PORT)/?authSource=admin # syncer uses the env to wait dns ready @@ -231,34 +223,51 @@ spec: - name: mongodb-backup-agent image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.percona.backup.repository }}:{{ .Values.image.percona.backup.tag }} imagePullPolicy: {{ default "IfNotPresent" .Values.image.pullPolicy }} + ports: + - name: pbm-agent-ha + protocol: TCP + containerPort: 3361 command: - - /bin/bash - - -c - - /scripts/backup-agent-setup.sh + - /tools/syncer + - -- + - /tools/pbm-agent env: + - name: POD_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.name + - name: POD_NAMESPACE + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.namespace + - name: POD_IP + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: status.podIP - name: PATH value: /tools/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + - name: KB_SERVICE_CHARACTER_TYPE + value: mongodb + - name: KB_WORKLOAD_TYPE + value: pbm-agent + - name: SYNCER_IGNORE_HA + value: "true" + - name: SYNCER_BACKUP_ENABLED + value: "true" + - name: SYNCER_SERVICE_PORT + value: "3361" - name: PBM_AGENT_MONGODB_USERNAME value: $(MONGODB_ADMIN_USER) - name: PBM_AGENT_MONGODB_PASSWORD value: $(MONGODB_ADMIN_PASSWORD) - - name: PBM_MONGODB_REPLICA_SET - value: $(CLUSTER_COMPONENT_NAME) - - name: PBM_AGENT_SIDECAR - value: "true" - - name: PBM_AGENT_SIDECAR_SLEEP - value: "5" - - name: SHARDED - value: "TRUE" - name: PBM_MONGODB_URI value: mongodb://$(PBM_AGENT_MONGODB_USERNAME):$(PBM_AGENT_MONGODB_PASSWORD)@localhost:$(KB_SERVICE_PORT)/?authSource=admin - - name: PBM_DATA_MOUNT_POINT - value: {{ .Values.dataMountPath }} volumeMounts: - mountPath: {{ .Values.dataMountPath }} name: data - - name: scripts - mountPath: /scripts - mountPath: /tools name: tools - name: exporter diff --git a/addons/mongodb/templates/cmpd-mongos.yaml b/addons/mongodb/templates/cmpd-mongos.yaml index 6daa9a4dea..e631fef6e4 100644 --- a/addons/mongodb/templates/cmpd-mongos.yaml +++ b/addons/mongodb/templates/cmpd-mongos.yaml @@ -58,14 +58,13 @@ spec: - sh - -c - | - mkdir -p {{ .Values.dataMountPath }}/tmp/bin - cp -r /opt/bitnami/kubectl/bin/kubectl {{ .Values.dataMountPath }}/tmp/bin - image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.kubectl.repository }}:{{ .Values.image.kubectl.tag }} + cp -r /bin/syncer /bin/syncerctl /kubeblocks/ + image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.syncer.repository }}:{{ .Values.image.syncer.tag }} imagePullPolicy: {{ default "IfNotPresent" .Values.image.pullPolicy }} - name: init-kubectl + name: init-syncer volumeMounts: - - mountPath: {{ .Values.dataMountPath }} - name: data + - mountPath: /kubeblocks + name: kubeblocks containers: - name: mongos image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:{{ .Values.image.tag }} @@ -74,9 +73,12 @@ spec: - name: mongos protocol: TCP containerPort: 27017 + - name: ha + protocol: TCP + containerPort: 3601 command: - - bash - - -c + - /kubeblocks/syncer + - -- - /scripts/mongodb-mongos-setup.sh env: - name: POD_NAME @@ -101,6 +103,14 @@ spec: fieldPath: status.podIP - name: PATH value: /kubeblocks/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + - name: KB_SERVICE_CHARACTER_TYPE + value: mongodb + - name: KB_WORKLOAD_TYPE + value: mongos + - name: SYNCER_IGNORE_HA + value: "true" + - name: SYNCER_BACKUP_ENABLED + value: "true" - name: SERVICE_PORT value: $(KB_SERVICE_PORT) - name: MONGODB_ROOT_USER @@ -130,7 +140,7 @@ spec: - -c - | client=$(mongosh --version 1>/dev/null&&echo mongosh||echo mongo) - $client --port $SERVICE_PORT -u $MONGOS_USER -p $MONGOS_PASSWORD --authenticationDatabase admin --eval "db.adminCommand('ping')" + exec timeout -k 1s 3s "$client" --quiet --port "$SERVICE_PORT" -u "$MONGOS_USER" -p "$MONGOS_PASSWORD" --authenticationDatabase admin --eval "db.adminCommand('ping')" - name: exporter imagePullPolicy: {{ default "IfNotPresent" .Values.image.pullPolicy }} command: @@ -192,6 +202,15 @@ spec: componentName: Required - name: KB_SERVICE_PORT value: "27017" + - name: SYNCER_SERVICE_PORT + valueFrom: + hostNetworkVarRef: + optional: true + container: + name: mongos + port: + name: ha + option: Optional - name: CFG_SERVER_REPLICA_SET_NAME valueFrom: componentVarRef: @@ -234,3 +253,4 @@ spec: - container: mongos ports: - mongos + - ha diff --git a/addons/mongodb/templates/cmpd.yaml b/addons/mongodb/templates/cmpd.yaml index 32f5981302..84989c0774 100644 --- a/addons/mongodb/templates/cmpd.yaml +++ b/addons/mongodb/templates/cmpd.yaml @@ -88,6 +88,7 @@ spec: - /bin/sh - -c - /scripts/mongodb-member-leave.sh > /tmp/member-leave.log 2>&1 + timeoutSeconds: -1 switchover: exec: container: mongodb @@ -100,27 +101,18 @@ spec: # percona-server-mongodb needs run as root to have privilege to access to keyfile runAsUser: 0 initContainers: - - command: - - cp - - -r - - /bin/syncer - - /bin/syncerctl - - /tools/ - imagePullPolicy: {{ default "IfNotPresent" .Values.image.pullPolicy }} - name: init-syncer - volumeMounts: - - mountPath: /tools - name: tools - command: - sh - -c - | mkdir -p {{ .Values.dataMountPath }}/tmp/bin - cp -r /opt/bitnami/kubectl/bin/kubectl {{ .Values.dataMountPath }}/tmp/bin - image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.kubectl.repository }}:{{ .Values.image.kubectl.tag }} + cp -r /bin/syncer /bin/syncerctl /tools/ + cp -r /bin/syncerctl {{ .Values.dataMountPath }}/tmp/bin imagePullPolicy: {{ default "IfNotPresent" .Values.image.pullPolicy }} - name: init-kubectl + name: init-syncer volumeMounts: + - mountPath: /tools + name: tools - mountPath: {{ .Values.dataMountPath }} name: data - command: @@ -129,7 +121,6 @@ spec: - | cp -r /usr/bin/pbm /tools cp -r /usr/bin/pbm-agent /tools - cp -r /usr/bin/pbm-agent-entrypoint /tools image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.percona.backup.repository }}:{{ .Values.image.percona.backup.tag }} imagePullPolicy: {{ default "IfNotPresent" .Values.image.pullPolicy }} name: init-pbm-agent @@ -175,6 +166,14 @@ spec: value: /tools/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin - name: KB_SERVICE_CHARACTER_TYPE value: mongodb + - name: SYNCER_BACKUP_ENABLED + value: "true" + - name: PBM_BIN + value: /tools/pbm + - name: PBM_AGENT_BIN + value: /tools/pbm-agent + - name: PBM_DATA_MOUNT_POINT + value: {{ .Values.dataMountPath }} - name: SERVICE_PORT value: $(KB_SERVICE_PORT) - name: MONGODB_ROOT_USER @@ -187,12 +186,6 @@ spec: value: $(MONGODB_USER) - name: PBM_AGENT_MONGODB_PASSWORD value: $(MONGODB_PASSWORD) - - name: PBM_MONGODB_REPLICA_SET - value: $(KB_CLUSTER_COMP_NAME) - - name: PBM_AGENT_SIDECAR - value: "true" - - name: PBM_AGENT_SIDECAR_SLEEP - value: "5" - name: PBM_MONGODB_URI value: mongodb://$(PBM_AGENT_MONGODB_USERNAME):$(PBM_AGENT_MONGODB_PASSWORD)@localhost:$(KB_SERVICE_PORT)/?authSource=admin # syncer uses the env to wait dns ready @@ -214,37 +207,53 @@ spec: - name: mongodb-backup-agent image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.percona.backup.repository }}:{{ .Values.image.percona.backup.tag }} imagePullPolicy: {{ default "IfNotPresent" .Values.image.pullPolicy }} + ports: + - name: pbm-agent-ha + protocol: TCP + containerPort: 3361 command: - - /bin/bash - - -c - - | - while [ -f $PBM_DATA_MOUNT_POINT/tmp/mongodb_pbm.backup ]; do - echo "Waiting for restore..."; - sleep 5; - done - exec pbm-agent-entrypoint + - /tools/syncer + - -- + - /tools/pbm-agent env: + - name: POD_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.name + - name: POD_NAMESPACE + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.namespace + - name: POD_IP + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: status.podIP - name: PATH value: /tools/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + - name: KB_SERVICE_CHARACTER_TYPE + value: mongodb + - name: KB_WORKLOAD_TYPE + value: pbm-agent + - name: SYNCER_IGNORE_HA + value: "true" + - name: SYNCER_BACKUP_ENABLED + value: "true" + - name: SYNCER_SERVICE_PORT + value: "3361" - name: PBM_AGENT_MONGODB_USERNAME value: $(MONGODB_USER) - name: PBM_AGENT_MONGODB_PASSWORD value: $(MONGODB_PASSWORD) - - name: PBM_MONGODB_REPLICA_SET - value: $(KB_CLUSTER_COMP_NAME) - - name: PBM_AGENT_SIDECAR - value: "true" - - name: PBM_AGENT_SIDECAR_SLEEP - value: "5" - name: PBM_MONGODB_URI value: mongodb://$(PBM_AGENT_MONGODB_USERNAME):$(PBM_AGENT_MONGODB_PASSWORD)@localhost:$(KB_SERVICE_PORT)/?authSource=admin - - name: PBM_DATA_MOUNT_POINT - value: {{ .Values.dataMountPath }} volumeMounts: - mountPath: {{ .Values.dataMountPath }} name: data - - name: scripts - mountPath: /scripts + - mountPath: /tools + name: tools - name: exporter imagePullPolicy: {{ default "IfNotPresent" .Values.image.pullPolicy }} command: @@ -358,4 +367,4 @@ spec: - ha - container: exporter ports: - - exporter \ No newline at end of file + - exporter diff --git a/addons/mongodb/templates/cmpv-mongos.yaml b/addons/mongodb/templates/cmpv-mongos.yaml index d1a9253940..bc7d50b24a 100644 --- a/addons/mongodb/templates/cmpv-mongos.yaml +++ b/addons/mongodb/templates/cmpv-mongos.yaml @@ -27,7 +27,7 @@ spec: serviceVersion: {{ index . 1 }} images: mongos: {{ $imageRegistry }}/{{ $.Values.image.repository }}:{{ index . 2 }} - init-kubectl: {{ $imageRegistry }}/{{ $.Values.image.kubectl.repository }}:{{ $.Values.image.kubectl.tag }} + init-syncer: {{ $imageRegistry }}/{{ $.Values.image.syncer.repository }}:{{ $.Values.image.syncer.tag }} exporter: {{ $imageRegistry }}/{{ $.Values.image.exporter.repository }}:{{ $.Values.image.exporter.tag }} {{- end }} {{- end }} diff --git a/addons/mongodb/templates/cmpv-shard.yaml b/addons/mongodb/templates/cmpv-shard.yaml index 5d5e4adb87..138b7348d7 100644 --- a/addons/mongodb/templates/cmpv-shard.yaml +++ b/addons/mongodb/templates/cmpv-shard.yaml @@ -33,7 +33,6 @@ spec: postProvision: {{ $imageRegistry }}/{{ $.Values.image.repository }}:{{ index . 2 }} mongodb-backup-agent: {{ $imageRegistry }}/{{ $.Values.image.percona.backup.repository }}:{{ index . 3 }} init-syncer: {{ $imageRegistry }}/{{ $.Values.image.syncer.repository }}:{{ $.Values.image.syncer.tag }} - init-kubectl: {{ $imageRegistry }}/{{ $.Values.image.kubectl.repository }}:{{ $.Values.image.kubectl.tag }} init-pbm-agent: {{ $imageRegistry }}/{{ $.Values.image.percona.backup.repository }}:{{ index . 3 }} exporter: {{ $imageRegistry }}/{{ $.Values.image.exporter.repository }}:{{ $.Values.image.exporter.tag }} {{- end }} diff --git a/addons/mongodb/templates/cmpv.yaml b/addons/mongodb/templates/cmpv.yaml index d65f3d4d92..2536571e6c 100644 --- a/addons/mongodb/templates/cmpv.yaml +++ b/addons/mongodb/templates/cmpv.yaml @@ -31,7 +31,6 @@ spec: memberLeave: {{ $imageRegistry }}/{{ $.Values.image.repository }}:{{ index . 2 }} mongodb-backup-agent: {{ $imageRegistry }}/{{ $.Values.image.percona.backup.repository }}:{{ index . 3 }} init-syncer: {{ $imageRegistry }}/{{ $.Values.image.syncer.repository }}:{{ $.Values.image.syncer.tag }} - init-kubectl: {{ $imageRegistry }}/{{ $.Values.image.kubectl.repository }}:{{ $.Values.image.kubectl.tag }} init-pbm-agent: {{ $imageRegistry }}/{{ $.Values.image.percona.backup.repository }}:{{ index . 3 }} exporter: {{ $imageRegistry }}/{{ $.Values.image.exporter.repository }}:{{ $.Values.image.exporter.tag }} {{- end }} diff --git a/addons/mongodb/templates/script-template.yaml b/addons/mongodb/templates/script-template.yaml index 3d654e820a..1186f7731e 100644 --- a/addons/mongodb/templates/script-template.yaml +++ b/addons/mongodb/templates/script-template.yaml @@ -17,8 +17,6 @@ data: DATA_VOLUME={{ .Values.dataMountPath }} {{- .Files.Get "scripts/replicaset-setup.tpl" | nindent 4 }} - mongodb-common.sh: |- - {{- .Files.Get "scripts/mongodb-common.sh" | nindent 4 }} mongodb-member-leave.sh: |- {{- .Files.Get "scripts/mongodb-member-leave.sh" | nindent 4 }} mongodb-switchover.sh: |- diff --git a/addons/mongodb/templates/scriptstemplate-shard.yaml b/addons/mongodb/templates/scriptstemplate-shard.yaml index d08732ffd4..46023573e0 100644 --- a/addons/mongodb/templates/scriptstemplate-shard.yaml +++ b/addons/mongodb/templates/scriptstemplate-shard.yaml @@ -12,8 +12,6 @@ data: {{- .Files.Get "scripts/mongodb-shard-setup.sh" | nindent 4 }} mongodb-shard-manage.sh: |- {{- .Files.Get "scripts/mongodb-shard-manage.sh" | nindent 4 }} - backup-agent-setup.sh: |- - {{- .Files.Get "scripts/backup-agent-setup.sh" | nindent 4 }} mongodb-mongos-setup.sh: |- #!/bin/bash diff --git a/addons/mongodb/values.yaml b/addons/mongodb/values.yaml index c2547b79f9..8cf7677b5a 100644 --- a/addons/mongodb/values.yaml +++ b/addons/mongodb/values.yaml @@ -12,9 +12,6 @@ image: backup: repository: apecloud/percona-backup-mongodb tag: 2.9.1 - kubectl: - repository: apecloud/kubectl - tag: 1.29 syncer: repository: apecloud/syncer tag: "0.7.7"