2828from xml .etree import ElementTree
2929from xml .dom import minidom
3030import time
31- from shutil import copy
31+ from shutil import copy , copytree
3232from random import randint
3333from plogical .processUtilities import ProcessUtilities
3434try :
4141except :
4242 pass
4343
44+ VERSION = '2.0'
45+ BUILD = '1'
46+
4447## I am not the monster that you think I am..
4548
4649class backupUtilities :
@@ -66,6 +69,12 @@ def prepareBackupMeta(backupDomain, backupName, tempStoragePath, backupPath):
6669
6770 metaFileXML = Element ('metaFile' )
6871
72+ child = SubElement (metaFileXML , 'VERSION' )
73+ child .text = VERSION
74+
75+ child = SubElement (metaFileXML , 'BUILD' )
76+ child .text = str (BUILD )
77+
6978 child = SubElement (metaFileXML , 'masterDomain' )
7079 child .text = backupDomain
7180
@@ -354,7 +363,13 @@ def startBackup(tempStoragePath, backupName, backupPath, metaPath = None):
354363 ## /home/example.com/backup/backup-example.com-02.13.2018_10-24-52 -- tempStoragePath
355364 ## shutil.make_archive
356365
357- make_archive (os .path .join (tempStoragePath ,"public_html" ), 'gztar' , os .path .join ("/home" ,domainName ,"public_html" ))
366+ ## Stop making archive of document_root and copy instead
367+
368+ copytree ('/home/%s/public_html' % domainName , tempStoragePath )
369+
370+ #make_archive(os.path.join(tempStoragePath,"public_html"), 'gztar', os.path.join("/home",domainName,"public_html"))
371+
372+ ##
358373
359374 logging .CyberCPLogFileWriter .statusWriter (status , "Backing up databases.." )
360375 print ('1,None' )
@@ -412,6 +427,7 @@ def BackupRoot(tempStoragePath, backupName, backupPath, metaPath=None):
412427 for childDomain in childDomains :
413428
414429 actualChildDomain = childDomain .find ('domain' ).text
430+ childPath = childDomain .find ('path' ).text
415431
416432 if os .path .exists (backupUtilities .licenseKey ):
417433 completPathToConf = backupUtilities .Server_root + '/conf/vhosts/' + actualChildDomain + '/vhost.conf'
@@ -433,6 +449,10 @@ def BackupRoot(tempStoragePath, backupName, backupPath, metaPath=None):
433449 sslStoragePath )
434450 except :
435451 pass
452+
453+ if childPath .find ('/home/%s/public_html' % domainName ) == - 1 :
454+ copytree (childPath , '%s/%s-docroot' % (tempStoragePath , actualChildDomain ))
455+
436456 except BaseException as msg :
437457 pass
438458
@@ -660,6 +680,13 @@ def startRestore(backupName, dir):
660680 backupMetaData = ElementTree .parse (os .path .join (completPath , "meta.xml" ))
661681 masterDomain = backupMetaData .find ('masterDomain' ).text
662682
683+ try :
684+ version = backupMetaData .find ('VERSION' ).text
685+ build = backupMetaData .find ('BUILD' ).text
686+ except :
687+ version = '2.0'
688+ build = '0'
689+
663690 result = backupUtilities .createWebsiteFromBackup (backupName , dir )
664691
665692 if result [0 ] == 1 :
@@ -686,6 +713,9 @@ def startRestore(backupName, dir):
686713 logging .CyberCPLogFileWriter .statusWriter (status , "Error Message: " + result [1 ] + ". Not able to create Account, Databases and DNS Records, aborting. [575][5009]" )
687714 return 0
688715
716+ if float (version ) > 2.0 or float (build ) > 0 :
717+ copytree ('%s/public_html' % (completPath ), '/home/%s' % masterDomain )
718+
689719 ########### Creating child/sub/addon/parked domains
690720
691721 logging .CyberCPLogFileWriter .statusWriter (status , "Creating Child Domains!" )
@@ -751,11 +781,16 @@ def startRestore(backupName, dir):
751781 except :
752782 logging .CyberCPLogFileWriter .writeToFile ('While restoring backup we had minor issues for rebuilding vhost conf for: ' + domain + '. However this will be auto healed.' )
753783
784+ if float (version ) > 2.0 or float (build ) > 0 :
785+ if path .find ('/home/%s/public_html' % masterDomain ) == - 1 :
786+ copytree ('%s/%s-docroot' % (completPath , domain ), path )
787+
754788 continue
755789 else :
756790 logging .CyberCPLogFileWriter .writeToFile ('Error domain %s' % (domain ))
757791 logging .CyberCPLogFileWriter .statusWriter (status , "Error Message: " + retValues [1 ] + ". Not able to create child domains, aborting. [635][5009]" )
758792 return 0
793+
759794 except BaseException as msg :
760795 status = open (os .path .join (completPath ,'status' ), "w" )
761796 status .write ("Error Message: " + str (msg ) + ". Not able to create child domains, aborting. [638][5009]" )
@@ -813,10 +848,11 @@ def startRestore(backupName, dir):
813848 logging .CyberCPLogFileWriter .statusWriter (status , "Extracting web home data!" )
814849
815850 # /home/backup/backup-example.com-02.13.2018_10-24-52/public_html.tar.gz
851+ ## Moving above v2.0.0 extracting webhome data is not required, thus commenting below lines
816852
817- tar = tarfile .open (pathToCompressedHome )
818- tar .extractall (websiteHome )
819- tar .close ()
853+ # tar = tarfile.open(pathToCompressedHome)
854+ # tar.extractall(websiteHome)
855+ # tar.close()
820856
821857 ## extracting email accounts
822858
0 commit comments