diff --git a/IncBackups/static/IncBackups/IncBackups.js b/IncBackups/static/IncBackups/IncBackups.js index 2eab7ff25..ea2603ebd 100644 --- a/IncBackups/static/IncBackups/IncBackups.js +++ b/IncBackups/static/IncBackups/IncBackups.js @@ -1205,6 +1205,11 @@ app.controller('restorev2backupoage', function ($scope, $http, $timeout, $compil $scope.backupLoading = true; + $scope.installationProgress = true; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; $scope.selectwebsite = function () { document.getElementById('reposelectbox').innerHTML = ""; @@ -1286,17 +1291,21 @@ app.controller('restorev2backupoage', function ($scope, $http, $timeout, $compil } } - $scope.RestorePathV2 = function (SnapshotId, Path) { + $scope.RestorePathV2Model = function (SnapshotId, Path) { + $('#RestoreSnapshotPath').modal('show'); + + document.getElementById('Snapshot_id').innerText = SnapshotId + document.getElementById('Snapshot_Path_id').innerText = Path + + + } + function getCreationStatus() { + + url = "/IncrementalBackups/CreateV2BackupStatus"; - console.log("SnapshotId: " + SnapshotId) - console.log("Path: " + Path) - var url = "/IncrementalBackups/RestorePathV2"; var data = { - snapshotid: SnapshotId, - path: Path, - selwebsite: $scope.selwebsite, - selectedrepo:$('#reposelectbox').val() - } + domain: Domain + }; var config = { headers: { @@ -1310,13 +1319,111 @@ app.controller('restorev2backupoage', function ($scope, $http, $timeout, $compil function ListInitialDatas(response) { + if (response.data.abort === 1) { + + if (response.data.installStatus === 1) { + + $scope.webSiteCreationLoading = true; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = false; + $scope.couldNotConnect = true; + $scope.goBackDisable = false; + + $("#installProgress").css("width", "100%"); + $scope.installPercentage = "100"; + $scope.currentStatus = response.data.currentStatus; + $timeout.cancel(); + + } else { + $scope.webSiteCreationLoading = true; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = false; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = false; + + $scope.errorMessage = response.data.error_message; + + $("#installProgress").css("width", "0%"); + $scope.installPercentage = "0"; + $scope.goBackDisable = false; + + } + + } else { + $scope.webSiteCreationLoading = false; + $("#installProgress").css("width", response.data.installationProgress + "%"); + $scope.installPercentage = response.data.installationProgress; + $scope.currentStatus = response.data.currentStatus; + $timeout(getCreationStatus, 1000); + } + + } + + function cantLoadInitialDatas(response) { + + $scope.webSiteCreationLoading = true; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = false; + $scope.goBackDisable = false; + + } + + + } + $scope.RestorePathV2 = function (SnapshotId, Path) { + + SnapshotId = document.getElementById('Snapshot_id').innerText + Path = document.getElementById('Snapshot_Path_id').innerText + console.log("SnapshotId: " + SnapshotId) + console.log("Path: " + Path) + var url = "/IncrementalBackups/RestorePathV2"; + var data = { + snapshotid: SnapshotId, + path: Path, + selwebsite: $scope.selwebsite, + selectedrepo: $('#reposelectbox').val() + } + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { if (response.data.status === 1) { $scope.SnapShotId = response.data.SnapShotId; $scope.tempPath = response.data.Path; + console.log("Returned ID on ListInitialDatas: " + $scope.SnapShotId) console.log("Returned PATH on ListInitialDatas: " + $scope.tempPath) + + Domain = $scope.selwebsite; + getCreationStatus(); + + } else { + $scope.backupLoading = true; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = false; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = false; + + $scope.errorMessage = response.data.error_message; } } @@ -1355,12 +1462,9 @@ app.controller('restorev2backupoage', function ($scope, $http, $timeout, $compil var data = response.data.data - console.log(response.data.data) var snapshots = response.data.data - console.log("length 0 : "+snapshots.length) - console.log("length 0 1 : "+snapshots[0][1].length) - console.log("length 1 1 : "+snapshots[1][1].length) + for (var i = 0; i < snapshots.length; i++) { for (var j = 0; j < snapshots[i][1].length; j++) { var tml = '\n' + @@ -1372,14 +1476,14 @@ app.controller('restorev2backupoage', function ($scope, $http, $timeout, $compil ' \n' + '' + '' + - ' ' + + ' ' + ' \n'; for (var k = 0; k < snapshots[i][1][j].paths.length; k++) { tml += '\n' + '\n' + '\n' + + '\n' + '\n'; } @@ -1525,15 +1629,15 @@ app.controller('CreateV2Backup', function ($scope, $http, $timeout, $compile) { if (websiteData === true || websiteDatabases === true || websiteEmails === true) { chk = 1; } - var data ={}; + var data = {}; - data = { + data = { Selectedwebsite: $scope.selwebsite, Selectedrepo: $('#reposelectbox').val(), - websiteDatabases: websiteDatabases, - websiteEmails: websiteEmails, - websiteData: websiteData, + websiteDatabases: websiteDatabases, + websiteEmails: websiteEmails, + websiteData: websiteData, }; @@ -1741,8 +1845,6 @@ app.controller('ConfigureV2Backup', function ($scope, $http, $timeout) { function listpaths(pathid, button) { - console.log("ID of button used to hide " + button); - console.log(" ID of container which we hide on button press" + pathid); var pathlist = document.getElementById(pathid) if (pathlist.style.display === "none") { pathlist.style.display = "revert"; diff --git a/IncBackups/templates/IncBackups/RestoreV2Backup.html b/IncBackups/templates/IncBackups/RestoreV2Backup.html index 08588b585..0b3b37b72 100644 --- a/IncBackups/templates/IncBackups/RestoreV2Backup.html +++ b/IncBackups/templates/IncBackups/RestoreV2Backup.html @@ -72,6 +72,87 @@
' + snapshots[i][1][j].paths[k] + '' + - '
+ diff --git a/IncBackups/views.py b/IncBackups/views.py index 054ea1069..389d3658a 100644 --- a/IncBackups/views.py +++ b/IncBackups/views.py @@ -853,21 +853,35 @@ def RestorePathV2(request): else: return ACLManager.loadError() - vm = CPBackupsV2({'domain': Selectedwebsite, 'BackendName': Selectedrepo, "function": "", 'BasePath': '/home/backup'}) - status = vm.InitiateRestore(SnapShotId, Path) + extra_args = {} + extra_args['function'] = 'InitiateRestore' + extra_args['website'] = Selectedwebsite + extra_args['domain'] = Selectedwebsite + extra_args['BasePath'] = '/home/backup' + extra_args['BackendName'] = Selectedrepo + extra_args['path'] = Path + extra_args['snapshotid'] = SnapShotId + # extra_args['BackupData'] = data['websiteData'] if 'websiteData' in data else False + # extra_args['BackupEmails'] = data['websiteEmails'] if 'websiteEmails' in data else False + # extra_args['BackupDatabase'] = data['websiteDatabases'] if 'websiteDatabases' in data else False - if status == 1: - final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'error_message': "None"}) - return HttpResponse(final_json) - else: - # final_json = json.dumps({'status': 0, 'fetchStatus': 1, 'error_message': ac,}) - final_json = json.dumps({'status': 0, 'fetchStatus': 1, 'error_message': 'Cannot Find!', }) - return HttpResponse(final_json) + + background = CPBackupsV2(extra_args) + background.start() + + # vm = CPBackupsV2({'domain': Selectedwebsite, 'BackendName': Selectedrepo, "function": "", 'BasePath': '/home/backup'}) + # status = vm.InitiateRestore(SnapShotId, Path) + + time.sleep(2) + + data_ret = {'status': 1, 'installStatus': 1, 'error_message': 'None',} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) except BaseException as msg: - final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)} - final_json = json.dumps(final_dic) - return HttpResponse(final_json) + data_ret = {'status': 0, 'installStatus': 0, 'error_message': str(msg)} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) def selectwebsiteRetorev2(request): import re diff --git a/plogical/Backupsv2.py b/plogical/Backupsv2.py index a9c1bdc68..09040656c 100644 --- a/plogical/Backupsv2.py +++ b/plogical/Backupsv2.py @@ -74,6 +74,9 @@ class CPBackupsV2(multi.Thread): try: if self.function == 'InitiateBackup': self.InitiateBackup() + elif self.function == 'InitiateRestore': + self.InitiateRestore() + except BaseException as msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + ' [CPBackupsV2.run]') @@ -635,7 +638,7 @@ token = {token} #### Resote Functions - def InitiateRestore(self, snapshotid, path): + def InitiateRestore(self): ### if restore then status file should be restore status file @@ -693,16 +696,16 @@ token = {token} ### Find Restore path first, if path is db, only then restore it to cp - if path.find('.sql') > -1: - mysqlUtilities.restoreDatabaseBackup(path.rstrip('.sql'), None, None, None, None, 1, self.repo, self.website.externalApp, snapshotid) + if self.path.find('.sql') > -1: + mysqlUtilities.restoreDatabaseBackup(self.path.rstrip('.sql'), None, None, None, None, 1, self.repo, self.website.externalApp, self.snapshotid) else: - if path.find('/home/vmail') > -1: + if self.path.find('/home/vmail') > -1: externalApp = None else: externalApp = self.website.externalApp - command = f'rustic -r {self.repo} restore {snapshotid}:{path} {path} --password "" --json 2>/dev/null' + command = f'rustic -r {self.repo} restore {self.snapshotid}:{self.path} {self.path} --password "" --json 2>/dev/null' result = ProcessUtilities.outputExecutioner(command, externalApp, True) if os.path.exists(ProcessUtilities.debugPath):