backup schedule bug fix

This commit is contained in:
usmannasir
2019-03-13 23:20:15 +05:00
parent bb6f7f0111
commit 84bfa17ec9
3 changed files with 29 additions and 22 deletions

View File

@@ -181,19 +181,23 @@ class BackupManager:
if status.find("Completed") > -1: if status.find("Completed") > -1:
backupOb = Backups.objects.get(fileName=fileName) backupObs = Backups.objects.filter(fileName=fileName)
backupOb.status = 1
## adding backup data to database. ## adding backup data to database.
try: try:
backupOb.size = str(int(float( for items in backupObs:
os.path.getsize("/home/" + backupDomain + "/backup/" + fileName + ".tar.gz")) / ( items.status = 1
1024.0 * 1024.0))) + "MB" items.size = str(int(float(
backupOb.save() os.path.getsize("/home/" + backupDomain + "/backup/" + fileName + ".tar.gz")) / (
1024.0 * 1024.0))) + "MB"
items.save()
except: except:
backupOb.size = str( for items in backupObs:
int(os.path.getsize("/home/" + backupDomain + "/backup/" + fileName + ".tar.gz"))) items.status = 1
backupOb.save() items.size = str(int(float(
os.path.getsize("/home/" + backupDomain + "/backup/" + fileName + ".tar.gz")) / (
1024.0 * 1024.0))) + "MB"
items.save()
### Removing Files ### Removing Files

View File

@@ -49,6 +49,7 @@ class backupSchedule:
except BaseException, msg: except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startBackup]") logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startBackup]")
return 0, "None"
@staticmethod @staticmethod
def createBackup(virtualHost, ipAddress, backupLogPath , port): def createBackup(virtualHost, ipAddress, backupLogPath , port):
@@ -147,20 +148,22 @@ class backupSchedule:
ipAddressLocal = ipData.split('\n', 1)[0] ipAddressLocal = ipData.split('\n', 1)[0]
if backupUtilities.checkIfHostIsUp(ipAddress) == 1: if backupUtilities.checkIfHostIsUp(ipAddress) != 1:
checkConn = backupUtilities.checkConnection(ipAddress) backupSchedule.remoteBackupLogging(backupLogPath, "Ping for : " + ipAddress + " does not seems to work, however we will continue.")
if checkConn[0] == 0:
backupSchedule.remoteBackupLogging(backupLogPath, "Connection to: " + ipAddress+ " Failed, please resetup this destination from CyberPanel, aborting.")
return 0
else:
## Create backup dir on remote server
command = "sudo ssh -o StrictHostKeyChecking=no -p " + port + " -i /root/.ssh/cyberpanel root@" + ipAddress + " mkdir -p /home/backup/"+ ipAddressLocal + "/" + time.strftime("%a-%b")
subprocess.call(shlex.split(command)) checkConn = backupUtilities.checkConnection(ipAddress)
pass if checkConn[0] == 0:
else: backupSchedule.remoteBackupLogging(backupLogPath,
backupSchedule.remoteBackupLogging(backupLogPath, "Host: " + ipAddress + " is down, aborting.") "Connection to: " + ipAddress + " Failed, please resetup this destination from CyberPanel, aborting.")
return 0 return 0
else:
## Create backup dir on remote server
command = "sudo ssh -o StrictHostKeyChecking=no -p " + port + " -i /root/.ssh/cyberpanel root@" + ipAddress + " mkdir -p /home/backup/" + ipAddressLocal + "/" + time.strftime(
"%a-%b")
subprocess.call(shlex.split(command))
pass
for virtualHost in os.listdir("/home"): for virtualHost in os.listdir("/home"):
if match(r'([\da-z\.-]+\.[a-z\.]{2,12}|[\d\.]+)([\/:?=&#]{1}[\da-z\.-]+)*[\/\?]?', virtualHost, M | I): if match(r'([\da-z\.-]+\.[a-z\.]{2,12}|[\d\.]+)([\/:?=&#]{1}[\da-z\.-]+)*[\/\?]?', virtualHost, M | I):