2024-02-29 12:36:59 +00:00
type: update
2024-03-07 14:40:30 +00:00
jpsVersion: 6.1.1
2024-02-29 12:36:59 +00:00
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.
2024-03-12 15:45:00 +00:00
baseUrl: https://deploy-proxy.mightybox.io/addons/mb-backup-manager/raw/branch/main
2024-03-07 15:23:59 +00:00
2024-02-29 12:36:59 +00:00
targetNodes:
2024-03-07 14:39:23 +00:00
nodeType:
- nginxphp
- litespeedphp
- lemp
- llsmp
2024-02-29 12:36:59 +00:00
2024-03-04 17:31:33 +00:00
globals:
2024-03-12 15:45:00 +00:00
scriptSufix: wpmb-backup
2024-02-29 12:36:59 +00:00
onInstall:
- checkApplication
- checkAddons
- installRestic
2024-03-13 13:25:45 +00:00
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
2024-02-29 12:36:59 +00:00
2024-03-04 17:31:33 +00:00
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:
2024-03-12 15:45:00 +00:00
cronTime: "0 * * * *"
backupCount: "5"
2024-03-04 17:31:33 +00:00
2024-02-29 12:36:59 +00:00
actions:
checkApplication:
2024-03-04 17:31:33 +00:00
- 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.
2024-03-13 13:25:45 +00:00
backupnow:
message: BACKUP ALL DONE
2024-02-29 12:36:59 +00:00
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++) {
2024-03-04 17:31:33 +00:00
if (resp.apps[i].isInstalled) {
2024-02-29 12:36:59 +00:00
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.
2024-03-04 17:31:33 +00:00
2024-02-29 12:36:59 +00:00
installRestic:
2024-03-04 17:31:33 +00:00
cmd [cp]: |-
2024-03-12 15:45:00 +00:00
if which dnf >/dev/null 2>&1; then
dnf install -y epel-release
dnf install -y restic
2024-02-29 12:36:59 +00:00
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
2024-03-13 13:25:45 +00:00
echo "/var/log/backup_addon.log {
weekly
rotate 52
missingok
notifempty
compress
copytruncate
}" > /etc/logrotate.d/backup-addon
2024-03-12 15:45:00 +00:00
fi
2024-03-04 17:31:33 +00:00
user: root
2024-02-29 12:36:59 +00:00
installScript:
- removeScript
2024-03-07 14:52:13 +00:00
- getStorageCtid
2024-02-29 12:36:59 +00:00
- script: ${baseUrl}/scripts/create-backup-main-script.js?_r=${fn.random}
params:
scriptName: ${env.envName}-${globals.scriptSufix}
baseUrl: ${baseUrl}
2024-03-13 13:25:45 +00:00
cronTime: '0 * * * *'
backupCount: '5'
2024-02-29 12:36:59 +00:00
userId: ${env.uid}
2024-03-13 13:25:45 +00:00
2024-03-04 17:31:33 +00:00
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 };
2024-03-07 14:52:13 +00:00
backup:
2024-03-04 17:31:33 +00:00
- callScript: backup
restore:
- cmd[cp]: |-
echo "${settings.backupedEnvName}" > /root/.backupedenv
echo "${settings.backupDir}" > /root/.backupid
user: root
2024-03-13 13:25:45 +00:00
- callScript: restore