From bbff0e30f84ce012c72e12ee93782287d522e000 Mon Sep 17 00:00:00 2001 From: Teingi Date: Mon, 9 Dec 2024 21:00:54 +0800 Subject: [PATCH] fix --- init.sh | 8 ++++---- obdiag_backup.sh | 26 +++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/init.sh b/init.sh index fcf219bf..2e9b09b2 100755 --- a/init.sh +++ b/init.sh @@ -50,10 +50,11 @@ if [ -d "${OBDIAG_HOME}/check_package.yaml" ]; then echo "${OBDIAG_HOME}/*check_package.yaml and ${OBDIAG_HOME}/tasks has been discarded. If you have made any changes to these files on your own, please transfer the relevant data to *check_package.yaml in ${OBDIAG_HOME}/check/" fi +cd - output_file=${OBDIAG_HOME}/version.yaml -version_line=$(obdiag --version 2>&1 | grep -oP 'OceanBase Diagnostic Tool: \K[\d.]+') -if [ -n "$version" ]; then - content="obdiag_version: \"$version\"" +version_line=$(/usr/local/oceanbase-diagnostic-tool/obdiag --version 2>&1 | grep -oP 'OceanBase Diagnostic Tool: \K[\d.]+') +if [ -n "$version_line" ]; then + content="obdiag_version: \"$version_line\"" # Write or update the version information to the file echo "$content" > "$output_file" @@ -64,4 +65,3 @@ else fi echo "Init obdiag finished" -cd - diff --git a/obdiag_backup.sh b/obdiag_backup.sh index bc7ff2be..40a37d02 100755 --- a/obdiag_backup.sh +++ b/obdiag_backup.sh @@ -10,6 +10,20 @@ mkdir -p "$BACKUP_DIR" # List of directories to be backed up DIRS=("display" "check" "gather" "rca") +# Check if any of the directories contain files +should_backup=false +for dir in "${DIRS[@]}"; do + if [ -d "$SOURCE_DIR$dir" ] && [ "$(ls -A "$SOURCE_DIR$dir")" ]; then + should_backup=true + break + fi +done + +if ! $should_backup; then + echo "None of the specified directories contain files. Skipping backup." + exit 0 +fi + # Retrieve version information; if file does not exist or read fails, VERSION remains empty VERSION="" if [ -f "$SOURCE_DIR/version.yaml" ]; then @@ -17,9 +31,15 @@ if [ -f "$SOURCE_DIR/version.yaml" ]; then fi # Define the name of the backup archive (use timestamp for uniqueness, and optionally add version) -TIMESTAMP=$(date +"%Y%m%d_%H%M%S") -TARFILE="$BACKUP_DIR/obdiag_backup_$TIMESTAMP" -TARFILE+="${VERSION:+_v$VERSION}.tar.gz" +TIMESTAMP=$(date +"%Y%m%d%H%M%S") +BASE_NAME="obdiag_backup${VERSION:+_v$VERSION}" +TARFILE="$BACKUP_DIR/${BASE_NAME}_$TIMESTAMP.tar.gz" + +# Check if a file with the same name already exists in the BACKUP_DIR +if find "$BACKUP_DIR" -maxdepth 1 -name "${BASE_NAME}_*.tar.gz" -print -quit | grep -q .; then + echo "A backup file with the same name already exists. Skipping backup creation." + exit 0 +fi # Temporary directory for staging backup files TEMP_BACKUP_DIR="$BACKUP_DIR/tmp_obdiag_backup_$TIMESTAMP"