cyberpanel_snapshots_Restore
This commit is contained in:
parent
3742776b12
commit
f70ee3c73a
|
|
@ -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 = '<tr style="">\n' +
|
||||
|
|
@ -1372,14 +1476,14 @@ app.controller('restorev2backupoage', function ($scope, $http, $timeout, $compil
|
|||
' <button id="' + snapshots[i][1][j].id + 'button" class="my-4 mx-4 btn " style="margin-bottom: 15px;margin-top: -8px;background-color: #161a69; color: white;border-radius: 6px" onclick=listpaths("' + snapshots[i][1][j].id + '","' + snapshots[i][1][j].id + 'button")>+</button>\n' +
|
||||
'</td></tr>' +
|
||||
'<tr style="border: none!important;">' +
|
||||
' <td colspan="2" style="display: none;border: none" id="' + snapshots[i][1][j].id+ '">' +
|
||||
' <td colspan="2" style="display: none;border: none" id="' + snapshots[i][1][j].id + '">' +
|
||||
' <table id="inside" style="margin: 0 auto; margin-bottom: 30px;border: 1px #ccc solid;">\n';
|
||||
|
||||
for (var k = 0; k < snapshots[i][1][j].paths.length; k++) {
|
||||
tml += '<tr style="border-top: 1px #cccccc solid;display: flex;padding: 15px; justify-content: space-between;">\n' +
|
||||
'<td style="">' + snapshots[i][1][j].paths[k] + '</td>\n' +
|
||||
'<td style="">' +
|
||||
'<button id="' + snapshots[i][1][j].paths[k] + '" style="margin-inline: 30px; color: white!important; background-color: #3051be; border-radius: 6px;" class="btn" ng-click=\'RestorePathV2("' + snapshots[i][1][j].id + '","' + snapshots[i][1][j].paths[k] + '")\'>Restore</button></td>\n' +
|
||||
'<button id="' + snapshots[i][1][j].paths[k] + '" style="margin-inline: 30px; color: white!important; background-color: #3051be; border-radius: 6px;" class="btn" ng-click=\'RestorePathV2Model("' + snapshots[i][1][j].id + '","' + snapshots[i][1][j].paths[k] + '")\'>Restore</button></td>\n' +
|
||||
'</tr>\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";
|
||||
|
|
|
|||
|
|
@ -72,6 +72,87 @@
|
|||
|
||||
</table>
|
||||
</div>
|
||||
<div id="RestoreSnapshotPath" class="modal fade" role="dialog">
|
||||
<div class="modal-dialog modal-lg">
|
||||
|
||||
<!-- Modal content-->
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal">×
|
||||
</button>
|
||||
<h4 id="restore_header_text" class="modal-title">{% trans "Restore" %}</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
|
||||
<span style="font-weight: bolder">ID: <span style="font-weight: normal" id="Snapshot_id"></span></span><br>
|
||||
<span style="font-weight: bolder">PATH: <span style="font-weight: normal" id="Snapshot_Path_id"></span></span><br>
|
||||
<span style="display: flex;justify-content: center;margin-top: 20px;font-weight: bolder">Are You to Restore Backup </span>
|
||||
<div style="display: flex;justify-content: center;margin-top: 10px;margin-bottom: 20px">
|
||||
<button type="button" class="btn btn-primary "style="margin-right: 20px!important;"
|
||||
ng-click="RestorePathV2()">Yes <img
|
||||
ng-hide="cyberpanelLoading"
|
||||
src="">
|
||||
</button>
|
||||
<button type="button" ng-disabled="savingSettings"
|
||||
class="btn btn-default mx-3" data-dismiss="modal">
|
||||
No
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div ng-hide="installationProgress" class="form-group">
|
||||
<label class="col-sm-2 control-label"></label>
|
||||
<div class="col-sm-7">
|
||||
|
||||
<div class="alert alert-success text-center">
|
||||
<h2>{$ currentStatus $}</h2>
|
||||
</div>
|
||||
|
||||
<div class="progress">
|
||||
<div id="installProgress" class="progress-bar" role="progressbar" aria-valuenow="70"
|
||||
aria-valuemin="0" aria-valuemax="100" style="width:0%">
|
||||
<span class="sr-only">70% Complete</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div ng-hide="errorMessageBox" class="alert alert-danger">
|
||||
<p>{% trans "Error message:" %} {$ errorMessage $}</p>
|
||||
</div>
|
||||
|
||||
<div ng-hide="success" class="alert alert-success">
|
||||
<p>{% trans "Backup succesfully." %}</p>
|
||||
</div>
|
||||
|
||||
|
||||
<div ng-hide="couldNotConnect" class="alert alert-danger">
|
||||
<p>{% trans "Could not connect to server. Please refresh this page." %}</p>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div ng-hide="installationProgress" class="form-group">
|
||||
<label class="col-sm-3 control-label"></label>
|
||||
<div class="col-sm-4">
|
||||
<button type="button" ng-disabled="goBackDisable" ng-click="goBack()"
|
||||
class="btn btn-primary btn-lg">{% trans "Go Back" %}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
{# <button type="button" class="btn btn-primary"#}
|
||||
{# ng-click="setupAccount()">Save <img#}
|
||||
{# ng-hide="cyberpanelLoading"#}
|
||||
{# src="">#}
|
||||
{# </button>#}
|
||||
<button type="button" ng-disabled="savingSettings"
|
||||
class="btn btn-default" data-dismiss="modal">
|
||||
Close
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Reference in New Issue