From 19680575c3070e2e1b6f0b328a9e2545e01b4234 Mon Sep 17 00:00:00 2001 From: wangyelei Date: Fri, 27 Oct 2023 16:23:49 +0800 Subject: [PATCH] fix: mongodb restore failed for datafile backup (#5647) --- deploy/mongodb/dataprotection/datafile-backup.sh | 2 +- deploy/mongodb/dataprotection/datafile-restore.sh | 2 +- deploy/qdrant/scripts/qdrant-restore.sh | 2 +- deploy/redis/dataprotection/backup.sh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/deploy/mongodb/dataprotection/datafile-backup.sh b/deploy/mongodb/dataprotection/datafile-backup.sh index a3c0a7d4d06..0dcfcf70b2a 100644 --- a/deploy/mongodb/dataprotection/datafile-backup.sh +++ b/deploy/mongodb/dataprotection/datafile-backup.sh @@ -1,4 +1,3 @@ -set -e set -o pipefail export PATH="$PATH:$DP_DATASAFED_BIN_PATH" export DATASAFED_BACKEND_BASE_PATH="$DP_BACKUP_BASE_PATH" @@ -6,6 +5,7 @@ trap handle_exit EXIT cd ${DATA_DIR} START_TIME=$(get_current_time) # TODO: flush data and locked write, otherwise data maybe inconsistent +# NOTE: if files changed during taring, the exit code will be 1 when it ends. tar -czvf - ./ | datasafed push - "${DP_BACKUP_NAME}.tar.gz" rm -rf mongodb.backup # stat and save the backup information diff --git a/deploy/mongodb/dataprotection/datafile-restore.sh b/deploy/mongodb/dataprotection/datafile-restore.sh index b07ae478126..8758c293a80 100644 --- a/deploy/mongodb/dataprotection/datafile-restore.sh +++ b/deploy/mongodb/dataprotection/datafile-restore.sh @@ -3,7 +3,7 @@ set -o pipefail export PATH="$PATH:$DP_DATASAFED_BIN_PATH" export DATASAFED_BACKEND_BASE_PATH="$DP_BACKUP_BASE_PATH" mkdir -p ${DATA_DIR} -res=`ls -A ${DATA_DIR}` +res=`find ${DATA_DIR} -type f` data_protection_file=${DATA_DIR}/.kb-data-protection if [ ! -z "${res}" ] && [ ! -f ${data_protection_file} ]; then echo "${DATA_DIR} is not empty! Please make sure that the directory is empty before restoring the backup." diff --git a/deploy/qdrant/scripts/qdrant-restore.sh b/deploy/qdrant/scripts/qdrant-restore.sh index 809a32ee82a..57730635900 100644 --- a/deploy/qdrant/scripts/qdrant-restore.sh +++ b/deploy/qdrant/scripts/qdrant-restore.sh @@ -5,7 +5,7 @@ set -o pipefail export PATH="$PATH:$DP_DATASAFED_BIN_PATH" export DATASAFED_BACKEND_BASE_PATH="$DP_BACKUP_BASE_PATH" mkdir -p ${DATA_DIR} -res=`ls -A ${DATA_DIR}` +res=`find ${DATA_DIR} -type f` if [ ! -z "${res}" ]; then echo "${DATA_DIR} is not empty! Please make sure that the directory is empty before restoring the backup." exit 1 diff --git a/deploy/redis/dataprotection/backup.sh b/deploy/redis/dataprotection/backup.sh index e0d336da21f..2dfa5b5998c 100644 --- a/deploy/redis/dataprotection/backup.sh +++ b/deploy/redis/dataprotection/backup.sh @@ -1,4 +1,3 @@ -set -e set -o pipefail # if the script exits with a non-zero exit code, touch a file to indicate that the backup failed, @@ -29,6 +28,7 @@ while true; do done echo "INFO: start to save data file..." cd ${DATA_DIR} +# NOTE: if files changed during taring, the exit code will be 1 when it ends. tar -czvf - ./ | datasafed push - "${DP_BACKUP_NAME}.tar.gz" echo "INFO: save data file successfully" TOTAL_SIZE=$(datasafed stat / | grep TotalSize | awk '{print $2}')