diff --git a/plogical/IncScheduler.py b/plogical/IncScheduler.py index 91f1eae4f..66990fcac 100644 --- a/plogical/IncScheduler.py +++ b/plogical/IncScheduler.py @@ -1117,18 +1117,18 @@ def WPUpdates(): @staticmethod def RemoteBackup(function): try: - # print("....start remote backup...............") + print("....start remote backup...............") from websiteFunctions.models import RemoteBackupSchedule, RemoteBackupsites, WPSites from loginSystem.models import Administrator import json import time from plogical.applicationInstaller import ApplicationInstaller for config in RemoteBackupSchedule.objects.all(): - # print("....start remote backup........site.......%s"%config.Name) + print("....start remote backup........site.......%s"%config.Name) try: configbakup = json.loads(config.config) backuptype = configbakup['BackupType'] - # print("....start remote backup........site.......%s.. and bakuptype...%s" % (config.Name, backuptype)) + print("....start remote backup........site.......%s.. and bakuptype...%s" % (config.Name, backuptype)) if backuptype == 'Only DataBase': Backuptype = "3" elif backuptype == 'Only Website': @@ -1140,12 +1140,12 @@ def RemoteBackup(function): continue try: allRemoteBackupsiteobj = RemoteBackupsites.objects.filter(owner=config) - # print("store site id.....%s"%str(allRemoteBackupsiteobj)) + print("store site id.....%s"%str(allRemoteBackupsiteobj)) for i in allRemoteBackupsiteobj: try: backupsiteID = i.WPsites wpsite = WPSites.objects.get(pk=backupsiteID) - # print("site name.....%s"%wpsite.title) + print("site name.....%s"%wpsite.title) AdminID = wpsite.owner.admin_id Admin = Administrator.objects.get(pk=AdminID) @@ -1401,23 +1401,42 @@ def SendTORemote(FileName, RemoteBackupID): Password = config['Password'] Path = config['Path'] - cnopts = sftp.CnOpts() - cnopts.hostkeys = None + # Connect to the remote server using the private key + ssh = paramiko.SSHClient() + ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) - with pysftp.Connection(HostName, username=Username, password=Password, cnopts=cnopts) as sftp: - print("Connection succesfully stablished ... ") + # Connect to the server using the private key + ssh.connect(HostName, username=Username, password=Password) + sftp = ssh.open_sftp() + ssh.exec_command(f'mkdir -p {Path}') - try: - with sftp.cd(Path): - sftp.put(FileName) - except: - sftp.mkdir(Path) - with sftp.cd(Path): - sftp.put(FileName) + if os.path.exists(ProcessUtilities.debugPath): + logging.writeToFile(f"Filename: {FileName}, Path {Path}/{FileName.split('/')[-1]}. [SendTORemote]") + + sftp.put(FileName, f"{Path}/{FileName.split('/')[-1]}") + + # sftp.get(str(remotepath), str(loaclpath), + # callback=self.UpdateDownloadStatus) + # + # cnopts = sftp.CnOpts() + # cnopts.hostkeys = None + # + # with pysftp.Connection(HostName, username=Username, password=Password, cnopts=cnopts) as sftp: + # print("Connection succesfully stablished ... ") + # + # try: + # with sftp.cd(Path): + # sftp.put(FileName) + # except BaseException as msg: + # print(f'Error on {str(msg)}') + # sftp.mkdir(Path) + # with sftp.cd(Path): + # sftp.put(FileName) except BaseException as msg: + print('%s. [SendTORemote]' % (str(msg))) logging.writeToFile('%s. [SendTORemote]' % (str(msg))) @staticmethod diff --git a/plogical/applicationInstaller.py b/plogical/applicationInstaller.py index 01dca6bdc..fe9a2a7c0 100755 --- a/plogical/applicationInstaller.py +++ b/plogical/applicationInstaller.py @@ -2643,7 +2643,7 @@ def WPCreateBackup(self): backupobj.save() command = f'rm -rf {self.tempPath}' - result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + #result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) if result == 0: raise BaseException(stdout) @@ -2948,6 +2948,7 @@ def WPCreateBackup(self): ProcessUtilities.executioner(command) except: pass + logging.statusWriter(self.tempStatusPath, f'{str(msg)}. [404]') return 0, str(msg), None @@ -3002,18 +3003,44 @@ def RestoreWPbackupNow(self): Username = RemoteBackupconf['Username'] Password = RemoteBackupconf['Password'] Path = RemoteBackupconf['Path'] - cnopts = sftp.CnOpts() - cnopts.hostkeys = None - with pysftp.Connection(HostName, username=Username, password=Password, cnopts=cnopts) as sftp: - logging.statusWriter(self.tempStatusPath, 'Downloading Backups...,15') - loaclpath = "/home/cyberpanel/%s.tar.gz" % BackUpFileName - remotepath = "%s/%s.tar.gz" % (Path, BackUpFileName) - logging.writeToFile("Downloading start") - sftp.get(str(remotepath), str(loaclpath)) - command = "mv %s /home/backup/" % loaclpath - ProcessUtilities.executioner(command) + #### + + # Connect to the remote server using the private key + ssh = paramiko.SSHClient() + ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + + # Connect to the server using the private key + ssh.connect(HostName, username=Username, password=Password) + sftp = ssh.open_sftp() + + logging.statusWriter(self.tempStatusPath, 'Downloading Backups...,15') + loaclpath = "/home/cyberpanel/%s.tar.gz" % BackUpFileName + remotepath = "%s/%s.tar.gz" % (Path, BackUpFileName) + logging.writeToFile("Downloading start") + + sftp.get(str(remotepath), str(loaclpath), + callback=self.UpdateDownloadStatus) + + command = "mv %s /home/backup/" % loaclpath + ProcessUtilities.executioner(command) + + ## + + + # cnopts = sftp.CnOpts() + # cnopts.hostkeys = None + # + # with pysftp.Connection(HostName, username=Username, password=Password, cnopts=cnopts) as sftp: + # logging.statusWriter(self.tempStatusPath, 'Downloading Backups...,15') + # loaclpath = "/home/cyberpanel/%s.tar.gz" % BackUpFileName + # remotepath = "%s/%s.tar.gz" % (Path, BackUpFileName) + # logging.writeToFile("Downloading start") + # sftp.get(str(remotepath), str(loaclpath)) + # + # command = "mv %s /home/backup/" % loaclpath + # ProcessUtilities.executioner(command) # ##### CHeck if Backup type is Only Database # if BackupType == 'DataBase Backup': @@ -5280,6 +5307,14 @@ def RestoreWPbackupNow(self): raise BaseException(stdout) + if os.path.exists(ProcessUtilities.debugPath): + + if os.path.exists(f'/home/backup/{BackUpFileName}'): + logging.writeToFile(f'Backup file is present and downloaded {str(stdout)}') + logging.writeToFile(f'Extracting to {str(self.tempPath)}') + + + logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,30') #### Make temp dir ab for unzip @@ -5295,6 +5330,15 @@ def RestoreWPbackupNow(self): if result == 0: raise BaseException(stdout) + if os.path.exists(ProcessUtilities.debugPath): + + logging.writeToFile(f'Output of archive {str(stdout)}') + + command = f"ls -lh {self.tempPath}/ab" + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + logging.writeToFile(f'Listing files {str(stdout)}') + + ##### Check if Backup type is Only Database if BackupType == 'DataBase Backup': if (DomainName == "" and int(self.extraArgs['DesSiteID']) != -1): @@ -5870,10 +5914,10 @@ def RestoreWPbackupNow(self): ### Remove temppath command = f'rm -rf {self.tempPath}' - # result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - # - # if result == 0: - # raise BaseException(stdout) + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) # try: # WPobj = WPSites.objects.get(FinalURL=finalurl, owner=webobj) @@ -6308,21 +6352,21 @@ def RestoreWPbackupNow(self): logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') ########Now Replace URL's - command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % ( + command = f'sudo -u %s {FinalPHPPath} -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % ( VHuser, newWPpath, oldurl, newurl) result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) if stdout.find('Error:') > -1: raise BaseException(stdout) - command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % ( + command = f'sudo -u %s {FinalPHPPath} -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % ( VHuser, newWPpath, newurl, newurl) result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) if stdout.find('Error:') > -1: raise BaseException(stdout) - command = f'sudo -u {VHuser} /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp litespeed-purge all --path={newWPpath}' + command = f'sudo -u {VHuser} {FinalPHPPath} -d error_reporting=0 /usr/bin/wp litespeed-purge all --path={newWPpath}' ProcessUtilities.outputExecutioner(command, None, None, None, 1) ##Remove temppath @@ -6343,7 +6387,7 @@ def RestoreWPbackupNow(self): logging.writeToFile("Error RestoreWPbackupNow ....... %s" % str(msg)) try: command = f'rm -rf {self.tempPath}' - #ProcessUtilities.executioner(command) + ProcessUtilities.executioner(command) except: pass diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js index 5962b06f9..ae41912fa 100755 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js @@ -1967,7 +1967,7 @@ app.controller('RestoreWPBackup', function ($scope, $http, $timeout, $window) { function ListInitialDatas(response) { - $('#wordpresshomeloading').hide(); + //$('#wordpresshomeloading').hide(); if (response.data.abort === 1) { @@ -2023,7 +2023,7 @@ app.controller('RestoreWPBackup', function ($scope, $http, $timeout, $window) { } function cantLoadInitialDatas(response) { - $('#wordpresshomeloading').hide(); + //$('#wordpresshomeloading').hide(); $scope.wordpresshomeloading = true; $scope.stagingDetailsForm = true; $scope.installationProgress = false;