mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-12 00:06:09 +01:00
bug fix: createLocalBackup function
This commit is contained in:
@@ -49,8 +49,6 @@ class backupSchedule:
|
|||||||
def createLocalBackup(virtualHost, backupLogPath):
|
def createLocalBackup(virtualHost, backupLogPath):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
startingTime = datetime.now()
|
|
||||||
|
|
||||||
backupSchedule.remoteBackupLogging(backupLogPath, "Starting local backup for: " + virtualHost)
|
backupSchedule.remoteBackupLogging(backupLogPath, "Starting local backup for: " + virtualHost)
|
||||||
|
|
||||||
###
|
###
|
||||||
@@ -75,7 +73,6 @@ class backupSchedule:
|
|||||||
killCounter = 0
|
killCounter = 0
|
||||||
|
|
||||||
while (1):
|
while (1):
|
||||||
diff = datetime.now() - startingTime
|
|
||||||
|
|
||||||
backupDomain = virtualHost
|
backupDomain = virtualHost
|
||||||
status = os.path.join("/home", backupDomain, "backup/status")
|
status = os.path.join("/home", backupDomain, "backup/status")
|
||||||
@@ -91,10 +88,7 @@ class backupSchedule:
|
|||||||
ifRunning = ProcessUtilities.outputExecutioner('ps aux')
|
ifRunning = ProcessUtilities.outputExecutioner('ps aux')
|
||||||
|
|
||||||
if (ifRunning.find('startBackup') > -1 or ifRunning.find('BackupRoot') > -1) and ifRunning.find('/%s/' % (backupDomain)):
|
if (ifRunning.find('startBackup') > -1 or ifRunning.find('BackupRoot') > -1) and ifRunning.find('/%s/' % (backupDomain)):
|
||||||
pass
|
|
||||||
else:
|
|
||||||
if os.path.exists(status):
|
if os.path.exists(status):
|
||||||
|
|
||||||
status = open(status, 'r').read()
|
status = open(status, 'r').read()
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
@@ -117,44 +111,51 @@ class backupSchedule:
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
return 1, tempStoragePath
|
return 1, tempStoragePath
|
||||||
else:
|
|
||||||
return 0, 'Backup process killed without reporting any error.'
|
|
||||||
else:
|
|
||||||
if killCounter == 1:
|
|
||||||
return 0, 'Backup process killed without reporting any error.'
|
|
||||||
else:
|
|
||||||
time.sleep(10)
|
|
||||||
killCounter = 1
|
|
||||||
|
|
||||||
## file name read ends
|
elif status.find("[5009]") > -1:
|
||||||
|
## removing status file, so that backup can re-run
|
||||||
|
try:
|
||||||
|
command = 'sudo rm -f ' + status
|
||||||
|
ProcessUtilities.normalExecutioner(command)
|
||||||
|
|
||||||
if os.path.exists(status):
|
command = 'sudo rm -f ' + backupFileNamePath
|
||||||
status = open(status, 'r').read()
|
ProcessUtilities.normalExecutioner(command)
|
||||||
time.sleep(2)
|
|
||||||
|
|
||||||
if status.find("Completed") > -1:
|
command = 'sudo rm -f ' + pid
|
||||||
|
ProcessUtilities.normalExecutioner(command)
|
||||||
|
|
||||||
### Removing Files
|
backupObs = Backups.objects.filter(fileName=fileName)
|
||||||
|
for items in backupObs:
|
||||||
|
items.delete()
|
||||||
|
|
||||||
command = 'sudo rm -f ' + status
|
except:
|
||||||
ProcessUtilities.normalExecutioner(command)
|
pass
|
||||||
|
|
||||||
command = 'sudo rm -f ' + backupFileNamePath
|
backupSchedule.remoteBackupLogging(backupLogPath,
|
||||||
ProcessUtilities.normalExecutioner(command)
|
"Local backup creating failed for %s, Error message: %s" % (
|
||||||
|
virtualHost, status), backupSchedule.ERROR)
|
||||||
|
|
||||||
command = 'sudo rm -f ' + pid
|
try:
|
||||||
ProcessUtilities.normalExecutioner(command)
|
os.remove(pathToFile)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return 0, tempStoragePath
|
||||||
|
|
||||||
backupSchedule.remoteBackupLogging(backupLogPath, "Backup Completed for: " + virtualHost)
|
elif os.path.exists(schedulerPath):
|
||||||
try:
|
backupSchedule.remoteBackupLogging(backupLogPath, 'Backup process killed. Error: %s' % (
|
||||||
os.remove(pathToFile)
|
open(schedulerPath, 'r').read()),
|
||||||
except:
|
backupSchedule.ERROR)
|
||||||
pass
|
os.remove(schedulerPath)
|
||||||
return 1, tempStoragePath
|
return 0, 'Backup process killed.'
|
||||||
|
else:
|
||||||
|
if os.path.exists(status):
|
||||||
|
status = open(status, 'r').read()
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
|
if status.find("Completed") > -1:
|
||||||
|
|
||||||
|
### Removing Files
|
||||||
|
|
||||||
elif status.find("[5009]") > -1:
|
|
||||||
## removing status file, so that backup can re-run
|
|
||||||
try:
|
|
||||||
command = 'sudo rm -f ' + status
|
command = 'sudo rm -f ' + status
|
||||||
ProcessUtilities.normalExecutioner(command)
|
ProcessUtilities.normalExecutioner(command)
|
||||||
|
|
||||||
@@ -164,26 +165,29 @@ class backupSchedule:
|
|||||||
command = 'sudo rm -f ' + pid
|
command = 'sudo rm -f ' + pid
|
||||||
ProcessUtilities.normalExecutioner(command)
|
ProcessUtilities.normalExecutioner(command)
|
||||||
|
|
||||||
backupObs = Backups.objects.filter(fileName=fileName)
|
backupSchedule.remoteBackupLogging(backupLogPath, "Backup Completed for: " + virtualHost)
|
||||||
for items in backupObs:
|
try:
|
||||||
items.delete()
|
os.remove(pathToFile)
|
||||||
|
except:
|
||||||
except:
|
pass
|
||||||
pass
|
return 1, tempStoragePath
|
||||||
|
elif os.path.exists(schedulerPath):
|
||||||
backupSchedule.remoteBackupLogging(backupLogPath, "Local backup creating failed for %s, Error message: %s" % (virtualHost, status), backupSchedule.ERROR)
|
backupSchedule.remoteBackupLogging(backupLogPath, 'Backup process killed. Error: %s' % (open(schedulerPath, 'r').read()),
|
||||||
|
|
||||||
try:
|
|
||||||
os.remove(pathToFile)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
return 0, tempStoragePath
|
|
||||||
|
|
||||||
elif os.path.exists(schedulerPath):
|
|
||||||
backupSchedule.remoteBackupLogging(backupLogPath, 'Backup process killed without reporting any error.',
|
|
||||||
backupSchedule.ERROR)
|
backupSchedule.ERROR)
|
||||||
os.remove(schedulerPath)
|
os.remove(schedulerPath)
|
||||||
return 0, 'Backup process killed without reporting any error.'
|
return 0, 'Backup process killed.'
|
||||||
|
else:
|
||||||
|
if killCounter == 1:
|
||||||
|
return 0, 'Backup process killed without reporting any error. [184]'
|
||||||
|
elif os.path.exists(schedulerPath):
|
||||||
|
backupSchedule.remoteBackupLogging(backupLogPath, 'Backup process killed. Error: %s' % (
|
||||||
|
open(schedulerPath, 'r').read()),
|
||||||
|
backupSchedule.ERROR)
|
||||||
|
os.remove(schedulerPath)
|
||||||
|
return 0, 'Backup process killed.'
|
||||||
|
else:
|
||||||
|
time.sleep(10)
|
||||||
|
killCounter = 1
|
||||||
|
|
||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [119:startBackup]")
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [119:startBackup]")
|
||||||
|
|||||||
@@ -1266,7 +1266,7 @@ def submitBackupCreation(tempStoragePath, backupName, backupPath, backupDomain):
|
|||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
else:
|
else:
|
||||||
writeToFile = open(schedulerPath, 'w')
|
writeToFile = open(schedulerPath, 'w')
|
||||||
writeToFile.writelines('error')
|
writeToFile.writelines('1269')
|
||||||
writeToFile.close()
|
writeToFile.close()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@@ -1275,7 +1275,7 @@ def submitBackupCreation(tempStoragePath, backupName, backupPath, backupDomain):
|
|||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
else:
|
else:
|
||||||
writeToFile = open(schedulerPath, 'w')
|
writeToFile = open(schedulerPath, 'w')
|
||||||
writeToFile.writelines('error')
|
writeToFile.writelines('1278')
|
||||||
writeToFile.close()
|
writeToFile.close()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@@ -1286,7 +1286,7 @@ def submitBackupCreation(tempStoragePath, backupName, backupPath, backupDomain):
|
|||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
else:
|
else:
|
||||||
writeToFile = open(schedulerPath, 'w')
|
writeToFile = open(schedulerPath, 'w')
|
||||||
writeToFile.writelines('error')
|
writeToFile.writelines('1289')
|
||||||
writeToFile.close()
|
writeToFile.close()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@@ -1295,7 +1295,7 @@ def submitBackupCreation(tempStoragePath, backupName, backupPath, backupDomain):
|
|||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
else:
|
else:
|
||||||
writeToFile = open(schedulerPath, 'w')
|
writeToFile = open(schedulerPath, 'w')
|
||||||
writeToFile.writelines('error')
|
writeToFile.writelines('1298')
|
||||||
writeToFile.close()
|
writeToFile.close()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@@ -1305,7 +1305,7 @@ def submitBackupCreation(tempStoragePath, backupName, backupPath, backupDomain):
|
|||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
else:
|
else:
|
||||||
writeToFile = open(schedulerPath, 'w')
|
writeToFile = open(schedulerPath, 'w')
|
||||||
writeToFile.writelines('error')
|
writeToFile.writelines('1308')
|
||||||
writeToFile.close()
|
writeToFile.close()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@@ -1314,7 +1314,7 @@ def submitBackupCreation(tempStoragePath, backupName, backupPath, backupDomain):
|
|||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
else:
|
else:
|
||||||
writeToFile = open(schedulerPath, 'w')
|
writeToFile = open(schedulerPath, 'w')
|
||||||
writeToFile.writelines('error')
|
writeToFile.writelines('1317')
|
||||||
writeToFile.close()
|
writeToFile.close()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@@ -1322,7 +1322,7 @@ def submitBackupCreation(tempStoragePath, backupName, backupPath, backupDomain):
|
|||||||
|
|
||||||
if result[0] == 0:
|
if result[0] == 0:
|
||||||
writeToFile = open(schedulerPath, 'w')
|
writeToFile = open(schedulerPath, 'w')
|
||||||
writeToFile.writelines('error')
|
writeToFile.writelines('1325')
|
||||||
writeToFile.close()
|
writeToFile.close()
|
||||||
logging.CyberCPLogFileWriter.statusWriter(status, str(result[1]) + ' [1084][5009]')
|
logging.CyberCPLogFileWriter.statusWriter(status, str(result[1]) + ' [1084][5009]')
|
||||||
return 0
|
return 0
|
||||||
@@ -1339,7 +1339,7 @@ def submitBackupCreation(tempStoragePath, backupName, backupPath, backupDomain):
|
|||||||
if output.find('[5009') > -1:
|
if output.find('[5009') > -1:
|
||||||
logging.CyberCPLogFileWriter.writeToFile(output)
|
logging.CyberCPLogFileWriter.writeToFile(output)
|
||||||
writeToFile = open(schedulerPath, 'w')
|
writeToFile = open(schedulerPath, 'w')
|
||||||
writeToFile.writelines('error')
|
writeToFile.writelines(output)
|
||||||
writeToFile.close()
|
writeToFile.close()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@@ -1355,7 +1355,7 @@ def submitBackupCreation(tempStoragePath, backupName, backupPath, backupDomain):
|
|||||||
|
|
||||||
if mysqlUtilities.mysqlUtilities.createDatabaseBackup(dbName, '/home/cyberpanel') == 0:
|
if mysqlUtilities.mysqlUtilities.createDatabaseBackup(dbName, '/home/cyberpanel') == 0:
|
||||||
writeToFile = open(schedulerPath, 'w')
|
writeToFile = open(schedulerPath, 'w')
|
||||||
writeToFile.writelines('error')
|
writeToFile.writelines('1358')
|
||||||
writeToFile.close()
|
writeToFile.close()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user