Skip to content

Commit

Permalink
backups: reduce number of compressions
Browse files Browse the repository at this point in the history
  • Loading branch information
usmannasir committed Apr 6, 2020
1 parent 36e85ef commit 56fb493
Showing 1 changed file with 41 additions and 5 deletions.
46 changes: 41 additions & 5 deletions plogical/backupUtilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -41,6 +41,9 @@
except:
pass

VERSION = '2.0'
BUILD = '1'

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

class backupUtilities:
Expand All @@ -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

Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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'
Expand All @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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!")
Expand Down Expand Up @@ -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]")
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 56fb493

Please sign in to comment.