mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-07 22:06:05 +01:00
feature: set custom path for local backups
This commit is contained in:
@@ -24,6 +24,7 @@ from plogical.processUtilities import ProcessUtilities
|
|||||||
from multiprocessing import Process
|
from multiprocessing import Process
|
||||||
|
|
||||||
class BackupManager:
|
class BackupManager:
|
||||||
|
localBackupPath = '/home/cyberpanel/localBackupPath'
|
||||||
def __init__(self, domain = None, childDomain = None):
|
def __init__(self, domain = None, childDomain = None):
|
||||||
self.domain = domain
|
self.domain = domain
|
||||||
self.childDomain = childDomain
|
self.childDomain = childDomain
|
||||||
@@ -681,6 +682,12 @@ class BackupManager:
|
|||||||
command = "systemctl restart crond"
|
command = "systemctl restart crond"
|
||||||
ProcessUtilities.executioner(command)
|
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)
|
destination = dest.objects.get(destLoc=backupDest)
|
||||||
newSchedule = backupSchedules(dest=destination, frequency=backupFreq)
|
newSchedule = backupSchedules(dest=destination, frequency=backupFreq)
|
||||||
newSchedule.save()
|
newSchedule.save()
|
||||||
@@ -720,6 +727,12 @@ class BackupManager:
|
|||||||
newSchedule = backupSchedules(dest=destination, frequency=backupFreq)
|
newSchedule = backupSchedules(dest=destination, frequency=backupFreq)
|
||||||
newSchedule.save()
|
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"})
|
final_json = json.dumps({'scheduleStatus': 1, 'error_message': "None"})
|
||||||
return HttpResponse(final_json)
|
return HttpResponse(final_json)
|
||||||
|
|
||||||
|
|||||||
@@ -680,6 +680,7 @@ app.controller('scheduleBackup', function ($scope, $http, $timeout) {
|
|||||||
$scope.couldNotConnect = true;
|
$scope.couldNotConnect = true;
|
||||||
$scope.scheduleFreq = true;
|
$scope.scheduleFreq = true;
|
||||||
$scope.scheduleBtn = true;
|
$scope.scheduleBtn = true;
|
||||||
|
$scope.localPath = true;
|
||||||
|
|
||||||
populateCurrentRecords();
|
populateCurrentRecords();
|
||||||
|
|
||||||
@@ -691,6 +692,12 @@ app.controller('scheduleBackup', function ($scope, $http, $timeout) {
|
|||||||
$scope.scheduleFreq = false;
|
$scope.scheduleFreq = false;
|
||||||
$scope.scheduleBtn = true;
|
$scope.scheduleBtn = true;
|
||||||
|
|
||||||
|
if($scope.backupDest === 'Home'){
|
||||||
|
$scope.localPath = false;
|
||||||
|
}else{
|
||||||
|
$scope.localPath = true;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.scheduleBtnView = function () {
|
$scope.scheduleBtnView = function () {
|
||||||
@@ -719,6 +726,7 @@ app.controller('scheduleBackup', function ($scope, $http, $timeout) {
|
|||||||
var data = {
|
var data = {
|
||||||
backupDest: $scope.backupDest,
|
backupDest: $scope.backupDest,
|
||||||
backupFreq: $scope.backupFreq,
|
backupFreq: $scope.backupFreq,
|
||||||
|
localPath: $scope.localPathValue
|
||||||
};
|
};
|
||||||
|
|
||||||
var config = {
|
var config = {
|
||||||
|
|||||||
@@ -10,14 +10,18 @@
|
|||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div id="page-title">
|
<div id="page-title">
|
||||||
<h2>{% trans "Schedule Back up" %} - <a target="_blank" href="http://go.cyberpanel.net/remote-backup" style="height: 23px;line-height: 21px;" class="btn btn-border btn-alt border-red btn-link font-red" title=""><span>{% trans "Remote Backups" %}</span></a></h2>
|
<h2>{% trans "Schedule Back up" %} - <a target="_blank" href="http://go.cyberpanel.net/remote-backup"
|
||||||
|
style="height: 23px;line-height: 21px;"
|
||||||
|
class="btn btn-border btn-alt border-red btn-link font-red"
|
||||||
|
title=""><span>{% trans "Remote Backups" %}</span></a></h2>
|
||||||
<p>{% trans "On this page you can schedule Back ups to localhost or remote server (If you have added one)." %}</p>
|
<p>{% trans "On this page you can schedule Back ups to localhost or remote server (If you have added one)." %}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div ng-controller="scheduleBackup" class="panel">
|
<div ng-controller="scheduleBackup" class="panel">
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<h3 class="title-hero">
|
<h3 class="title-hero">
|
||||||
{% trans "Schedule Back up" %} <img ng-hide="scheduleBackupLoading" src="{% static 'images/loading.gif' %}">
|
{% trans "Schedule Back up" %} <img ng-hide="scheduleBackupLoading"
|
||||||
|
src="{% static 'images/loading.gif' %}">
|
||||||
</h3>
|
</h3>
|
||||||
<div class="example-box-wrapper">
|
<div class="example-box-wrapper">
|
||||||
|
|
||||||
@@ -46,12 +50,21 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div ng-hide="localPath" class="form-group">
|
||||||
|
<label class="col-sm-3 control-label">{% trans "Local Path" %}</label>
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<input name="dom" type="text" class="form-control" ng-model="localPathValue"
|
||||||
|
placeholder="{% trans "Local directory where backups will be moved after creation." %}"
|
||||||
|
required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div ng-hide="scheduleBtn" class="form-group">
|
<div ng-hide="scheduleBtn" class="form-group">
|
||||||
<label class="col-sm-3 control-label"></label>
|
<label class="col-sm-3 control-label"></label>
|
||||||
<div class="col-sm-4">
|
<div class="col-sm-4">
|
||||||
<button type="button" ng-click="addSchedule()" class="btn btn-primary btn-lg btn-block">{% trans "Add Destination" %}</button>
|
<button type="button" ng-click="addSchedule()"
|
||||||
|
class="btn btn-primary btn-lg btn-block">{% trans "Add Destination" %}</button>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -97,7 +110,8 @@
|
|||||||
<td ng-bind="record.id"></td>
|
<td ng-bind="record.id"></td>
|
||||||
<td ng-bind="record.destLoc"></td>
|
<td ng-bind="record.destLoc"></td>
|
||||||
<td ng-bind="record.frequency"></td>
|
<td ng-bind="record.frequency"></td>
|
||||||
<td ng-click="delSchedule(record.destLoc,record.frequency)"><img src="{% static 'images/delete.png' %}"></td>
|
<td ng-click="delSchedule(record.destLoc,record.frequency)"><img
|
||||||
|
src="{% static 'images/delete.png' %}"></td>
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
@@ -111,7 +125,6 @@
|
|||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -14,13 +14,12 @@ from backupUtilities import backupUtilities
|
|||||||
from re import match,I,M
|
from re import match,I,M
|
||||||
from websiteFunctions.models import Websites, Backups
|
from websiteFunctions.models import Websites, Backups
|
||||||
from plogical.processUtilities import ProcessUtilities
|
from plogical.processUtilities import ProcessUtilities
|
||||||
from multiprocessing import Process
|
|
||||||
import plogical.backupUtilities as backupUtil
|
|
||||||
from random import randint
|
from random import randint
|
||||||
import json, requests
|
import json, requests
|
||||||
|
|
||||||
class backupSchedule:
|
class backupSchedule:
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def remoteBackupLogging(fileName, message):
|
def remoteBackupLogging(fileName, message):
|
||||||
try:
|
try:
|
||||||
@@ -88,6 +87,7 @@ class backupSchedule:
|
|||||||
os.remove(pathToFile)
|
os.remove(pathToFile)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(tempStoragePath)
|
||||||
return 1, tempStoragePath
|
return 1, tempStoragePath
|
||||||
|
|
||||||
elif status.find("[5009]") > -1:
|
elif status.find("[5009]") > -1:
|
||||||
@@ -117,7 +117,7 @@ class backupSchedule:
|
|||||||
return 0, tempStoragePath
|
return 0, tempStoragePath
|
||||||
except BaseException, msg:
|
except BaseException, msg:
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [119:startBackup]")
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [119:startBackup]")
|
||||||
return 0, "None"
|
return 0, str(msg)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def createBackup(virtualHost, ipAddress, backupLogPath , port):
|
def createBackup(virtualHost, ipAddress, backupLogPath , port):
|
||||||
|
|||||||
@@ -2,8 +2,11 @@ import CyberCPLogFileWriter as logging
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
from backupSchedule import backupSchedule
|
from backupSchedule import backupSchedule
|
||||||
|
from plogical.processUtilities import ProcessUtilities
|
||||||
|
from re import match,I,M
|
||||||
|
|
||||||
class backupScheduleLocal:
|
class backupScheduleLocal:
|
||||||
|
localBackupPath = '/home/cyberpanel/localBackupPath'
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def prepare():
|
def prepare():
|
||||||
@@ -20,7 +23,20 @@ class backupScheduleLocal:
|
|||||||
backupSchedule.remoteBackupLogging(backupLogPath, "")
|
backupSchedule.remoteBackupLogging(backupLogPath, "")
|
||||||
|
|
||||||
for virtualHost in os.listdir("/home"):
|
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, "")
|
||||||
backupSchedule.remoteBackupLogging(backupLogPath, "")
|
backupSchedule.remoteBackupLogging(backupLogPath, "")
|
||||||
|
|||||||
Reference in New Issue
Block a user