From 56fb4937898a24c76db7d58aec9d8070b2ec50bb Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Mon, 6 Apr 2020 14:24:52 +0500 Subject: [PATCH] backups: reduce number of compressions --- plogical/backupUtilities.py | 46 +++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/plogical/backupUtilities.py b/plogical/backupUtilities.py index 6ee5b2583..a88de3a72 100755 --- a/plogical/backupUtilities.py +++ b/plogical/backupUtilities.py @@ -28,7 +28,7 @@ from xml.etree.ElementTree import Element, SubElement from xml.etree import ElementTree from xml.dom import minidom import time -from shutil import copy +from shutil import copy, copytree from random import randint from plogical.processUtilities import ProcessUtilities try: @@ -41,6 +41,9 @@ try: except: pass +VERSION = '2.0' +BUILD = '1' + ## I am not the monster that you think I am.. class backupUtilities: @@ -66,6 +69,12 @@ class backupUtilities: metaFileXML = Element('metaFile') + child = SubElement(metaFileXML, 'VERSION') + child.text = VERSION + + child = SubElement(metaFileXML, 'BUILD') + child.text = str(BUILD) + child = SubElement(metaFileXML, 'masterDomain') child.text = backupDomain @@ -354,7 +363,13 @@ class backupUtilities: ## /home/example.com/backup/backup-example.com-02.13.2018_10-24-52 -- tempStoragePath ## shutil.make_archive - make_archive(os.path.join(tempStoragePath,"public_html"), 'gztar', os.path.join("/home",domainName,"public_html")) + ## Stop making archive of document_root and copy instead + + copytree('/home/%s/public_html' % domainName, tempStoragePath) + + #make_archive(os.path.join(tempStoragePath,"public_html"), 'gztar', os.path.join("/home",domainName,"public_html")) + + ## logging.CyberCPLogFileWriter.statusWriter(status, "Backing up databases..") print('1,None') @@ -412,6 +427,7 @@ class backupUtilities: for childDomain in childDomains: actualChildDomain = childDomain.find('domain').text + childPath = childDomain.find('path').text if os.path.exists(backupUtilities.licenseKey): completPathToConf = backupUtilities.Server_root + '/conf/vhosts/' + actualChildDomain + '/vhost.conf' @@ -433,6 +449,10 @@ class backupUtilities: sslStoragePath) except: pass + + if childPath.find('/home/%s/public_html' % domainName) == -1: + copytree(childPath, '%s/%s-docroot' % (tempStoragePath, actualChildDomain)) + except BaseException as msg: pass @@ -660,6 +680,13 @@ class backupUtilities: backupMetaData = ElementTree.parse(os.path.join(completPath, "meta.xml")) masterDomain = backupMetaData.find('masterDomain').text + try: + version = backupMetaData.find('VERSION').text + build = backupMetaData.find('BUILD').text + except: + version = '2.0' + build = '0' + result = backupUtilities.createWebsiteFromBackup(backupName, dir) if result[0] == 1: @@ -686,6 +713,9 @@ class backupUtilities: logging.CyberCPLogFileWriter.statusWriter(status, "Error Message: " + result[1] + ". Not able to create Account, Databases and DNS Records, aborting. [575][5009]") return 0 + if float(version) > 2.0 or float(build) > 0: + copytree('%s/public_html' % (completPath), '/home/%s' % masterDomain) + ########### Creating child/sub/addon/parked domains logging.CyberCPLogFileWriter.statusWriter(status, "Creating Child Domains!") @@ -751,11 +781,16 @@ class backupUtilities: except: logging.CyberCPLogFileWriter.writeToFile('While restoring backup we had minor issues for rebuilding vhost conf for: ' + domain + '. However this will be auto healed.') + if float(version) > 2.0 or float(build) > 0: + if path.find('/home/%s/public_html' % masterDomain) == -1: + copytree('%s/%s-docroot' % (completPath, domain), path) + continue else: logging.CyberCPLogFileWriter.writeToFile('Error domain %s' % (domain)) logging.CyberCPLogFileWriter.statusWriter(status, "Error Message: " + retValues[1] + ". Not able to create child domains, aborting. [635][5009]") return 0 + except BaseException as msg: status = open(os.path.join(completPath,'status'), "w") status.write("Error Message: " + str(msg) +". Not able to create child domains, aborting. [638][5009]") @@ -813,10 +848,11 @@ class backupUtilities: logging.CyberCPLogFileWriter.statusWriter(status, "Extracting web home data!") # /home/backup/backup-example.com-02.13.2018_10-24-52/public_html.tar.gz + ## Moving above v2.0.0 extracting webhome data is not required, thus commenting below lines - tar = tarfile.open(pathToCompressedHome) - tar.extractall(websiteHome) - tar.close() + # tar = tarfile.open(pathToCompressedHome) + # tar.extractall(websiteHome) + # tar.close() ## extracting email accounts