Skip to content

Commit c2a54f0

Browse files
committed
bug fix: to restore folders
1 parent 56fb493 commit c2a54f0

1 file changed

Lines changed: 18 additions & 17 deletions

File tree

plogical/backupUtilities.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
from xml.etree import ElementTree
2929
from xml.dom import minidom
3030
import time
31-
from shutil import copy, copytree
31+
from shutil import copy
32+
from distutils.dir_util import copy_tree
3233
from random import randint
3334
from plogical.processUtilities import ProcessUtilities
3435
try:
@@ -42,7 +43,7 @@
4243
pass
4344

4445
VERSION = '2.0'
45-
BUILD = '1'
46+
BUILD = 1
4647

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

@@ -365,7 +366,8 @@ def startBackup(tempStoragePath, backupName, backupPath, metaPath = None):
365366

366367
## Stop making archive of document_root and copy instead
367368

368-
copytree('/home/%s/public_html' % domainName, tempStoragePath)
369+
370+
copy_tree('/home/%s/public_html' % domainName, '%s/%s' % (tempStoragePath, 'public_html'))
369371

370372
#make_archive(os.path.join(tempStoragePath,"public_html"), 'gztar', os.path.join("/home",domainName,"public_html"))
371373

@@ -451,7 +453,7 @@ def BackupRoot(tempStoragePath, backupName, backupPath, metaPath=None):
451453
pass
452454

453455
if childPath.find('/home/%s/public_html' % domainName) == -1:
454-
copytree(childPath, '%s/%s-docroot' % (tempStoragePath, actualChildDomain))
456+
copy_tree(childPath, '%s/%s-docroot' % (tempStoragePath, actualChildDomain))
455457

456458
except BaseException as msg:
457459
pass
@@ -649,8 +651,6 @@ def startRestore(backupName, dir):
649651
completPath = "/home/backup/transfer-"+str(dir)+"/"+backupFileName ## without extension
650652
originalFile = "/home/backup/transfer-"+str(dir)+"/"+backupName ## with extension
651653

652-
653-
654654
pathToCompressedHome = os.path.join(completPath,"public_html.tar.gz")
655655

656656
if not os.path.exists(completPath):
@@ -671,7 +671,6 @@ def startRestore(backupName, dir):
671671
tar.extractall(completPath)
672672
tar.close()
673673

674-
675674
logging.CyberCPLogFileWriter.statusWriter(status, "Creating Accounts,Databases and DNS records!")
676675

677676
########### Creating website and its dabases
@@ -680,12 +679,14 @@ def startRestore(backupName, dir):
680679
backupMetaData = ElementTree.parse(os.path.join(completPath, "meta.xml"))
681680
masterDomain = backupMetaData.find('masterDomain').text
682681

682+
683+
twoPointO = 0
683684
try:
684685
version = backupMetaData.find('VERSION').text
685686
build = backupMetaData.find('BUILD').text
687+
twoPointO = 1
686688
except:
687-
version = '2.0'
688-
build = '0'
689+
twoPointO = 0
689690

690691
result = backupUtilities.createWebsiteFromBackup(backupName, dir)
691692

@@ -713,8 +714,6 @@ def startRestore(backupName, dir):
713714
logging.CyberCPLogFileWriter.statusWriter(status, "Error Message: " + result[1] + ". Not able to create Account, Databases and DNS Records, aborting. [575][5009]")
714715
return 0
715716

716-
if float(version) > 2.0 or float(build) > 0:
717-
copytree('%s/public_html' % (completPath), '/home/%s' % masterDomain)
718717

719718
########### Creating child/sub/addon/parked domains
720719

@@ -783,14 +782,13 @@ def startRestore(backupName, dir):
783782

784783
if float(version) > 2.0 or float(build) > 0:
785784
if path.find('/home/%s/public_html' % masterDomain) == -1:
786-
copytree('%s/%s-docroot' % (completPath, domain), path)
785+
copy_tree('%s/%s-docroot' % (completPath, domain), path)
787786

788787
continue
789788
else:
790789
logging.CyberCPLogFileWriter.writeToFile('Error domain %s' % (domain))
791790
logging.CyberCPLogFileWriter.statusWriter(status, "Error Message: " + retValues[1] + ". Not able to create child domains, aborting. [635][5009]")
792791
return 0
793-
794792
except BaseException as msg:
795793
status = open(os.path.join(completPath,'status'), "w")
796794
status.write("Error Message: " + str(msg) +". Not able to create child domains, aborting. [638][5009]")
@@ -823,7 +821,6 @@ def startRestore(backupName, dir):
823821
result = mailUtilities.createEmailAccount(masterDomain, username, password, 'restore')
824822
if result[0] == 0:
825823
raise BaseException(result[1])
826-
827824
except BaseException as msg:
828825
logging.CyberCPLogFileWriter.statusWriter(status, "Error Message: " + str(msg) +". Not able to create email accounts, aborting. [671][5009]")
829826
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startRestore]")
@@ -850,9 +847,13 @@ def startRestore(backupName, dir):
850847
# /home/backup/backup-example.com-02.13.2018_10-24-52/public_html.tar.gz
851848
## Moving above v2.0.0 extracting webhome data is not required, thus commenting below lines
852849

853-
# tar = tarfile.open(pathToCompressedHome)
854-
# tar.extractall(websiteHome)
855-
# tar.close()
850+
if not twoPointO:
851+
tar = tarfile.open(pathToCompressedHome)
852+
tar.extractall(websiteHome)
853+
tar.close()
854+
else:
855+
if float(version) > 2.0 or float(build) > 0:
856+
copy_tree('%s/public_html' % (completPath), websiteHome)
856857

857858
## extracting email accounts
858859

0 commit comments

Comments
 (0)