@@ -49,8 +49,6 @@ def remoteBackupLogging(fileName, message, status = 0):
4949 def createLocalBackup (virtualHost , backupLogPath ):
5050 try :
5151
52- startingTime = datetime .now ()
53-
5452 backupSchedule .remoteBackupLogging (backupLogPath , "Starting local backup for: " + virtualHost )
5553
5654 ###
@@ -75,7 +73,6 @@ def createLocalBackup(virtualHost, backupLogPath):
7573 killCounter = 0
7674
7775 while (1 ):
78- diff = datetime .now () - startingTime
7976
8077 backupDomain = virtualHost
8178 status = os .path .join ("/home" , backupDomain , "backup/status" )
@@ -91,10 +88,7 @@ def createLocalBackup(virtualHost, backupLogPath):
9188 ifRunning = ProcessUtilities .outputExecutioner ('ps aux' )
9289
9390 if (ifRunning .find ('startBackup' ) > - 1 or ifRunning .find ('BackupRoot' ) > - 1 ) and ifRunning .find ('/%s/' % (backupDomain )):
94- pass
95- else :
9691 if os .path .exists (status ):
97-
9892 status = open (status , 'r' ).read ()
9993 time .sleep (2 )
10094
@@ -117,44 +111,51 @@ def createLocalBackup(virtualHost, backupLogPath):
117111 except :
118112 pass
119113 return 1 , tempStoragePath
120- else :
121- return 0 , 'Backup process killed without reporting any error.'
122- else :
123- if killCounter == 1 :
124- return 0 , 'Backup process killed without reporting any error.'
125- else :
126- time .sleep (10 )
127- killCounter = 1
128114
129- ## file name read ends
115+ elif status .find ("[5009]" ) > - 1 :
116+ ## removing status file, so that backup can re-run
117+ try :
118+ command = 'sudo rm -f ' + status
119+ ProcessUtilities .normalExecutioner (command )
130120
131- if os .path .exists (status ):
132- status = open (status , 'r' ).read ()
133- time .sleep (2 )
121+ command = 'sudo rm -f ' + backupFileNamePath
122+ ProcessUtilities .normalExecutioner (command )
134123
135- if status .find ("Completed" ) > - 1 :
124+ command = 'sudo rm -f ' + pid
125+ ProcessUtilities .normalExecutioner (command )
136126
137- ### Removing Files
127+ backupObs = Backups .objects .filter (fileName = fileName )
128+ for items in backupObs :
129+ items .delete ()
138130
139- command = 'sudo rm -f ' + status
140- ProcessUtilities .normalExecutioner (command )
131+ except :
132+ pass
133+
134+ backupSchedule .remoteBackupLogging (backupLogPath ,
135+ "Local backup creating failed for %s, Error message: %s" % (
136+ virtualHost , status ), backupSchedule .ERROR )
141137
142- command = 'sudo rm -f ' + backupFileNamePath
143- ProcessUtilities .normalExecutioner (command )
138+ try :
139+ os .remove (pathToFile )
140+ except :
141+ pass
142+ return 0 , tempStoragePath
143+
144+ elif os .path .exists (schedulerPath ):
145+ backupSchedule .remoteBackupLogging (backupLogPath , 'Backup process killed. Error: %s' % (
146+ open (schedulerPath , 'r' ).read ()),
147+ backupSchedule .ERROR )
148+ os .remove (schedulerPath )
149+ return 0 , 'Backup process killed.'
150+ else :
151+ if os .path .exists (status ):
152+ status = open (status , 'r' ).read ()
153+ time .sleep (2 )
144154
145- command = 'sudo rm -f ' + pid
146- ProcessUtilities .normalExecutioner (command )
155+ if status .find ("Completed" ) > - 1 :
147156
148- backupSchedule .remoteBackupLogging (backupLogPath , "Backup Completed for: " + virtualHost )
149- try :
150- os .remove (pathToFile )
151- except :
152- pass
153- return 1 , tempStoragePath
157+ ### Removing Files
154158
155- elif status .find ("[5009]" ) > - 1 :
156- ## removing status file, so that backup can re-run
157- try :
158159 command = 'sudo rm -f ' + status
159160 ProcessUtilities .normalExecutioner (command )
160161
@@ -164,26 +165,29 @@ def createLocalBackup(virtualHost, backupLogPath):
164165 command = 'sudo rm -f ' + pid
165166 ProcessUtilities .normalExecutioner (command )
166167
167- backupObs = Backups .objects .filter (fileName = fileName )
168- for items in backupObs :
169- items .delete ()
170-
171- except :
172- pass
173-
174- backupSchedule .remoteBackupLogging (backupLogPath , "Local backup creating failed for %s, Error message: %s" % (virtualHost , status ), backupSchedule .ERROR )
175-
176- try :
177- os .remove (pathToFile )
178- except :
179- pass
180- return 0 , tempStoragePath
181-
182- elif os .path .exists (schedulerPath ):
183- backupSchedule .remoteBackupLogging (backupLogPath , 'Backup process killed without reporting any error.' ,
168+ backupSchedule .remoteBackupLogging (backupLogPath , "Backup Completed for: " + virtualHost )
169+ try :
170+ os .remove (pathToFile )
171+ except :
172+ pass
173+ return 1 , tempStoragePath
174+ elif os .path .exists (schedulerPath ):
175+ backupSchedule .remoteBackupLogging (backupLogPath , 'Backup process killed. Error: %s' % (open (schedulerPath , 'r' ).read ()),
184176 backupSchedule .ERROR )
185- os .remove (schedulerPath )
186- return 0 , 'Backup process killed without reporting any error.'
177+ os .remove (schedulerPath )
178+ return 0 , 'Backup process killed.'
179+ else :
180+ if killCounter == 1 :
181+ return 0 , 'Backup process killed without reporting any error. [184]'
182+ elif os .path .exists (schedulerPath ):
183+ backupSchedule .remoteBackupLogging (backupLogPath , 'Backup process killed. Error: %s' % (
184+ open (schedulerPath , 'r' ).read ()),
185+ backupSchedule .ERROR )
186+ os .remove (schedulerPath )
187+ return 0 , 'Backup process killed.'
188+ else :
189+ time .sleep (10 )
190+ killCounter = 1
187191
188192 except BaseException as msg :
189193 logging .CyberCPLogFileWriter .writeToFile (str (msg ) + " [119:startBackup]" )
0 commit comments