Skip to content
Permalink
Browse files
backups: reduce number of compressions
  • Loading branch information
usmannasir committed Apr 6, 2020
1 parent 36e85ef commit 56fb4937898a24c76db7d58aec9d8070b2ec50bb
Showing 1 changed file with 41 additions and 5 deletions.
@@ -28,7 +28,7 @@
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 @@
except:
pass

VERSION = '2.0'
BUILD = '1'

## I am not the monster that you think I am..

class backupUtilities:
@@ -66,6 +69,12 @@ def prepareBackupMeta(backupDomain, backupName, tempStoragePath, backupPath):

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 @@ def startBackup(tempStoragePath, backupName, backupPath, metaPath = None):
## /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 @@ def BackupRoot(tempStoragePath, backupName, backupPath, metaPath=None):
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 @@ def BackupRoot(tempStoragePath, backupName, backupPath, metaPath=None):
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 @@ def startRestore(backupName, dir):
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 @@ def startRestore(backupName, dir):
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 @@ def startRestore(backupName, dir):
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 @@ def startRestore(backupName, dir):
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

0 comments on commit 56fb493

Please sign in to comment.