From d3c3a603e7f00c14ec100c54f0444f159497dded Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Thu, 22 Aug 2019 20:38:49 +0500 Subject: [PATCH] feature: set custom path for local backups --- backup/backupManager.py | 13 ++ backup/static/backup/backup.js | 8 + backup/templates/backup/backupSchedule.html | 235 +++++++++++--------- plogical/backupSchedule.py | 6 +- plogical/backupScheduleLocal.py | 18 +- 5 files changed, 165 insertions(+), 115 deletions(-) diff --git a/backup/backupManager.py b/backup/backupManager.py index 969bb94c3..cf68a2a05 100755 --- a/backup/backupManager.py +++ b/backup/backupManager.py @@ -24,6 +24,7 @@ from plogical.processUtilities import ProcessUtilities from multiprocessing import Process class BackupManager: + localBackupPath = '/home/cyberpanel/localBackupPath' def __init__(self, domain = None, childDomain = None): self.domain = domain self.childDomain = childDomain @@ -681,6 +682,12 @@ class BackupManager: command = "systemctl restart crond" ProcessUtilities.executioner(command) + ## Set local path for backup + + writeToFile = open(BackupManager.localBackupPath, 'w') + writeToFile.write(data['localPath']) + writeToFile.close() + destination = dest.objects.get(destLoc=backupDest) newSchedule = backupSchedules(dest=destination, frequency=backupFreq) newSchedule.save() @@ -720,6 +727,12 @@ class BackupManager: newSchedule = backupSchedules(dest=destination, frequency=backupFreq) newSchedule.save() + ## Set local path for backup + + writeToFile = open(BackupManager.localBackupPath, 'w') + writeToFile.write(data['localPath']) + writeToFile.close() + final_json = json.dumps({'scheduleStatus': 1, 'error_message': "None"}) return HttpResponse(final_json) diff --git a/backup/static/backup/backup.js b/backup/static/backup/backup.js index 3648f61bd..9c158422b 100755 --- a/backup/static/backup/backup.js +++ b/backup/static/backup/backup.js @@ -680,6 +680,7 @@ app.controller('scheduleBackup', function ($scope, $http, $timeout) { $scope.couldNotConnect = true; $scope.scheduleFreq = true; $scope.scheduleBtn = true; + $scope.localPath = true; populateCurrentRecords(); @@ -691,6 +692,12 @@ app.controller('scheduleBackup', function ($scope, $http, $timeout) { $scope.scheduleFreq = false; $scope.scheduleBtn = true; + if($scope.backupDest === 'Home'){ + $scope.localPath = false; + }else{ + $scope.localPath = true; + } + }; $scope.scheduleBtnView = function () { @@ -719,6 +726,7 @@ app.controller('scheduleBackup', function ($scope, $http, $timeout) { var data = { backupDest: $scope.backupDest, backupFreq: $scope.backupFreq, + localPath: $scope.localPathValue }; var config = { diff --git a/backup/templates/backup/backupSchedule.html b/backup/templates/backup/backupSchedule.html index 2a2b35b81..69de37618 100755 --- a/backup/templates/backup/backupSchedule.html +++ b/backup/templates/backup/backupSchedule.html @@ -3,121 +3,134 @@ {% block title %}{% trans "Schedule Back up - CyberPanel" %} {% endblock %} {% block content %} -{% load static %} - -{% get_current_language as LANGUAGE_CODE %} - - -
-
-

{% trans "Schedule Back up" %} - {% trans "Remote Backups" %}

-

{% trans "On this page you can schedule Back ups to localhost or remote server (If you have added one)." %}

-
- -
-
-

- {% trans "Schedule Back up" %} -

-
- - -
- - -
- -
- -
-
- -
- -
- -
-
- - - -
- -
- - -
-
- - - - - -
- - -
- -
-

{% trans "Cannot add schedule. Error message:" %} {$ errorMessage $}

-
- -
-

{% trans "Schedule Added" %}

-
- -
-

{% trans "Could not connect to server. Please refresh this page." %}

-
-
-
- -
- -
- - - - - - - - - - - - - - - - - - - -
{% trans "ID" %}{% trans "Destination" %}{% trans "Frequency" %}{% trans "Delete" %}
-
-
- - - - -
- + {% load static %} + {% get_current_language as LANGUAGE_CODE %} + +
+
+

{% trans "Schedule Back up" %} - {% trans "Remote Backups" %}

+

{% trans "On this page you can schedule Back ups to localhost or remote server (If you have added one)." %}

+ +
+
+

+ {% trans "Schedule Back up" %} +

+
+ + +
+ + +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ + +
+ +
+ + +
+
+ + + + + +
+ + +
+ +
+

{% trans "Cannot add schedule. Error message:" %} {$ errorMessage $}

+
+ +
+

{% trans "Schedule Added" %}

+
+ +
+

{% trans "Could not connect to server. Please refresh this page." %}

+
+
+
+ +
+ +
+ + + + + + + + + + + + + + + + + + + +
{% trans "ID" %}{% trans "Destination" %}{% trans "Frequency" %}{% trans "Delete" %}
+
+
+ + + + +
+ + +
+
+
+ +
-
- - -
{% endblock %} \ No newline at end of file diff --git a/plogical/backupSchedule.py b/plogical/backupSchedule.py index 4c33a218f..ce4f933a3 100755 --- a/plogical/backupSchedule.py +++ b/plogical/backupSchedule.py @@ -14,13 +14,12 @@ from backupUtilities import backupUtilities from re import match,I,M from websiteFunctions.models import Websites, Backups from plogical.processUtilities import ProcessUtilities -from multiprocessing import Process -import plogical.backupUtilities as backupUtil from random import randint import json, requests class backupSchedule: + @staticmethod def remoteBackupLogging(fileName, message): try: @@ -88,6 +87,7 @@ class backupSchedule: os.remove(pathToFile) except: pass + logging.CyberCPLogFileWriter.writeToFile(tempStoragePath) return 1, tempStoragePath elif status.find("[5009]") > -1: @@ -117,7 +117,7 @@ class backupSchedule: return 0, tempStoragePath except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [119:startBackup]") - return 0, "None" + return 0, str(msg) @staticmethod def createBackup(virtualHost, ipAddress, backupLogPath , port): diff --git a/plogical/backupScheduleLocal.py b/plogical/backupScheduleLocal.py index 4067af5e5..7f000cf30 100755 --- a/plogical/backupScheduleLocal.py +++ b/plogical/backupScheduleLocal.py @@ -2,8 +2,11 @@ import CyberCPLogFileWriter as logging import os import time from backupSchedule import backupSchedule +from plogical.processUtilities import ProcessUtilities +from re import match,I,M class backupScheduleLocal: + localBackupPath = '/home/cyberpanel/localBackupPath' @staticmethod def prepare(): @@ -20,7 +23,20 @@ class backupScheduleLocal: backupSchedule.remoteBackupLogging(backupLogPath, "") for virtualHost in os.listdir("/home"): - backupSchedule.createLocalBackup(virtualHost, backupLogPath) + if match(r'([\da-z\.-]+\.[a-z\.]{2,12}|[\d\.]+)([\/:?=&#]{1}[\da-z\.-]+)*[\/\?]?', virtualHost, M | I): + retValues = backupSchedule.createLocalBackup(virtualHost, backupLogPath) + + if os.path.exists(backupScheduleLocal.localBackupPath): + backupPath = retValues[1] + ".tar.gz" + localBackupPath = '%s/%s' % (open(backupScheduleLocal.localBackupPath, 'r').read().rstrip('/'), time.strftime("%b-%d-%Y")) + + command = 'mkdir -p %s' % (localBackupPath) + ProcessUtilities.normalExecutioner(command) + + command = 'mv %s %s' % (backupPath, localBackupPath) + ProcessUtilities.normalExecutioner(command) + + backupSchedule.remoteBackupLogging(backupLogPath, "") backupSchedule.remoteBackupLogging(backupLogPath, "")