diff --git a/backup/backupManager.py b/backup/backupManager.py index 38f82d796..070353c05 100755 --- a/backup/backupManager.py +++ b/backup/backupManager.py @@ -751,7 +751,7 @@ class BackupManager: return HttpResponse(final_json) except BaseException as msg: - final_dic = {'restoreStatus': 0, 'error_message': str(msg)} + final_dic = {'restoreStatus': 0, 'error_message': str(msg), 'abort': 0, 'running': 'Running..', 'status': ''} final_json = json.dumps(final_dic) return HttpResponse(final_json) diff --git a/plogical/applicationInstaller.py b/plogical/applicationInstaller.py index ce02cbb7d..2a8513822 100755 --- a/plogical/applicationInstaller.py +++ b/plogical/applicationInstaller.py @@ -6364,6 +6364,15 @@ class ApplicationInstaller(multi.Thread): logging.statusWriter(self.tempStatusPath, str(msg)) return 0, str(msg) + def UpdateDownloadStatus(self, transferred, total): + percentage = (transferred / total) * 100 + + statusFile = open(self.tempStatusPath, 'w') + statusFile.writelines(f'{int(percentage)}% of file is downloaded from remote server..,50') + statusFile.close() + + + def StartOCRestore(self): try: @@ -6400,12 +6409,13 @@ class ApplicationInstaller(multi.Thread): ssh.connect(ip, username=ocb.sftpUser, pkey=key) sftp = ssh.open_sftp() - sftp.get(f'cpbackups/{folder}/{backupfile}', f'/home/cyberpanel/{backupfile}') + sftp.get(f'cpbackups/{folder}/{backupfile}', f'/home/cyberpanel/{backupfile}', callback=self.UpdateDownloadStatus) if not os.path.exists('/home/backup'): command = 'mkdir /home/backup' ProcessUtilities.executioner(command) + command = f'mv /home/cyberpanel/{backupfile} /home/backup/{backupfile}' ProcessUtilities.executioner(command) @@ -6413,6 +6423,12 @@ class ApplicationInstaller(multi.Thread): wm = BackupManager() resp = wm.submitRestore({'backupFile': backupfile}, userID) + statusFile = open(tempStatusPath, 'w') + statusFile.writelines("Download finished..,60") + statusFile.close() + + time.sleep(6) + if json.loads(resp.content)['restoreStatus'] == 0: statusFile = open(tempStatusPath, 'w') statusFile.writelines(f"Failed to restore backup. Error {json.loads(resp.content)['error_message']}. [404]") @@ -6423,13 +6439,21 @@ class ApplicationInstaller(multi.Thread): return 0 + if os.path.exists(ProcessUtilities.debugPath): + logging.writeToFile(f'Name of of the backup file downloaded: {backupfile}') + while True: resp = wm.restoreStatus({'backupFile': backupfile}) + resp = json.loads(resp.content) + if os.path.exists(ProcessUtilities.debugPath): + logging.writeToFile(f'Responce from status function: {str(resp)}') + + if resp['abort'] == 1 and resp['running'] == 'Completed': statusFile = open(tempStatusPath, 'w') - statusFile.writelines("Successfully Installed. [200]") + statusFile.writelines("Successfully Restored. [200]") statusFile.close() command = f'rm -f /home/backup/{backupfile}' ProcessUtilities.executioner(command) @@ -6437,7 +6461,7 @@ class ApplicationInstaller(multi.Thread): elif resp['abort'] == 1 and resp['running'] == 'Error': statusFile = open(tempStatusPath, 'w') statusFile.writelines( - f"Failed to restore backup. Error {resp['status']}. [404]") + f"Failed to restore backup. Error {str(resp['status'])}. [404]") statusFile.close() command = f'rm -f /home/backup/{backupfile}' ProcessUtilities.executioner(command) @@ -6446,8 +6470,6 @@ class ApplicationInstaller(multi.Thread): statusFile = open(tempStatusPath, 'w') statusFile.writelines(f"{resp['status']},60") statusFile.close() - command = f'rm -f /home/backup/{backupfile}' - ProcessUtilities.executioner(command) time.sleep(3) except BaseException as msg: