type: update jpsVersion: 6.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. baseUrl: https://deploy-proxy.mightybox.io/addons/mb-backup-manager/raw/branch/main targetNodes: nodeType: - nginxphp - litespeedphp - lemp - llsmp globals: scriptSufix: wpmb-backup onInstall: - checkApplication - checkAddons - installRestic menu: confirmText: Backup ALL Now? loadingText: Backing up ALL data on your site action: backupnow caption: Backup All successText: Backup All Completed Successfully title: Backup All Now submitButtonText: Backup Now onUninstall: - callScript: uninstall - removeScript onBeforeDelete: - callScript: uninstall - removeScript onAfterRedeployContainer[cp]: - installRestic onAfterClone: - script: return {result:0, jps:MANIFEST}; - install: ${response.jps} nodeGroup: ${targetNodes.nodeGroup:cp} settings: cronTime: "0 * * * *" backupCount: "5" actions: checkApplication: - cmd[${nodes.cp.master.id}]: |- [ -f /root/check_app.sh ] && rm -f /root/check_app.sh; wget -O /root/check_app.sh ${baseUrl}/scripts/check_app.sh; bash /root/check_app.sh; user: root - if (response.out == "Non-supported"): - stopEvent: type: warning message: Deployed application is not supported by Backup add-on. backupnow: message: BACKUP ALL DONE 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]: |- if which dnf >/dev/null 2>&1; then dnf install -y epel-release dnf install -y restic else yum-config-manager --add-repo https://copr.fedorainfracloud.org/coprs/copart/restic/repo/epel-7/copart-restic-epel-7.repo yum-config-manager --enable copr:copr.fedorainfracloud.org:copart:restic yum -y install restic yum-config-manager --disable copr:copr.fedorainfracloud.org:copart:restic echo "/var/log/backup_addon.log { weekly rotate 52 missingok notifempty compress copytruncate }" > /etc/logrotate.d/backup-addon fi user: root installScript: - removeScript - getStorageCtid - script: ${baseUrl}/scripts/create-backup-main-script.js?_r=${fn.random} params: scriptName: ${env.envName}-${globals.scriptSufix} baseUrl: ${baseUrl} cronTime: '0 * * * *' backupCount: '5' userId: ${env.uid} callScript: script: |- var resp = api.dev.scripting.Eval(appid, session, '${env.envName}-${globals.scriptSufix}', {action:"${this}"}); if (resp.result === 1702 && "${this}" == "uninstall") { return { result: 0, out: "script not found" }; } else { return resp.response || resp; } removeScript: script: |- var resp = api.dev.scripting.GetScript(appid, session, '${env.envName}-${globals.scriptSufix}'); if (resp.result === 0) { var resp = api.dev.scripting.DeleteScript(appid, session, '${env.envName}-${globals.scriptSufix}'); return resp.response || resp; } return { result: 0 }; backup: - callScript: backup restore: - cmd[cp]: |- echo "${settings.backupedEnvName}" > /root/.backupedenv echo "${settings.backupDir}" > /root/.backupid user: root - callScript: restore