Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Teingi committed Dec 9, 2024
1 parent d517211 commit bbff0e3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
8 changes: 4 additions & 4 deletions init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -64,4 +65,3 @@ else
fi

echo "Init obdiag finished"
cd -
26 changes: 23 additions & 3 deletions obdiag_backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,36 @@ 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
VERSION=$(grep 'obdiag_version:' "$SOURCE_DIR/version.yaml" | awk '{print $2}' | tr -d '"')
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"
Expand Down

0 comments on commit bbff0e3

Please sign in to comment.