Update Check Backup Repo

main
Anthony 2024-11-13 01:00:19 +08:00
parent 9a46217227
commit 3b5ab6e98b
2 changed files with 42 additions and 4 deletions

View File

@ -1,5 +1,5 @@
type: update type: update
jpsVersion: 1.0 jpsVersion: 1.1
name: MightyBox WordPress Backup/Restore Addon name: MightyBox WordPress Backup/Restore Addon
id: mb-backup-manager id: mb-backup-manager
description: Custom Backup and Restore Addon for WordPress using Restic. Supports backing up databases, core files, media files, and full backups with scheduling and retention policies. description: Custom Backup and Restore Addon for WordPress using Restic. Supports backing up databases, core files, media files, and full backups with scheduling and retention policies.
@ -42,6 +42,14 @@ buttons:
successText: The backup process has been finished successfully. successText: The backup process has been finished successfully.
menu: menu:
- caption: Check Backup Repository
confirmText: Do you want to check and repair the backup repository?
loadingText: Checking and repairing backup repository...
action: checkBackupRepo
successText: Backup repository check completed successfully.
title: Check Backup Repository
submitButtonText: Run Check
- caption: Core File Backup - caption: Core File Backup
confirmText: Backup Core Files? confirmText: Backup Core Files?
loadingText: Backing up Core Files... loadingText: Backing up Core Files...
@ -121,6 +129,14 @@ onAfterClone:
backupCount: "5" backupCount: "5"
actions: actions:
checkBackupRepo:
- cmd[cp]:
user: root
commands: bash /home/jelastic/mb-backups/backup-logic.sh check_backup_repo "${globals.envName}"
- return:
type: info
message: "${response.out}"
backupnow: backupnow:
- cmd[cp]: - cmd[cp]:
user: root user: root
@ -265,4 +281,5 @@ actions:
- curl -O https://deploy-proxy.mightybox.io/addons/mb-backup-manager/raw/branch/main/scripts/imports/manage_backup_schedule.sh - curl -O https://deploy-proxy.mightybox.io/addons/mb-backup-manager/raw/branch/main/scripts/imports/manage_backup_schedule.sh
- curl -O https://deploy-proxy.mightybox.io/addons/mb-backup-manager/raw/branch/main/scripts/imports/restore_backup_direct.sh - curl -O https://deploy-proxy.mightybox.io/addons/mb-backup-manager/raw/branch/main/scripts/imports/restore_backup_direct.sh
- curl -O https://deploy-proxy.mightybox.io/addons/mb-backup-manager/raw/branch/main/scripts/imports/view_snapshots.sh - curl -O https://deploy-proxy.mightybox.io/addons/mb-backup-manager/raw/branch/main/scripts/imports/view_snapshots.sh
- curl -O https://deploy-proxy.mightybox.io/addons/mb-backup-manager/raw/branch/main/scripts/backup-logic.sh
- chmod +x /home/litespeed/mb-backups/*.sh - chmod +x /home/litespeed/mb-backups/*.sh

View File

@ -30,25 +30,46 @@ function update_restic(){
function check_backup_repo(){ function check_backup_repo(){
local backup_repo_path="/mnt/backups/${ENV_NAME}" local backup_repo_path="/mnt/backups/${ENV_NAME}"
local password_file="/etc/restic-password"
# Create the backup repository path if it does not exist
[ -d "${backup_repo_path}" ] || mkdir -p "${backup_repo_path}" [ -d "${backup_repo_path}" ] || mkdir -p "${backup_repo_path}"
# Check if the password file exists and if it matches the ENV_NAME
if [ -f "$password_file" ]; then
stored_password=$(cat "$password_file")
if [ "$stored_password" != "$ENV_NAME" ]; then
echo "$(date) Password mismatch detected. Updating password to ${ENV_NAME}" | tee -a "${BACKUP_LOG_FILE}"
echo "$ENV_NAME" > "$password_file"
fi
else
# Create the password file if it doesn't exist
echo "$ENV_NAME" > "$password_file"
echo "$(date) Password file created with password: ${ENV_NAME}" | tee -a "${BACKUP_LOG_FILE}"
fi
# Export the repository password
export RESTIC_PASSWORD="$ENV_NAME"
export RESTIC_REPOSITORY="$backup_repo_path"
export FILES_COUNT=$(find "${backup_repo_path}" -mindepth 1 | wc -l) export FILES_COUNT=$(find "${backup_repo_path}" -mindepth 1 | wc -l)
# Check repository integrity if it has files, otherwise initialize it
if [ "${FILES_COUNT}" -gt 0 ]; then if [ "${FILES_COUNT}" -gt 0 ]; then
echo "$(date) ${ENV_NAME} Checking the backup repository integrity and consistency" | tee -a "${BACKUP_LOG_FILE}" echo "$(date) ${ENV_NAME} Checking the backup repository integrity and consistency" | tee -a "${BACKUP_LOG_FILE}"
if [[ $(ls -A "${backup_repo_path}/locks") ]]; then if [[ $(ls -A "${backup_repo_path}/locks") ]]; then
echo "$(date) ${ENV_NAME} Backup repository has a stale lock, removing" | tee -a "${BACKUP_LOG_FILE}" echo "$(date) ${ENV_NAME} Backup repository has a stale lock, removing" | tee -a "${BACKUP_LOG_FILE}"
GOGC=20 RESTIC_PASSWORD="${ENV_NAME}" restic -r "${backup_repo_path}" unlock GOGC=20 restic -r "${backup_repo_path}" unlock
sendEmailNotification sendEmailNotification
fi fi
if ! GOGC=20 RESTIC_PASSWORD="${ENV_NAME}" restic -q -r "${backup_repo_path}" check --read-data-subset=5%; then 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}" echo "Backup repository integrity check failed." | tee -a "${BACKUP_LOG_FILE}"
exit 1 exit 1
fi fi
else else
echo "$(date) ${ENV_NAME} Initializing new backup repository" | tee -a "${BACKUP_LOG_FILE}" echo "$(date) ${ENV_NAME} Initializing new backup repository" | tee -a "${BACKUP_LOG_FILE}"
GOGC=20 RESTIC_PASSWORD="${ENV_NAME}" restic init -r "${backup_repo_path}" GOGC=20 restic init -r "${backup_repo_path}"
fi fi
} }