bug fixes to v2 backups

This commit is contained in:
usman@cyberpersons.com
2023-04-11 03:05:49 +05:00
parent c08a477e88
commit db6762ebdf
6 changed files with 77 additions and 66 deletions

View File

@@ -1321,7 +1321,7 @@ app.controller('restorev2backupoage', function ($scope, $http, $timeout, $compil
function ListInitialDatas(response) {
if (response.data.abort === 1) {
$scope.backupLoading = true;
if (response.data.installStatus === 1) {
$scope.webSiteCreationLoading = true;
@@ -1338,6 +1338,7 @@ app.controller('restorev2backupoage', function ($scope, $http, $timeout, $compil
$timeout.cancel();
} else {
$scope.backupLoading = true;
$scope.webSiteCreationLoading = true;
$scope.installationDetailsForm = true;
$scope.installationProgress = false;
@@ -1381,6 +1382,8 @@ app.controller('restorev2backupoage', function ($scope, $http, $timeout, $compil
$scope.RestorePathV2 = function (SnapshotId, Path) {
$scope.backupLoading = false;
SnapshotId = document.getElementById('Snapshot_id').innerText
Path = document.getElementById('Snapshot_Path_id').innerText
console.log("SnapshotId: " + SnapshotId)
@@ -1663,7 +1666,6 @@ app.controller('CreateV2Backup', function ($scope, $http, $timeout, $compile) {
function ListInitialDatas(response) {
$scope.backupLoading = true;
if (response.data.status === 1) {
Domain = $scope.selwebsite;
@@ -1715,7 +1717,7 @@ app.controller('CreateV2Backup', function ($scope, $http, $timeout, $compile) {
function ListInitialDatas(response) {
if (response.data.abort === 1) {
$scope.backupLoading = true;
if (response.data.installStatus === 1) {
$scope.webSiteCreationLoading = true;

View File

@@ -13,7 +13,7 @@
<div ng-controller="ConfigureV2Backup" class="panel">
<div class="panel-body">
<h3 class="title-hero">
{% trans "Backup V2" %} <img ng-hide="cyberpanelLoading"
{% trans "Configure v2 Backup Destinations" %} <img ng-hide="cyberpanelLoading"
src="{% static 'images/loading.gif' %}">
</h3>
<div class="example-box-wrapper">

View File

@@ -13,14 +13,14 @@
<div class="container">
<div id="page-title">
<h2>{% trans "Restore V2 Backup Site" %} - <a target="_blank" href="http://go.cyberpanel.net/backup" style="height: 23px;line-height: 21px;" class="btn btn-border btn-alt border-red btn-link font-red" title=""><span>{% trans "Backup Docs" %}</span></a></h2>
<h2>{% trans "Restore V2 Backups" %} - <a target="_blank" href="http://go.cyberpanel.net/backup" style="height: 23px;line-height: 21px;" class="btn btn-border btn-alt border-red btn-link font-red" title=""><span>{% trans "Backup Docs" %}</span></a></h2>
<p>{% trans "This page can be used to restore your backup sites" %}</p>
</div>
<div ng-controller="restorev2backupoage" class="panel">
<div class="panel-body">
<h3 class="title-hero">
{% trans "Restore V2 Backup Site" %} <img ng-hide="backupLoading" src="{% static 'images/loading.gif' %}">
{% trans "Restore V2 Backups" %} <img ng-hide="backupLoading" src="{% static 'images/loading.gif' %}">
</h3>
<div class="example-box-wrapper">
@@ -80,17 +80,17 @@
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;
</button>
<h4 id="restore_header_text" class="modal-title">{% trans "Restore" %}</h4>
<h4 id="restore_header_text" class="modal-title">{% trans "Restore" %} <img ng-hide="backupLoading" src="{% static 'images/loading.gif' %}"></h4>
</div>
<div class="modal-body" style="">
<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>
<span style="display: flex;justify-content: center;margin-top: 20px;font-weight: bolder">{% trans "Are you ready to restore the backup? This may overwrite existing files." %} </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"
ng-hide="backupLoading"
src="">
</button>
<button type="button" ng-disabled="savingSettings"

View File

@@ -836,7 +836,6 @@ def RestoreV2backupSite(request):
return redirect(loadLoginPage)
def RestorePathV2(request):
import re
try:
userID = request.session['userID']
data = json.loads(request.body)

View File

@@ -704,7 +704,8 @@ team_drive =
def RestoreConfig(self):
try:
self.UpdateStatus(f'Restoring config..,10',
CPBackupsV2.RUNNING)
ConfigPath = f'/home/backup/{self.website.domain}/config.json'
RestoreConfigPath = f'/home/{self.website.domain}/'
@@ -748,8 +749,9 @@ team_drive =
for record in ConfigContent['DNSRecords']:
DNS.createDNSRecord(zone, record['name'], record['type'], record['content'], 0, record['ttl'])
except:
pass
except BaseException as msg:
self.UpdateStatus(f'Error in RestoreConfig while restoring dns config. Error: {str(msg)}',
CPBackupsV2.RUNNING)
### Create Emails Accounts
@@ -760,7 +762,6 @@ team_drive =
try:
from plogical.mailUtilities import mailUtilities
for emailAccount in ConfigContent['EmailAddresses']:
email = emailAccount['email']
@@ -788,76 +789,83 @@ team_drive =
# logging.statusWriter(statusPath,
# 'Email created: %s' % (
# email))
except:
pass
except BaseException as msg:
self.UpdateStatus(f'Error in RestoreConfig while restoring email config. Error: {str(msg)}',
CPBackupsV2.RUNNING)
### Restoring DBs
from databases.models import Databases, DatabasesUsers
try:
for database in ConfigContent['databases']:
from databases.models import Databases, DatabasesUsers
dbName = list(database.keys())[0]
for database in ConfigContent['databases']:
if os.path.exists(ProcessUtilities.debugPath):
logging.CyberCPLogFileWriter.writeToFile(f'Databasename: {dbName}')
first = 1
databaseUsers = database[dbName]
for databaseUser in databaseUsers:
dbUser = databaseUser['user']
dbHost = databaseUser['host']
password = databaseUser['password']
dbName = list(database.keys())[0]
if os.path.exists(ProcessUtilities.debugPath):
logging.CyberCPLogFileWriter.writeToFile('Database user: %s' % (dbUser))
logging.CyberCPLogFileWriter.writeToFile('Database host: %s' % (dbHost))
logging.CyberCPLogFileWriter.writeToFile('Database password: %s' % (password))
logging.CyberCPLogFileWriter.writeToFile(f'Databasename: {dbName}')
if first:
first = 1
first = 0
databaseUsers = database[dbName]
try:
dbExist = Databases.objects.get(dbName=dbName)
logging.CyberCPLogFileWriter.writeToFile('Database exists, changing Database password.. %s' % (dbName))
for databaseUser in databaseUsers:
if mysqlUtilities.mysqlUtilities.changePassword(dbUser, password, 1, dbHost) == 0:
logging.CyberCPLogFileWriter.writeToFile('Failed changing password for database: %s' % (dbName))
else:
logging.CyberCPLogFileWriter.writeToFile('Password successfully changed for database: %s.' % (dbName))
dbUser = databaseUser['user']
dbHost = databaseUser['host']
password = databaseUser['password']
except:
if os.path.exists(ProcessUtilities.debugPath):
logging.CyberCPLogFileWriter.writeToFile('Database user: %s' % (dbUser))
logging.CyberCPLogFileWriter.writeToFile('Database host: %s' % (dbHost))
logging.CyberCPLogFileWriter.writeToFile('Database password: %s' % (password))
logging.CyberCPLogFileWriter.writeToFile('Database did not exist, creating new.. %s' % (dbName))
if first:
if mysqlUtilities.mysqlUtilities.createDatabase(dbName, dbUser, "cyberpanel") == 0:
logging.CyberCPLogFileWriter.writeToFile('Failed the creation of database: %s' % (dbName))
else:
logging.CyberCPLogFileWriter.writeToFile('Database: %s successfully created.' % (dbName))
mysqlUtilities.mysqlUtilities.changePassword(dbUser, password, 1)
if mysqlUtilities.mysqlUtilities.changePassword(dbUser, password, 1) == 0:
logging.CyberCPLogFileWriter.writeToFile('Failed changing password for database: %s' % (dbName))
else:
logging.CyberCPLogFileWriter.writeToFile(
'Password successfully changed for database: %s.' % (dbName))
first = 0
try:
newDB = Databases(website=self.website, dbName=dbName, dbUser=dbUser)
newDB.save()
dbExist = Databases.objects.get(dbName=dbName)
logging.CyberCPLogFileWriter.writeToFile('Database exists, changing Database password.. %s' % (dbName))
if mysqlUtilities.mysqlUtilities.changePassword(dbUser, password, 1, dbHost) == 0:
logging.CyberCPLogFileWriter.writeToFile('Failed changing password for database: %s' % (dbName))
else:
logging.CyberCPLogFileWriter.writeToFile('Password successfully changed for database: %s.' % (dbName))
except:
pass
## This function will not create database, only database user is created as third value is 0 for createDB
logging.CyberCPLogFileWriter.writeToFile('Database did not exist, creating new.. %s' % (dbName))
mysqlUtilities.mysqlUtilities.createDatabase(dbName, dbUser, password, 0, dbHost)
mysqlUtilities.mysqlUtilities.changePassword(dbUser, password, 1, dbHost)
if mysqlUtilities.mysqlUtilities.createDatabase(dbName, dbUser, "cyberpanel") == 0:
logging.CyberCPLogFileWriter.writeToFile('Failed the creation of database: %s' % (dbName))
else:
logging.CyberCPLogFileWriter.writeToFile('Database: %s successfully created.' % (dbName))
mysqlUtilities.mysqlUtilities.changePassword(dbUser, password, 1)
if mysqlUtilities.mysqlUtilities.changePassword(dbUser, password, 1) == 0:
logging.CyberCPLogFileWriter.writeToFile('Failed changing password for database: %s' % (dbName))
else:
logging.CyberCPLogFileWriter.writeToFile(
'Password successfully changed for database: %s.' % (dbName))
try:
newDB = Databases(website=self.website, dbName=dbName, dbUser=dbUser)
newDB.save()
except:
pass
## This function will not create database, only database user is created as third value is 0 for createDB
mysqlUtilities.mysqlUtilities.createDatabase(dbName, dbUser, password, 0, dbHost)
mysqlUtilities.mysqlUtilities.changePassword(dbUser, password, 1, dbHost)
except BaseException as msg:
self.UpdateStatus(f'Error in RestoreConfig while restoring database config. Error: {str(msg)}', CPBackupsV2.RUNNING)
return 1, None
except BaseException as msg:
return 0, str(msg)
@@ -923,7 +931,11 @@ team_drive =
### Find Restore path first, if path is db, only then restore it to cp
self.RestoreConfig()
status, message = self.RestoreConfig()
if status == 0:
self.UpdateStatus(f'Failed to restore config, Error {message}',
CPBackupsV2.FAILED)
return 0
if self.data["path"].find('.sql') > -1:
mysqlUtilities.restoreDatabaseBackup(self.data["path"].rstrip('.sql'), None, None, None, None, 1,

View File

@@ -1,2 +0,0 @@
LaterCommand = """awk '/access_token/ {print $3}' | sed 's/[",]//g'"""
print(LaterCommand)