From 2cf28e8a557b5e39e875eda19f421c2c32295b12 Mon Sep 17 00:00:00 2001 From: "usman@cyberpersons.com" Date: Tue, 4 Apr 2023 18:00:38 +0500 Subject: [PATCH] fix bg run --- IncBackups/views.py | 2 -- plogical/Backupsv2.py | 22 +++++++++------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/IncBackups/views.py b/IncBackups/views.py index 389d3658a..e490bd05e 100644 --- a/IncBackups/views.py +++ b/IncBackups/views.py @@ -872,8 +872,6 @@ def RestorePathV2(request): # vm = CPBackupsV2({'domain': Selectedwebsite, 'BackendName': Selectedrepo, "function": "", 'BasePath': '/home/backup'}) # status = vm.InitiateRestore(SnapShotId, Path) - time.sleep(2) - data_ret = {'status': 1, 'installStatus': 1, 'error_message': 'None',} json_data = json.dumps(data_ret) return HttpResponse(json_data) diff --git a/plogical/Backupsv2.py b/plogical/Backupsv2.py index b3d9435c4..23b50491d 100644 --- a/plogical/Backupsv2.py +++ b/plogical/Backupsv2.py @@ -66,7 +66,6 @@ class CPBackupsV2(multi.Thread): self.restore = 0 - if os.path.exists(self.StatusFile): os.remove(self.StatusFile) @@ -76,7 +75,6 @@ class CPBackupsV2(multi.Thread): self.InitiateBackup() elif self.function == 'InitiateRestore': self.InitiateRestore() - except BaseException as msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + ' [CPBackupsV2.run]') @@ -643,15 +641,14 @@ token = {token} ### if restore then status file should be restore status file self.restore = 1 - self.StatusFile = self.StatusFile_Restore - - if os.path.exists(self.StatusFile): - os.remove(self.StatusFile) + #self.StatusFile = self.StatusFile_Restore from websiteFunctions.models import Websites from plogical.mysqlUtilities import mysqlUtilities self.website = Websites.objects.get(domain=self.data['domain']) + self.UpdateStatus('Started restoring,20', CPBackupsV2.RUNNING) + ## Base path is basically the path set by user where all the backups will be housed if not os.path.exists(self.data['BasePath']): @@ -698,27 +695,26 @@ token = {token} ### Find Restore path first, if path is db, only then restore it to cp - if self.path.find('.sql') > -1: - mysqlUtilities.restoreDatabaseBackup(self.path.rstrip('.sql'), None, None, None, None, 1, self.repo, self.website.externalApp, self.snapshotid) + if self.data["path"].find('.sql') > -1: + mysqlUtilities.restoreDatabaseBackup(self.data["path"].rstrip('.sql'), None, None, None, None, 1, self.repo, self.website.externalApp, self.data["snapshotid"]) else: - if self.path.find('/home/vmail') > -1: + if self.data["path"].find('/home/vmail') > -1: externalApp = None else: externalApp = self.website.externalApp - command = f'rustic -r {self.repo} restore {self.snapshotid}:{self.path} {self.path} --password "" --json 2>/dev/null' + command = f'rustic -r {self.repo} restore {self.data["snapshotid"]}:{self.data["path"]} {self.data["path"]} --password "" 2>/dev/null' result = ProcessUtilities.outputExecutioner(command, externalApp, True) - if os.path.exists(ProcessUtilities.debugPath): - logging.CyberCPLogFileWriter.writeToFile(result) + if os.path.exists(ProcessUtilities.debugPath): + logging.CyberCPLogFileWriter.writeToFile(result) self.UpdateStatus('Completed', CPBackupsV2.COMPLETED) return 1 - else: time.sleep(5)