Skip to content

Commit bfef244

Browse files
committed
bug fix: createLocalBackup function
1 parent 18958b7 commit bfef244

File tree

2 files changed

+67
-63
lines changed

2 files changed

+67
-63
lines changed

plogical/backupSchedule.py

Lines changed: 58 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -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]")

plogical/backupUtilities.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,7 @@ def submitBackupCreation(tempStoragePath, backupName, backupPath, backupDomain):
12661266
ProcessUtilities.executioner(command)
12671267
else:
12681268
writeToFile = open(schedulerPath, 'w')
1269-
writeToFile.writelines('error')
1269+
writeToFile.writelines('1269')
12701270
writeToFile.close()
12711271
return 0
12721272

@@ -1275,7 +1275,7 @@ def submitBackupCreation(tempStoragePath, backupName, backupPath, backupDomain):
12751275
ProcessUtilities.executioner(command)
12761276
else:
12771277
writeToFile = open(schedulerPath, 'w')
1278-
writeToFile.writelines('error')
1278+
writeToFile.writelines('1278')
12791279
writeToFile.close()
12801280
return 0
12811281

@@ -1286,7 +1286,7 @@ def submitBackupCreation(tempStoragePath, backupName, backupPath, backupDomain):
12861286
ProcessUtilities.executioner(command)
12871287
else:
12881288
writeToFile = open(schedulerPath, 'w')
1289-
writeToFile.writelines('error')
1289+
writeToFile.writelines('1289')
12901290
writeToFile.close()
12911291
return 0
12921292

@@ -1295,7 +1295,7 @@ def submitBackupCreation(tempStoragePath, backupName, backupPath, backupDomain):
12951295
ProcessUtilities.executioner(command)
12961296
else:
12971297
writeToFile = open(schedulerPath, 'w')
1298-
writeToFile.writelines('error')
1298+
writeToFile.writelines('1298')
12991299
writeToFile.close()
13001300
return 0
13011301

@@ -1305,7 +1305,7 @@ def submitBackupCreation(tempStoragePath, backupName, backupPath, backupDomain):
13051305
ProcessUtilities.executioner(command)
13061306
else:
13071307
writeToFile = open(schedulerPath, 'w')
1308-
writeToFile.writelines('error')
1308+
writeToFile.writelines('1308')
13091309
writeToFile.close()
13101310
return 0
13111311

@@ -1314,15 +1314,15 @@ def submitBackupCreation(tempStoragePath, backupName, backupPath, backupDomain):
13141314
ProcessUtilities.executioner(command)
13151315
else:
13161316
writeToFile = open(schedulerPath, 'w')
1317-
writeToFile.writelines('error')
1317+
writeToFile.writelines('1317')
13181318
writeToFile.close()
13191319
return 0
13201320

13211321
result = backupUtilities.prepareBackupMeta(backupDomain, backupName, tempStoragePath, backupPath)
13221322

13231323
if result[0] == 0:
13241324
writeToFile = open(schedulerPath, 'w')
1325-
writeToFile.writelines('error')
1325+
writeToFile.writelines('1325')
13261326
writeToFile.close()
13271327
logging.CyberCPLogFileWriter.statusWriter(status, str(result[1]) + ' [1084][5009]')
13281328
return 0
@@ -1339,7 +1339,7 @@ def submitBackupCreation(tempStoragePath, backupName, backupPath, backupDomain):
13391339
if output.find('[5009') > -1:
13401340
logging.CyberCPLogFileWriter.writeToFile(output)
13411341
writeToFile = open(schedulerPath, 'w')
1342-
writeToFile.writelines('error')
1342+
writeToFile.writelines(output)
13431343
writeToFile.close()
13441344
return 0
13451345

@@ -1355,7 +1355,7 @@ def submitBackupCreation(tempStoragePath, backupName, backupPath, backupDomain):
13551355

13561356
if mysqlUtilities.mysqlUtilities.createDatabaseBackup(dbName, '/home/cyberpanel') == 0:
13571357
writeToFile = open(schedulerPath, 'w')
1358-
writeToFile.writelines('error')
1358+
writeToFile.writelines('1358')
13591359
writeToFile.close()
13601360
return 0
13611361

0 commit comments

Comments
 (0)