Skip to content
Permalink
Browse files
bug fix: #385
  • Loading branch information
usmannasir committed Jul 5, 2020
1 parent 1dab0cd commit 57e8a6ea4ce7f26c249e6a0d44a917b4f86aa4c3
Showing 1 changed file with 22 additions and 44 deletions.
@@ -7,7 +7,8 @@
import subprocess
import shlex
from multiprocessing import Process
from shutil import move,rmtree
from plogical.backupSchedule import backupSchedule
from shutil import rmtree

class remoteBackup:

@@ -227,14 +228,13 @@ def sendBackup(completedPathToSend, IPAddress, folderNumber,writeToFile):
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startBackup]")

@staticmethod
def backupProcess(ipAddress, dir, backupLogPath,folderNumber,accountsToTransfer):
def backupProcess(ipAddress, dir, backupLogPath,folderNumber, accountsToTransfer):
try:
## dir is without forward slash

for virtualHost in accountsToTransfer:

try:

if virtualHost == "vmail" or virtualHost == "backup":
continue

@@ -243,59 +243,37 @@ def backupProcess(ipAddress, dir, backupLogPath,folderNumber,accountsToTransfer)
"%m.%d.%Y_%H-%M-%S") + "]" + " Currently generating local backups for: " + virtualHost + "\n")
writeToFile.close()

retValues = backupSchedule.createLocalBackup(virtualHost, backupLogPath)

finalData = json.dumps({'websiteToBeBacked': virtualHost})
r = requests.post("http://localhost:5003/backup/submitBackupCreation", data=finalData,verify=False)

data = json.loads(r.text)

fileName = data['tempStorage']+".tar.gz"

completePathToBackupFile = fileName


while (1):
time.sleep(2)
r = requests.post("http://localhost:5003/backup/backupStatus", data= finalData,verify=False)
data = json.loads(r.text)

if retValues[0] == 1:
writeToFile = open(backupLogPath, "a")

writeToFile.writelines("[" + time.strftime(
"%m.%d.%Y_%H-%M-%S") + "]" + " Waiting for backup to complete.. " + "\n")

writeToFile.close()


if data['abort'] == 1:
"%m.%d.%Y_%H-%M-%S") + "]" + " Local Backup Completed for: " + virtualHost + "\n")

writeToFile = open(backupLogPath, "a")
## move the generated backup file to specified destination

writeToFile.writelines("[" + time.strftime(
"%m.%d.%Y_%H-%M-%S") + "]" + " Local Backup Completed for: " +virtualHost + " with status: "+ data['status'] +"\n")
completedPathToSend = retValues[1] + ".tar.gz"

writeToFile.writelines("[" + time.strftime(
"%m.%d.%Y_%H-%M-%S") + "]" + " Sending " + completedPathToSend + " to " + ipAddress + ".\n")

## move the generated backup file to specified destination

if os.path.exists(completePathToBackupFile):
move(completePathToBackupFile,dir)

completedPathToSend = dir +"/" + completePathToBackupFile.split("/")[-1]

writeToFile.writelines("[" + time.strftime(
"%m.%d.%Y_%H-%M-%S") + "]" + " Sending " + completedPathToSend +" to "+ipAddress +".\n")
remoteBackup.sendBackup(completedPathToSend, ipAddress, str(folderNumber), writeToFile)

writeToFile.writelines("[" + time.strftime(
"%m.%d.%Y_%H-%M-%S") + "]" + " Sent " + completedPathToSend + " to " + ipAddress + ".\n")

remoteBackup.sendBackup(completedPathToSend,ipAddress,str(folderNumber),writeToFile)
writeToFile.writelines("[" + time.strftime(
"%m.%d.%Y_%H-%M-%S") + "]" + " #############################################" + "\n")

writeToFile.writelines("[" + time.strftime(
"%m.%d.%Y_%H-%M-%S") + "]" + " Sent " + completedPathToSend + " to " + ipAddress + ".\n")
writeToFile.close()
else:
writeToFile = open(backupLogPath, "a")

writeToFile.writelines("[" + time.strftime(
"%m.%d.%Y_%H-%M-%S") + "]" + " #############################################" + "\n")
writeToFile.writelines("[" + time.strftime(
"%m.%d.%Y_%H-%M-%S") + "]" + 'Local backup failed for %s. Error message: %s' % (virtualHost, retValues[1]) )
writeToFile.close()

writeToFile.close()
break
except:
pass

@@ -306,7 +284,7 @@ def backupProcess(ipAddress, dir, backupLogPath,folderNumber,accountsToTransfer)

## removing local directory where backups were generated
time.sleep(5)
#rmtree(dir)
rmtree(dir)

except BaseException as msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [backupProcess]")

0 comments on commit 57e8a6e

Please sign in to comment.