Added create-backup-main-script.js
parent
290fd683af
commit
b6aab4e747
52
manifest.jps
52
manifest.jps
|
@ -13,20 +13,29 @@ targetNodes:
|
|||
- llsmp
|
||||
|
||||
globals:
|
||||
scriptSufix: wpmb-backup
|
||||
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 ALL Now?
|
||||
loadingText: Backing up ALL data on your site
|
||||
action: backupnow
|
||||
caption: Backup All
|
||||
successText: Backup All Completed Successfully
|
||||
title: Backup All Now
|
||||
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:
|
||||
|
@ -110,7 +119,6 @@ actions:
|
|||
|
||||
installScript:
|
||||
- removeScript
|
||||
- getStorageCtid
|
||||
- script: ${baseUrl}/scripts/create-backup-main-script.js?_r=${fn.random}
|
||||
params:
|
||||
scriptName: ${env.envName}-${globals.scriptSufix}
|
||||
|
@ -139,7 +147,33 @@ actions:
|
|||
|
||||
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
|
||||
|
|
|
@ -4,7 +4,7 @@ var action = getParam("action", "backup"),
|
|||
baseUrl = "${baseUrl}";
|
||||
|
||||
function run() {
|
||||
var BackupManager = use("scripts/mb-backup-manager.js", {
|
||||
var BackupManager = use("scripts/backup-manager.js", {
|
||||
session : session,
|
||||
baseUrl : baseUrl,
|
||||
uid : user.uid,
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
//@auth
|
||||
//@req(baseUrl, cronTime)
|
||||
|
||||
var scriptName = getParam("scriptName", "${env.envName}-wp-backup"),
|
||||
envName = getParam("envName", "${env.envName}"),
|
||||
envAppid = getParam("envAppid", "${env.appid}"),
|
||||
userId = getparam("userId", ""),
|
||||
backupCount = getParam("backupCount", "5");
|
||||
|
||||
|
||||
|
||||
function run() {
|
||||
var BackupManager = use("scripts/backup-manager.js", {
|
||||
session : session,
|
||||
baseUrl : baseUrl,
|
||||
uid : userId,
|
||||
cronTime : cronTime,
|
||||
scriptName : scriptName,
|
||||
envName : envName,
|
||||
envAppid : envAppid,
|
||||
backupCount : backupCount
|
||||
});
|
||||
|
||||
api.local.ReturnResult(
|
||||
BackupManager.install()
|
||||
);
|
||||
}
|
||||
|
||||
function use(script, config) {
|
||||
var Transport = com.hivext.api.core.utils.Transport,
|
||||
url = baseUrl + "/" + script + "?_r=" + Math.random(),
|
||||
body = new Transport().get(url);
|
||||
return new (new Function("return " + body)())(config);
|
||||
}
|
||||
|
||||
try {
|
||||
run();
|
||||
} catch (ex) {
|
||||
var resp = {
|
||||
result : com.hivext.api.Response.ERROR_UNKNOWN,
|
||||
error: "Error: " + toJSON(ex)
|
||||
};
|
||||
|
||||
api.marketplace.console.WriteLog("ERROR: " + resp);
|
||||
api.local.ReturnResult(resp);
|
||||
}
|
Loading…
Reference in New Issue