type: update jpsVersion: 1.8 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. baseUrl: https://deploy-proxy.mightybox.io/addons/mb-backup-manager/raw/branch/main targetNodes: nodeType: - nginxphp - litespeedphp - lemp - llsmp globals: envName: "${env.name}" scriptPath: "/home/litespeed/mb-backups" logPath: "/home/litespeed/mb-backups/logs" onInstall: - checkAddons - installRestic - importScripts settings: backupSettings: submitUnchanged: true fields: - name: blabel caption: Backup Label type: string restoreSettings: submitUnchanged: true fields: - name: snapshotId caption: Snapshot ID type: string buttons: - caption: Backup Now action: backupnow loadingText: Backing up... confirmText: Do you want to initiate the backup process? successText: The backup process has been finished successfully. menu: - caption: Configure Auto Backup action: configureAutoBackup confirmText: Configure automated backup schedule? loadingText: Setting up backup schedule... successText: Backup schedule configured successfully title: Configure Automated Backup Schedule submitButtonText: Save Schedule - caption: List Scheduled Backups action: listScheduledBackups confirmText: List scheduled backups? loadingText: Listing scheduled backups... successText: Scheduled backups listed successfully - caption: Remove Auto Backup action: removeAutoBackup confirmText: Remove automated backup schedule? loadingText: Removing backup schedule... successText: Backup schedule removed successfully - caption: View Schedule action: viewBackupSchedule confirmText: View current backup schedule? successText: Current schedule retrieved successfully - 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... action: backupcore successText: Core Files Backup Completed Successfully settings: backupSettings title: Backup Core Files submitButtonText: Backup Now - caption: Media Backup confirmText: Backup Media Files? loadingText: Backing up Media Files... action: backupmedia successText: Media Files Backup Completed Successfully settings: backupSettings title: Backup Media Files submitButtonText: Backup Now - caption: Database Backup confirmText: Backup Database? loadingText: Backing up Database... action: backupdb successText: Database Backup Completed Successfully settings: backupSettings title: Backup Database submitButtonText: Backup Now - caption: Restore confirmText: Restore from Snapshot? loadingText: Restoring... action: restore successText: Restore Completed Successfully settings: restoreSettings title: Restore from Snapshot submitButtonText: Restore Now - caption: View All Backups action: viewAllBackups confirmText: Are you sure you want to view all backups? successText: All backups listed successfully. - caption: View Core Backups action: viewCoreBackups confirmText: Are you sure you want to view core backups? successText: Core backups listed successfully. - caption: View Media Backups action: viewMediaBackups confirmText: Are you sure you want to view media backups? successText: Media backups listed successfully. - caption: View Database Backups action: viewDatabaseBackups confirmText: Are you sure you want to view database backups? successText: Database backups listed successfully. - caption: Check Repository Stats confirmText: Check repository stats? loadingText: Checking repository stats... action: checkRepoStats successText: Repository stats checked successfully. onUninstall: - removeScripts onBeforeDelete: - removeScripts onAfterRedeployContainer[cp]: - installRestic onAfterClone: - script: return {result:0, jps:MANIFEST}; - install: ${response.jps} nodeGroup: ${targetNodes.nodeGroup:cp} settings: cronTime: "0 * * * *" backupCount: "5" actions: configureAutoBackup: - cmd[cp]: user: root commands: bash "/home/jelastic/mb-backups/manage_backup_schedule.sh" add "0 0 * * *" "$(cat /etc/restic-password)" - return: type: info message: "Daily backup schedule configured successfully" listScheduledBackups: - cmd[cp]: user: root commands: bash /home/litespeed/mb-backups/manage_backup_schedule.sh list - return: type: info message: "${response.out}" removeAutoBackup: - cmd[cp]: user: root commands: bash /home/litespeed/mb-backups/manage_backup_schedule.sh remove - return: type: info message: "${response.out}" checkBackupRepo: - cmd[cp]: user: root commands: bash /home/jelastic/mb-backups/check_backup_repo.sh - return: type: info message: "${response.out}" backupnow: - cmd[cp]: user: root commands: bash /home/jelastic/mb-backups/backup_all.sh manual - return: type: info message: "${response.out}" backupcore: - cmd[cp]: user: root commands: bash /home/jelastic/mb-backups/backup_core_files.sh "$(cat /etc/restic-password)" "${settings.blabel}" - return: type: info message: "${response.out}" backupmedia: - cmd[cp]: user: root commands: bash /home/jelastic/mb-backups/backup_media.sh "$(cat /etc/restic-password)" "${settings.blabel}" - return: type: info message: "${response.out}" backupdb: - cmd[cp]: user: root commands: bash /home/jelastic/mb-backups/backup_database.sh "$(cat /etc/restic-password)" "${settings.blabel}" - return: type: info message: "${response.out}" restore: - cmd[cp]: user: root commands: bash /home/jelastic/mb-backups/restore_backup_direct.sh "${settings.snapshotId}" - return: type: info message: "${response.out}" viewAllBackups: - cmd[cp]: user: root commands: bash /home/jelastic/mb-backups/view_snapshots.sh all - return: type: info message: "${response.out}" viewCoreBackups: - cmd[cp]: user: root commands: bash /home/jelastic/mb-backups/view_snapshots.sh core_files - return: type: info message: "${response.out}" viewMediaBackups: - cmd[cp]: user: root commands: bash /home/jelastic/mb-backups/view_snapshots.sh media_themes - return: type: info message: "${response.out}" viewDatabaseBackups: - cmd[cp]: user: root commands: bash /home/jelastic/mb-backups/view_snapshots.sh wordpress_db - return: type: info message: "${response.out}" viewBackupSchedule: - cmd[cp]: user: root commands: bash /home/litespeed/mb-backups/check_sched.sh - return: type: info message: "${response.out}" checkRepoStats: - cmd[cp]: user: root commands: bash /home/jelastic/mb-backups/check_repo_stats.sh - return: type: info message: "${response.out}" checkAddons: - script: |- var onAfterReturn = { setGlobals: {} }, glbs = onAfterReturn.setGlobals, resp = api.marketplace.app.GetAddonList({ search: {}, envName: "${env.name}", session: session }); if (resp.result != 0) return resp; glbs["alreadyInstalled"] = false; for (let i = 0, n = resp.apps.length; i < n; i++) { if (resp.apps[i].isInstalled) { if (resp.apps[i].app_id == 'db-backup') { glbs["alreadyInstalled"] = true; break; } } } return { result: 0, onAfterReturn: onAfterReturn }; - if ('${globals.alreadyInstalled}' == 'true' ): - stopEvent: type: warning message: Database backup add-on is already installed on ${env.name}. Backup addon installation is not possible. installRestic: - cmd[cp]: user: root commands: # Download and install Restic - curl -L https://github.com/restic/restic/releases/download/v0.15.2/restic_0.15.2_linux_amd64.bz2 -o restic.bz2 - bzip2 -d restic.bz2 - chmod +x restic - mv restic /usr/local/bin/ # Create password file if it doesn't exist - if [ ! -f /etc/restic-password ]; then head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16 > /etc/restic-password; fi # Fix the core issue: Make password readable by everyone - chmod 644 /etc/restic-password # Create backup and log directories - mkdir -p /mnt/backups - mkdir -p /home/jelastic/mb-backups/logs - chmod -R 755 /home/jelastic/mb-backups/logs - chmod 755 /mnt/backups # Initialize the Restic repository - export RESTIC_PASSWORD=$(cat /etc/restic-password) && export RESTIC_REPOSITORY=/mnt/backups && restic init importScripts: - cmd[cp]: user: root commands: - mkdir -p /home/jelastic/mb-backups - mkdir -p /home/jelastic/mb-backups/logs - mkdir -p /home/jelastic/mb-backups/logs/auto - mkdir -p /home/jelastic/mb-backups/logs/manual - mkdir -p /home/jelastic/mb-backups/logs/restore - cd /home/jelastic/mb-backups - curl -O https://deploy-proxy.mightybox.io/addons/mb-backup-manager/raw/branch/main/scripts/imports/backup_all.sh - curl -O https://deploy-proxy.mightybox.io/addons/mb-backup-manager/raw/branch/main/scripts/imports/backup_core_files.sh - curl -O https://deploy-proxy.mightybox.io/addons/mb-backup-manager/raw/branch/main/scripts/imports/backup_database.sh - curl -O https://deploy-proxy.mightybox.io/addons/mb-backup-manager/raw/branch/main/scripts/imports/backup_media.sh - curl -O https://deploy-proxy.mightybox.io/addons/mb-backup-manager/raw/branch/main/scripts/imports/check_sched.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/view_snapshots.sh - curl -O https://deploy-proxy.mightybox.io/addons/mb-backup-manager/raw/branch/main/scripts/imports/check_backup_repo.sh - curl -O https://deploy-proxy.mightybox.io/addons/mb-backup-manager/raw/branch/main/scripts/imports/check_repo_stats.sh - chmod +x /home/jelastic/mb-backups/*.sh removeScripts: - cmd[cp]: user: root commands: # Remove the crontab entry for the add-on - (crontab -l | grep -v "${globals.scriptPath}/manage_backup_schedule.sh" | crontab -) || true - rm -rf "${globals.scriptPath}" # Use globals.scriptPath - rm -f /etc/restic-password - rm -f /etc/logrotate.d/backup-addon