mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-08 22:36:12 +01:00
complete restore of cloudbackup
This commit is contained in:
@@ -1664,8 +1664,11 @@ class CloudManager:
|
|||||||
|
|
||||||
backupDomain = self.data['domainName']
|
backupDomain = self.data['domainName']
|
||||||
backupsPath = '/home/cyberpanel/backups/%s/' % (backupDomain)
|
backupsPath = '/home/cyberpanel/backups/%s/' % (backupDomain)
|
||||||
backups = os.listdir(backupsPath)
|
try:
|
||||||
backups.reverse()
|
backups = os.listdir(backupsPath)
|
||||||
|
backups.reverse()
|
||||||
|
except:
|
||||||
|
backups = []
|
||||||
|
|
||||||
json_data = "["
|
json_data = "["
|
||||||
checker = 0
|
checker = 0
|
||||||
@@ -1732,3 +1735,40 @@ class CloudManager:
|
|||||||
data_ret = {'status': 0, 'abort': 0, 'installationProgress': "0", 'errorMessage': str(msg)}
|
data_ret = {'status': 0, 'abort': 0, 'installationProgress': "0", 'errorMessage': str(msg)}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
def deleteCloudBackup(self):
|
||||||
|
try:
|
||||||
|
|
||||||
|
backupDomain = self.data['domainName']
|
||||||
|
backupFile = self.data['backupFile']
|
||||||
|
backupsPathComplete = '/home/cyberpanel/backups/%s/%s' % (backupDomain, backupFile)
|
||||||
|
|
||||||
|
command = 'rm -f %s' % (backupsPathComplete)
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'error_message': "None"})
|
||||||
|
return HttpResponse(final_json)
|
||||||
|
except BaseException as msg:
|
||||||
|
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
|
||||||
|
final_json = json.dumps(final_dic)
|
||||||
|
return HttpResponse(final_json)
|
||||||
|
|
||||||
|
def SubmitCloudBackupRestore(self):
|
||||||
|
try:
|
||||||
|
|
||||||
|
tempStatusPath = "/home/cyberpanel/" + str(randint(1000, 9999))
|
||||||
|
|
||||||
|
writeToFile = open(tempStatusPath, 'w')
|
||||||
|
writeToFile.write('Starting..,0')
|
||||||
|
writeToFile.close()
|
||||||
|
|
||||||
|
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py"
|
||||||
|
execPath = execPath + " SubmitCloudBackupRestore --backupDomain %s --backupFile %s --tempStoragePath %s" % (self.data['domain'], self.data['backupFile'], tempStatusPath)
|
||||||
|
ProcessUtilities.popenExecutioner(execPath)
|
||||||
|
|
||||||
|
final_dic = {'status': 1, 'tempStatusPath': tempStatusPath}
|
||||||
|
final_json = json.dumps(final_dic)
|
||||||
|
return HttpResponse(final_json)
|
||||||
|
|
||||||
|
except BaseException as msg:
|
||||||
|
return self.ajaxPre(0, str(msg))
|
||||||
|
|||||||
@@ -59,6 +59,10 @@ def router(request):
|
|||||||
return cm.fetchCloudBackupSettings()
|
return cm.fetchCloudBackupSettings()
|
||||||
elif controller == 'saveCloudBackupSettings':
|
elif controller == 'saveCloudBackupSettings':
|
||||||
return cm.saveCloudBackupSettings()
|
return cm.saveCloudBackupSettings()
|
||||||
|
elif controller == 'deleteCloudBackup':
|
||||||
|
return cm.deleteCloudBackup()
|
||||||
|
elif controller == 'SubmitCloudBackupRestore':
|
||||||
|
return cm.SubmitCloudBackupRestore()
|
||||||
elif controller == 'fetchWebsites':
|
elif controller == 'fetchWebsites':
|
||||||
return cm.fetchWebsites()
|
return cm.fetchWebsites()
|
||||||
elif controller == 'fetchWebsiteDataJSON':
|
elif controller == 'fetchWebsiteDataJSON':
|
||||||
|
|||||||
@@ -1279,7 +1279,7 @@ class backupUtilities:
|
|||||||
|
|
||||||
self.CheckIfSleepNeeded()
|
self.CheckIfSleepNeeded()
|
||||||
|
|
||||||
command = 'nice -n %s cp -R %s %s' % (self.nice, self.DataPath, self.BackupDataPath)
|
command = 'nice -n %s cp -Rp %s %s' % (self.nice, self.DataPath, self.BackupDataPath)
|
||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
## Store child domains if any in json format
|
## Store child domains if any in json format
|
||||||
@@ -1289,7 +1289,7 @@ class backupUtilities:
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
for child in self.website.childdomains_set.all():
|
for child in self.website.childdomains_set.all():
|
||||||
childs.append(child.domain)
|
childs.append({'domain': child.domain, 'path': child.path, 'php': child.phpSelection})
|
||||||
|
|
||||||
DataJson['ChildDomains'] = childs
|
DataJson['ChildDomains'] = childs
|
||||||
|
|
||||||
@@ -1322,7 +1322,7 @@ class backupUtilities:
|
|||||||
|
|
||||||
self.CheckIfSleepNeeded()
|
self.CheckIfSleepNeeded()
|
||||||
|
|
||||||
command = 'nice -n %s cp -R %s %s' % (self.nice, self.DataPath, self.BackupDataPath)
|
command = 'nice -n %s cp -Rp %s %s' % (self.nice, self.DataPath, self.BackupDataPath)
|
||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
## Store child domains if any in json format
|
## Store child domains if any in json format
|
||||||
@@ -1476,6 +1476,137 @@ class backupUtilities:
|
|||||||
command = 'rm -rf %s' % (self.BackupPath)
|
command = 'rm -rf %s' % (self.BackupPath)
|
||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], 'Completed [200].')
|
||||||
|
|
||||||
|
## Restore functions
|
||||||
|
|
||||||
|
def SubmitCloudBackupRestore(self):
|
||||||
|
import json
|
||||||
|
if os.path.exists(backupUtilities.CloudBackupConfigPath):
|
||||||
|
result = json.loads(open(backupUtilities.CloudBackupConfigPath, 'r').read())
|
||||||
|
self.nice = result['nice']
|
||||||
|
self.cpu = result['cpu']
|
||||||
|
self.time = int(result['time'])
|
||||||
|
else:
|
||||||
|
self.nice = backupUtilities.NiceDefault
|
||||||
|
self.cpu = backupUtilities.CPUDefault
|
||||||
|
self.time = int(backupUtilities.time)
|
||||||
|
|
||||||
|
self.BackupPath = '/home/cyberpanel/backups/%s/%s' % (self.extraArgs['domain'], self.extraArgs['backupFile'])
|
||||||
|
self.website = Websites.objects.get(domain=self.extraArgs['domain'])
|
||||||
|
|
||||||
|
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
|
||||||
|
'Extracting main archive..,0')
|
||||||
|
|
||||||
|
|
||||||
|
command = 'tar -xf %s -C %s' % (self.BackupPath, '/home/cyberpanel/backups/%s/' % (self.extraArgs['domain']))
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
|
||||||
|
'Main Archive extracted,20')
|
||||||
|
|
||||||
|
self.extractedPath = '/home/cyberpanel/backups/%s/%s' % (self.extraArgs['domain'], self.extraArgs['backupFile'].rstrip('.tar.gz'))
|
||||||
|
|
||||||
|
self.dataPath = '%s/data' % (self.extractedPath)
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile('Data path: %s' % (self.dataPath))
|
||||||
|
self.databasesPath = '%s/databases' % (self.extractedPath)
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile('Databases path: %s' % (self.databasesPath))
|
||||||
|
self.emailsPath = '%s/emails' % (self.extractedPath)
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile('Emails path: %s' % (self.emailsPath))
|
||||||
|
|
||||||
|
## Data
|
||||||
|
|
||||||
|
if os.path.exists(self.dataPath):
|
||||||
|
try:
|
||||||
|
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
|
||||||
|
'Creating child domains if any..,20')
|
||||||
|
childDomains = json.loads(open('%s/data.json' % (self.extractedPath), 'r').read())['ChildDomains']
|
||||||
|
|
||||||
|
for child in childDomains:
|
||||||
|
try:
|
||||||
|
ch = ChildDomains.objects.get(domain=child['domain'])
|
||||||
|
except:
|
||||||
|
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
|
||||||
|
'Creating %s,20' % (child['domain']))
|
||||||
|
virtualHostUtilities.createDomain(self.website.domain, child['domain'], child['php'], child['path'], 1, 0, 0,
|
||||||
|
self.website.admin.userName, 0, "/home/cyberpanel/" + str(randint(1000, 9999)))
|
||||||
|
|
||||||
|
except BaseException as msg:
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile('%s [SubmitCloudBackupRestore:1533]' % str(msg))
|
||||||
|
|
||||||
|
homePath = '/home/%s' % (self.website.domain)
|
||||||
|
command = 'rm -rf %s' % (homePath)
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
command = 'mv %s/%s %s' % (self.dataPath, self.website.domain, '/home')
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
from filemanager.filemanager import FileManager
|
||||||
|
|
||||||
|
fm = FileManager(None, None)
|
||||||
|
fm.fixPermissions(self.website.domain)
|
||||||
|
|
||||||
|
## Emails
|
||||||
|
|
||||||
|
if os.path.exists(self.emailsPath):
|
||||||
|
try:
|
||||||
|
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
|
||||||
|
'Creating emails if any..,40')
|
||||||
|
emails = json.loads(open('%s/emails.json' % (self.extractedPath), 'r').read())['emails']
|
||||||
|
from mailServer.models import Domains, EUsers
|
||||||
|
emailDomain = Domains.objects.get(domain=self.website.domain)
|
||||||
|
|
||||||
|
for email in emails:
|
||||||
|
try:
|
||||||
|
eu = EUsers.objects.get(emailOwner=emailDomain, email=email['email'])
|
||||||
|
except:
|
||||||
|
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
|
||||||
|
'Creating %s,40' % (email['email']))
|
||||||
|
emailAcct = EUsers(emailOwner=emailDomain, email=email['email'], password=email['password'])
|
||||||
|
emailAcct.mail = 'maildir:/home/vmail/%s/%s/Maildir' % (self.website.domain, email['email'].split('@')[0])
|
||||||
|
emailAcct.save()
|
||||||
|
|
||||||
|
EmailsHome = '/home/vmail/%s' % (self.website.domain)
|
||||||
|
|
||||||
|
command = 'rm -rf %s' % (EmailsHome)
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
command = 'mv %s/%s /home/vmail' % (self.emailsPath, self.website.domain)
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
command = 'chown -R vmail:vmail %s' % (EmailsHome)
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
except BaseException as msg:
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile('%s [SubmitCloudBackupRestore:1533]' % str(msg))
|
||||||
|
|
||||||
|
## Databases
|
||||||
|
|
||||||
|
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
|
||||||
|
'Restoring databases if any..,70')
|
||||||
|
|
||||||
|
databases = json.loads(open('%s/databases.json' % (self.extractedPath), 'r').read())['databases']
|
||||||
|
|
||||||
|
for db in databases:
|
||||||
|
|
||||||
|
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
|
||||||
|
'Restoring database %s..,70' % (db['databaseName']))
|
||||||
|
|
||||||
|
mysqlUtilities.mysqlUtilities.submitDBDeletion(db['databaseName'])
|
||||||
|
|
||||||
|
if mysqlUtilities.mysqlUtilities.createDatabase(db['databaseName'], db['databaseUser'], "cyberpanel") == 0:
|
||||||
|
raise BaseException("Failed to create Databases!")
|
||||||
|
|
||||||
|
newDB = Databases(website=self.website, dbName=db['databaseName'], dbUser=db['databaseUser'])
|
||||||
|
newDB.save()
|
||||||
|
|
||||||
|
mysqlUtilities.mysqlUtilities.restoreDatabaseBackup(db['databaseName'], self.databasesPath, db['password'])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], 'Completed [200].')
|
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], 'Completed [200].')
|
||||||
|
|
||||||
### Cloud Backup functions ends
|
### Cloud Backup functions ends
|
||||||
@@ -1746,6 +1877,13 @@ def main():
|
|||||||
extraArgs['databases'] = int(args.databases)
|
extraArgs['databases'] = int(args.databases)
|
||||||
bu = backupUtilities(extraArgs)
|
bu = backupUtilities(extraArgs)
|
||||||
bu.CloudBackups()
|
bu.CloudBackups()
|
||||||
|
elif args.function == 'SubmitCloudBackupRestore':
|
||||||
|
extraArgs = {}
|
||||||
|
extraArgs['domain'] = args.backupDomain
|
||||||
|
extraArgs['tempStatusPath'] = args.tempStoragePath
|
||||||
|
extraArgs['backupFile'] = args.backupFile
|
||||||
|
bu = backupUtilities(extraArgs)
|
||||||
|
bu.SubmitCloudBackupRestore()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -289,6 +289,7 @@ password=%s
|
|||||||
cnfContent = """[mysqldump]
|
cnfContent = """[mysqldump]
|
||||||
user=root
|
user=root
|
||||||
password=%s
|
password=%s
|
||||||
|
max_allowed_packet=1024M
|
||||||
[mysql]
|
[mysql]
|
||||||
user=root
|
user=root
|
||||||
password=%s
|
password=%s
|
||||||
|
|||||||
Reference in New Issue
Block a user