163 lines
5.2 KiB
Plaintext
163 lines
5.2 KiB
Plaintext
|
type: update
|
||
|
jpsVersion: 1.0
|
||
|
name: MightyBox WordPress Backup/Restore Addon
|
||
|
id: mb-backup-manager
|
||
|
targetEditions: any
|
||
|
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://raw.githubusercontent.com/mightybox-io/mb-backup-addon/main/mbbackupmanager.jps?token=GHSAT0AAAAAACOUCGPBHK4W74UZLPMP3462ZPAMSGQ
|
||
|
|
||
|
targetNodes:
|
||
|
nodeType:
|
||
|
- nginxphp
|
||
|
- litespeedphp
|
||
|
- lemp
|
||
|
- llsmp
|
||
|
|
||
|
settings:
|
||
|
backup:
|
||
|
fields:
|
||
|
- type: checkbox
|
||
|
name: enableScheduledBackup
|
||
|
caption: Enable Scheduled Backup
|
||
|
default: false
|
||
|
- type: list
|
||
|
name: backupSchedule
|
||
|
caption: Backup Schedule
|
||
|
required: true
|
||
|
dependsOn: enableScheduledBackup:true
|
||
|
values:
|
||
|
- value: daily
|
||
|
caption: Daily
|
||
|
- value: weekly
|
||
|
caption: Weekly
|
||
|
- value: monthly
|
||
|
caption: Monthly
|
||
|
- value: custom
|
||
|
caption: Custom
|
||
|
showIf: enableScheduledBackup:true
|
||
|
- type: string
|
||
|
name: customCron
|
||
|
caption: Custom Cron Schedule
|
||
|
dependsOn: backupSchedule:custom
|
||
|
showIf: backupSchedule:custom
|
||
|
- type: spinner
|
||
|
name: backupRetentionCount
|
||
|
caption: Number of Backups to Retain
|
||
|
default: 5
|
||
|
min: 1
|
||
|
max: 30
|
||
|
tooltip: "The number of newest backups to be kept during rotation."
|
||
|
|
||
|
onInstall:
|
||
|
- checkApplication
|
||
|
- checkAddons
|
||
|
- installRestic
|
||
|
- setSchedule
|
||
|
|
||
|
actions:
|
||
|
checkApplication:
|
||
|
cmd[${nodes.cp.master.id}]: |-
|
||
|
#!/bin/bash
|
||
|
if [ -e /var/www/webroot/ROOT/wp-config.php ]; then
|
||
|
echo "$(date) trying to install the backup add-on" >> /var/log/backup_addon.log
|
||
|
if [ -e /home/jelastic/bin/wp ]; then
|
||
|
/home/jelastic/bin/wp --info >> /var/log/backup_addon.log
|
||
|
fi
|
||
|
else
|
||
|
echo "$(date) The application deployed to WEBROOT cannot be backuped by Jelastic backup add-on" >> /var/log/backup_addon.log
|
||
|
echo "Non-supported"
|
||
|
fi
|
||
|
|
||
|
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; then
|
||
|
dnf install epel-release
|
||
|
dnf install 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
|
||
|
wget -O /etc/logrotate.d/backup-addon ${baseUrl}/scripts/backup-addon;
|
||
|
fi
|
||
|
user: root
|
||
|
|
||
|
setSchedule:
|
||
|
- setGlobals:
|
||
|
storageEnv: ${settings.storageName}
|
||
|
- if ("${settings.scheduleType}" == 2):
|
||
|
- convert
|
||
|
- else:
|
||
|
- setGlobals:
|
||
|
cron: ${settings.cronTime}
|
||
|
- installScript:
|
||
|
cronTime: ${globals.cron}
|
||
|
backupCount: ${settings.backupCount}
|
||
|
|
||
|
installScript:
|
||
|
- removeScript
|
||
|
- getStorageCtid
|
||
|
- script: ${baseUrl}/scripts/create-backup-main-script.js?_r=${fn.random}
|
||
|
params:
|
||
|
scriptName: ${env.envName}-${globals.scriptSufix}
|
||
|
baseUrl: ${baseUrl}
|
||
|
cronTime: ${this.cronTime}
|
||
|
backupCount: ${this.backupCount}
|
||
|
userId: ${env.uid}
|
||
|
storageNodeId: ${response.storageCtid}
|
||
|
backupExecNode: ${nodes.cp.master.id}
|
||
|
storageEnv: ${response.storageEnvShortName}
|
||
|
|
||
|
globals:
|
||
|
scriptSufix: mb-backup-manager
|
||
|
|
||
|
actions:
|
||
|
backupAllNow:
|
||
|
cmd[${nodes.cp.master.id}]: scripts/backupAll.sh
|
||
|
backupDatabaseOnly:
|
||
|
cmd[${nodes.cp.master.id}]: scripts/backupDatabase.sh
|
||
|
backupWordPressCoreFilesOnly:
|
||
|
cmd[${nodes.cp.master.id}]: scripts/backupWordPressCore.sh
|
||
|
backupMediaFilesOnly:
|
||
|
cmd[${nodes.cp.master.id}]: scripts/backupMediaFiles.sh
|
||
|
restoreAll:
|
||
|
cmd[${nodes.cp.master.id}]: scripts/restoreAll.sh
|
||
|
restoreDatabaseOnly:
|
||
|
cmd[${nodes.cp.master.id}]: scripts/restoreDatabase.sh
|
||
|
restoreMediaFilesOnly:
|
||
|
cmd[${nodes.cp.master.id}]: scripts/restoreMediaFiles.sh
|
||
|
restoreWordPressCoreFilesOnly:
|
||
|
cmd[${nodes.cp.master.id}]: scripts/restoreWordPressCore.sh
|
||
|
configureBackupSchedule:
|
||
|
script: scripts/configureSchedule.js
|
||
|
manageBackupRetention:
|
||
|
script: scripts/manageRetention.js
|
||
|
|
||
|
onUninstall:
|
||
|
- cmd[${nodes.cp.master.id}]: scripts/uninstallRestic.sh
|