77import subprocess
88import shlex
99from multiprocessing import Process
10- from shutil import move ,rmtree
10+ from plogical .backupSchedule import backupSchedule
11+ from shutil import rmtree
1112
1213class remoteBackup :
1314
@@ -227,14 +228,13 @@ def sendBackup(completedPathToSend, IPAddress, folderNumber,writeToFile):
227228 logging .CyberCPLogFileWriter .writeToFile (str (msg ) + " [startBackup]" )
228229
229230 @staticmethod
230- def backupProcess (ipAddress , dir , backupLogPath ,folderNumber ,accountsToTransfer ):
231+ def backupProcess (ipAddress , dir , backupLogPath ,folderNumber , accountsToTransfer ):
231232 try :
232233 ## dir is without forward slash
233234
234235 for virtualHost in accountsToTransfer :
235236
236237 try :
237-
238238 if virtualHost == "vmail" or virtualHost == "backup" :
239239 continue
240240
@@ -243,59 +243,37 @@ def backupProcess(ipAddress, dir, backupLogPath,folderNumber,accountsToTransfer)
243243 "%m.%d.%Y_%H-%M-%S" ) + "]" + " Currently generating local backups for: " + virtualHost + "\n " )
244244 writeToFile .close ()
245245
246+ retValues = backupSchedule .createLocalBackup (virtualHost , backupLogPath )
246247
247- finalData = json .dumps ({'websiteToBeBacked' : virtualHost })
248- r = requests .post ("http://localhost:5003/backup/submitBackupCreation" , data = finalData ,verify = False )
249-
250- data = json .loads (r .text )
251-
252- fileName = data ['tempStorage' ]+ ".tar.gz"
253-
254- completePathToBackupFile = fileName
255-
256-
257- while (1 ):
258- time .sleep (2 )
259- r = requests .post ("http://localhost:5003/backup/backupStatus" , data = finalData ,verify = False )
260- data = json .loads (r .text )
261-
248+ if retValues [0 ] == 1 :
262249 writeToFile = open (backupLogPath , "a" )
263250
264251 writeToFile .writelines ("[" + time .strftime (
265- "%m.%d.%Y_%H-%M-%S" ) + "]" + " Waiting for backup to complete.. " + "\n " )
266-
267- writeToFile .close ()
268-
269-
270- if data ['abort' ] == 1 :
252+ "%m.%d.%Y_%H-%M-%S" ) + "]" + " Local Backup Completed for: " + virtualHost + "\n " )
271253
272- writeToFile = open ( backupLogPath , "a" )
254+ ## move the generated backup file to specified destination
273255
274- writeToFile .writelines ("[" + time .strftime (
275- "%m.%d.%Y_%H-%M-%S" ) + "]" + " Local Backup Completed for: " + virtualHost + " with status: " + data ['status' ] + "\n " )
256+ completedPathToSend = retValues [1 ] + ".tar.gz"
276257
258+ writeToFile .writelines ("[" + time .strftime (
259+ "%m.%d.%Y_%H-%M-%S" ) + "]" + " Sending " + completedPathToSend + " to " + ipAddress + ".\n " )
277260
278- ## move the generated backup file to specified destination
279-
280- if os .path .exists (completePathToBackupFile ):
281- move (completePathToBackupFile ,dir )
282-
283- completedPathToSend = dir + "/" + completePathToBackupFile .split ("/" )[- 1 ]
284-
285- writeToFile .writelines ("[" + time .strftime (
286- "%m.%d.%Y_%H-%M-%S" ) + "]" + " Sending " + completedPathToSend + " to " + ipAddress + ".\n " )
261+ remoteBackup .sendBackup (completedPathToSend , ipAddress , str (folderNumber ), writeToFile )
287262
263+ writeToFile .writelines ("[" + time .strftime (
264+ "%m.%d.%Y_%H-%M-%S" ) + "]" + " Sent " + completedPathToSend + " to " + ipAddress + ".\n " )
288265
289- remoteBackup .sendBackup (completedPathToSend ,ipAddress ,str (folderNumber ),writeToFile )
266+ writeToFile .writelines ("[" + time .strftime (
267+ "%m.%d.%Y_%H-%M-%S" ) + "]" + " #############################################" + "\n " )
290268
291- writeToFile .writelines ("[" + time .strftime (
292- "%m.%d.%Y_%H-%M-%S" ) + "]" + " Sent " + completedPathToSend + " to " + ipAddress + ".\n " )
269+ writeToFile .close ()
270+ else :
271+ writeToFile = open (backupLogPath , "a" )
293272
294- writeToFile .writelines ("[" + time .strftime (
295- "%m.%d.%Y_%H-%M-%S" ) + "]" + " #############################################" + "\n " )
273+ writeToFile .writelines ("[" + time .strftime (
274+ "%m.%d.%Y_%H-%M-%S" ) + "]" + 'Local backup failed for %s. Error message: %s' % (virtualHost , retValues [1 ]) )
275+ writeToFile .close ()
296276
297- writeToFile .close ()
298- break
299277 except :
300278 pass
301279
@@ -306,7 +284,7 @@ def backupProcess(ipAddress, dir, backupLogPath,folderNumber,accountsToTransfer)
306284
307285 ## removing local directory where backups were generated
308286 time .sleep (5 )
309- # rmtree(dir)
287+ rmtree (dir )
310288
311289 except BaseException as msg :
312290 logging .CyberCPLogFileWriter .writeToFile (str (msg ) + " [backupProcess]" )
0 commit comments