Update Check Backup Repo
parent
9a46217227
commit
3b5ab6e98b
19
manifest.jps
19
manifest.jps
|
@ -1,5 +1,5 @@
|
|||
type: update
|
||||
jpsVersion: 1.0
|
||||
jpsVersion: 1.1
|
||||
name: MightyBox WordPress Backup/Restore Addon
|
||||
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.
|
||||
|
@ -42,6 +42,14 @@ buttons:
|
|||
successText: The backup process has been finished successfully.
|
||||
|
||||
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
|
||||
confirmText: Backup Core Files?
|
||||
loadingText: Backing up Core Files...
|
||||
|
@ -121,6 +129,14 @@ onAfterClone:
|
|||
backupCount: "5"
|
||||
|
||||
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:
|
||||
- cmd[cp]:
|
||||
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/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/backup-logic.sh
|
||||
- chmod +x /home/litespeed/mb-backups/*.sh
|
|
@ -30,25 +30,46 @@ function update_restic(){
|
|||
|
||||
function check_backup_repo(){
|
||||
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}"
|
||||
|
||||
# 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)
|
||||
|
||||
# Check repository integrity if it has files, otherwise initialize it
|
||||
if [ "${FILES_COUNT}" -gt 0 ]; then
|
||||
echo "$(date) ${ENV_NAME} Checking the backup repository integrity and consistency" | tee -a "${BACKUP_LOG_FILE}"
|
||||
|
||||
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_PASSWORD="${ENV_NAME}" restic -r "${backup_repo_path}" unlock
|
||||
GOGC=20 restic -r "${backup_repo_path}" unlock
|
||||
sendEmailNotification
|
||||
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}"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue