type: update jpsVersion: 1.4 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: 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 Full Backups action: viewFullBackups confirmText: Are you sure you want to view full backups? successText: Full 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. onUninstall: - removeScript onBeforeDelete: - removeScript 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" 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/backup-logic.sh check_backup_repo - return: type: info message: "${response.out}" backupnow: - cmd[cp]: user: root commands: bash /home/jelastic/mb-backups/backup-logic.sh "$(cat /etc/restic-password)" "backup" - 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}" viewFullBackups: - cmd[cp]: user: root commands: bash /home/jelastic/mb-backups/view_snapshots.sh main_backup - 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}" 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]: |- # Download the latest Restic release curl -L https://github.com/restic/restic/releases/download/v0.15.2/restic_0.15.2_linux_amd64.bz2 -o restic.bz2 # Decompress the downloaded file bzip2 -d restic.bz2 # Make the binary executable chmod +x restic # Move it to a directory in your PATH sudo mv restic /usr/local/bin/ # Create the Restic password file with a random password if it doesn't exist if [ ! -f /etc/restic-password ]; then head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16 | sudo tee /etc/restic-password fi # Set the correct permissions and ownership for the password file sudo chown litespeed:litespeed /etc/restic-password sudo chmod 640 /etc/restic-password # Set up log rotation for backup logs echo "/var/log/backup_addon.log { weekly rotate 52 missingok notifempty compress copytruncate }" > /etc/logrotate.d/backup-addon user: root importScripts: - cmd[cp]: user: root commands: - mkdir -p /home/jelastic/mb-backups - mkdir -p /home/litespeed/mb-backups/logs - mkdir -p /home/litespeed/mb-backups/logs/auto - mkdir -p /home/litespeed/mb-backups/logs/manual - mkdir -p /home/litespeed/mb-backups/logs/restore - chown -R litespeed:litespeed /home/litespeed/mb-backups - cd /home/jelastic/mb-backups - curl -O https://deploy-proxy.mightybox.io/addons/mb-backup-manager/raw/branch/main/scripts/backup-logic.sh - 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 - chmod +x /home/litespeed/mb-backups/*.sh - sudo chown -R litespeed:litespeed /home/litespeed/mb-backups