From ac5187845d401e130c53a5140cd983a2e1506653 Mon Sep 17 00:00:00 2001 From: Anthony Date: Wed, 13 Nov 2024 01:21:04 +0800 Subject: [PATCH] Update logging --- scripts/backup-logic.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/scripts/backup-logic.sh b/scripts/backup-logic.sh index 7deb074..7a26ae5 100644 --- a/scripts/backup-logic.sh +++ b/scripts/backup-logic.sh @@ -29,9 +29,9 @@ function update_restic(){ } function check_backup_repo() { - local backup_repo_path="/mnt/backups/" + local backup_repo_path="/mnt/backups/${ENV_NAME}" local password_file="/etc/restic-password" - local backup_log_file="/var/log/backup_addon.log" # Set the log file path + local backup_log_file="/var/log/backup_addon.log" # Ensure the backup repository directory exists [ -d "${backup_repo_path}" ] || mkdir -p "${backup_repo_path}" @@ -48,10 +48,16 @@ function check_backup_repo() { export RESTIC_REPOSITORY="$backup_repo_path" export FILES_COUNT=$(find "${backup_repo_path}" -mindepth 1 | wc -l) - # Check repository integrity if files exist; initialize otherwise + # Check if the repository is accessible with the current password if [ "${FILES_COUNT}" -gt 0 ]; then echo "$(date) ${ENV_NAME} Checking the backup repository integrity and consistency" | tee -a "${backup_log_file}" - + + if ! GOGC=20 restic -r "${backup_repo_path}" snapshots > /dev/null 2>&1; then + echo "$(date) ${ENV_NAME} ERROR: Repository exists but password does not match." | tee -a "${backup_log_file}" + echo "Please reinitialize the repository manually or adjust the password file." | tee -a "${backup_log_file}" + exit 1 + fi + # Remove stale lock if exists if [[ $(ls -A "${backup_repo_path}/locks") ]]; then echo "$(date) ${ENV_NAME} Backup repository has a stale lock, removing" | tee -a "${backup_log_file}" @@ -70,8 +76,6 @@ function check_backup_repo() { fi } - - function sendEmailNotification() { if [ -e "/usr/lib/jelastic/modules/api.module" ]; then [ -e "/var/run/jem.pid" ] && return 0;