182 lines
5.7 KiB
Plaintext
182 lines
5.7 KiB
Plaintext
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: mb-backup-manager
|
|
envName: "${env.name}"
|
|
log_file: "/var/log/backup_addon.log"
|
|
|
|
onInstall:
|
|
- checkApplication
|
|
- checkAddons
|
|
- installRestic
|
|
|
|
buttons:
|
|
- caption: Backup Now
|
|
action: backup
|
|
loadingText: Backing up...
|
|
confirmText: Do you want to initiate the backup process?
|
|
successText: The backup process has been finished successfully.
|
|
|
|
menu:
|
|
confirmText: Backup Core Files?
|
|
loadingText: Backing up Core Files on your site
|
|
action: backupcore
|
|
caption: Backup Core Only
|
|
successText: Backup Core Files Completed Successfully
|
|
title: Backup Core Files
|
|
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
|
|
- 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
|
|
|
|
backupcore:
|
|
- cmd[cp]: |-
|
|
# Ensure the /mbmanager directory exists
|
|
mkdir -p /mbmanager
|
|
|
|
# Download the backup-logic.sh script if it doesn't already exist
|
|
if [ ! -f /mbmanager/backup-logic.sh ]; then
|
|
echo "Downloading backup-logic.sh script..."
|
|
wget -O /mbmanager/backup-logic.sh '${baseUrl}/scripts/backup-logic.sh' || curl -o /mbmanager/backup-logic.sh '${baseUrl}/scripts/backup-logic.sh'
|
|
fi
|
|
|
|
# Make the script executable
|
|
chmod +x /mbmanager/backup-logic.sh
|
|
|
|
# Export necessary environment variables
|
|
export ENV_NAME='${globals.envName}'
|
|
export BACKUP_LOG_FILE='${globals.log_file}'
|
|
export BACKUP_TYPE='manual'
|
|
export APP_PATH='/var/www/webroot/ROOT'
|
|
export RESTIC_PASSWORD='your_restic_repository_password' # Replace with your actual password
|
|
export backupPath='/mnt/backups'
|
|
|
|
# Execute the backup_wp_core function from the script
|
|
/bin/bash /mbmanager/backup-logic.sh backup_wp_core
|
|
user: root
|
|
|
|
restore:
|
|
- cmd[cp]: |-
|
|
echo "${settings.backupedEnvName}" > /root/.backupedenv
|
|
echo "${settings.backupDir}" > /root/.backupid
|
|
user: root
|
|
- callScript: restore |