From 2a3c7341f05325853924f6b0909b8551d644e32d Mon Sep 17 00:00:00 2001 From: Anthony Date: Wed, 13 Nov 2024 01:23:39 +0800 Subject: [PATCH] Updated password checks and reinitiate restic --- scripts/backup-logic.sh | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/scripts/backup-logic.sh b/scripts/backup-logic.sh index 7a26ae5..318e6b5 100644 --- a/scripts/backup-logic.sh +++ b/scripts/backup-logic.sh @@ -54,21 +54,23 @@ function check_backup_repo() { 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 + echo "$(date) Reinitializing the repository with a new password." | tee -a "${backup_log_file}" + rm -rf "${backup_repo_path}"/* + GOGC=20 restic init -r "${backup_repo_path}" + echo "$(date) Repository reinitialized with a new password." | tee -a "${backup_log_file}" + else + # 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}" + GOGC=20 restic -r "${backup_repo_path}" unlock + sendEmailNotification + 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}" - GOGC=20 restic -r "${backup_repo_path}" unlock - sendEmailNotification - fi - - # Run the repository check command - if ! GOGC=20 restic -q -r "${backup_repo_path}" check --read-data-subset=5%; then - echo "Backup repository integrity check failed." | tee -a "${backup_log_file}" - exit 1 + # Run the repository check command + if ! GOGC=20 restic -q -r "${backup_repo_path}" check --read-data-subset=5%; then + echo "Backup repository integrity check failed." | tee -a "${backup_log_file}" + exit 1 + fi fi else echo "$(date) ${ENV_NAME} Initializing new backup repository" | tee -a "${backup_log_file}" @@ -76,6 +78,7 @@ function check_backup_repo() { fi } + function sendEmailNotification() { if [ -e "/usr/lib/jelastic/modules/api.module" ]; then [ -e "/var/run/jem.pid" ] && return 0;