bug fix to wp backups

This commit is contained in:
usmannasir
2024-09-29 14:35:14 +05:00
parent d72595ecb2
commit 1735553b1f
2 changed files with 158 additions and 189 deletions

View File

@@ -2795,7 +2795,7 @@ class ApplicationInstaller(multi.Thread):
###only backup of data base ###only backup of data base
logging.statusWriter(self.tempStatusPath, 'Getting database...,20') logging.statusWriter(self.tempStatusPath, 'Getting database...,20')
command = f'{FinalPHPPath} -d error_reporting=0 /usr/bin/wp config get DB_NAME --skip-plugins --skip-themes --path={WPsitepath}' command = f'sudo -u {VHuser} {FinalPHPPath} -d error_reporting=0 /usr/bin/wp config get DB_NAME --skip-plugins --skip-themes --path={WPsitepath}'
retStatus, stdoutput = ProcessUtilities.outputExecutioner(command, None, None, None, 1) retStatus, stdoutput = ProcessUtilities.outputExecutioner(command, None, None, None, 1)
if stdoutput.find('Error:') == -1: if stdoutput.find('Error:') == -1:
@@ -2806,7 +2806,7 @@ class ApplicationInstaller(multi.Thread):
if os.path.exists(ProcessUtilities.debugPath): if os.path.exists(ProcessUtilities.debugPath):
logging.writeToFile(f'DB Name: {DataBaseName}') logging.writeToFile(f'DB Name: {DataBaseName}')
command = f'{FinalPHPPath} -d error_reporting=0 /usr/bin/wp config get DB_USER --skip-plugins --skip-themes --path={WPsitepath}' command = f'sudo -u {VHuser} {FinalPHPPath} -d error_reporting=0 /usr/bin/wp config get DB_USER --skip-plugins --skip-themes --path={WPsitepath}'
retStatus, stdoutput = ProcessUtilities.outputExecutioner(command, None, None, None, 1) retStatus, stdoutput = ProcessUtilities.outputExecutioner(command, None, None, None, 1)
if stdoutput.find('Error:') == -1: if stdoutput.find('Error:') == -1:
@@ -5294,42 +5294,46 @@ class ApplicationInstaller(multi.Thread):
newWPpath = wpsite.path newWPpath = wpsite.path
newurl = wpsite.FinalURL newurl = wpsite.FinalURL
## get WPsite Database name and usr ## get WPsite Database name and usr
php = PHPManager.getPHPString(PhpVersion) from plogical.phpUtilities import phpUtilities
FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php)
#####Get DBname vhFile = f'/usr/local/lsws/conf/vhosts/{wpsite.owner.domain}/vhost.conf'
command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_NAME --skip-plugins --skip-themes --path=%s' % ( FinalPHPPath = phpUtilities.GetPHPVersionFromFile(vhFile, wpsite.owner.domain)
VHuser, FinalPHPPath, newWPpath)
result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1)
if stdout.find('Error:') == -1: # #####Get DBname
Finaldbname = stdout.rstrip("\n") # command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_NAME --skip-plugins --skip-themes --path=%s' % (
else: # VHuser, FinalPHPPath, newWPpath)
raise BaseException(stdout) # result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1)
#
#####Get DBuser # if stdout.find('Error:') == -1:
command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_USER --skip-plugins --skip-themes --path=%s' % ( # Finaldbname = stdout.rstrip("\n")
VHuser, FinalPHPPath, newWPpath) # else:
result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) # raise BaseException(stdout)
#
if stdout.find('Error:') == -1: # #####Get DBuser
Finaldbuser = stdout.rstrip("\n") # command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_USER --skip-plugins --skip-themes --path=%s' % (
else: # VHuser, FinalPHPPath, newWPpath)
raise BaseException(stdout) # result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1)
#
#####Get DBpsswd # if stdout.find('Error:') == -1:
command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_PASSWORD --skip-plugins --skip-themes --path=%s' % ( # Finaldbuser = stdout.rstrip("\n")
VHuser, FinalPHPPath, newWPpath) # else:
result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) # raise BaseException(stdout)
#
if stdout.find('Error:') == -1: # #####Get DBpsswd
Finaldbpasswd = stdout.rstrip("\n") # command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_PASSWORD --skip-plugins --skip-themes --path=%s' % (
else: # VHuser, FinalPHPPath, newWPpath)
raise BaseException(stdout) # result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1)
#
# if stdout.find('Error:') == -1:
# Finaldbpasswd = stdout.rstrip("\n")
# else:
# raise BaseException(stdout)
# dump Mysql file in unzippath path # dump Mysql file in unzippath path
unzippathdb = "%s/ab/usr/local/CyberCP/tmp/%s/%s" % (self.tempPath, oldtemppath, DumpFileName) unzippathdb = "%s/ab/usr/local/CyberCP/tmp/%s/%s" % (self.tempPath, oldtemppath, DumpFileName)
# command = "mysql -u root %s < %s" % (Finaldbname, unzippathdb) # command = "mysql -u root %s < %s" % (Finaldbname, unzippathdb)
command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp --allow-root --skip-plugins --skip-themes --path=%s --quiet db import %s' % ( command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp --allow-root --skip-plugins --skip-themes --path=%s --quiet db import %s' % (
@@ -5341,31 +5345,31 @@ class ApplicationInstaller(multi.Thread):
raise BaseException(stdout) raise BaseException(stdout)
logging.statusWriter(self.tempStatusPath, 'Restoreing Data Base...,70') logging.statusWriter(self.tempStatusPath, 'Restoreing Data Base...,70')
#####SetUp DataBase Settings # #####SetUp DataBase Settings
##set DBName # ##set DBName
command = "sudo -u %s %s /usr/bin/wp config set DB_NAME %s --skip-plugins --skip-themes --path=%s" % ( # command = "sudo -u %s %s /usr/bin/wp config set DB_NAME %s --skip-plugins --skip-themes --path=%s" % (
VHuser, FinalPHPPath, Finaldbname, newWPpath) # VHuser, FinalPHPPath, Finaldbname, newWPpath)
result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) # result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1)
#
if stdout.find('Error:') > -1: # if stdout.find('Error:') > -1:
raise BaseException(stdout) # raise BaseException(stdout)
#
##set DBuser # ##set DBuser
command = "sudo -u %s %s /usr/bin/wp config set DB_USER %s --skip-plugins --skip-themes --path=%s" % ( # command = "sudo -u %s %s /usr/bin/wp config set DB_USER %s --skip-plugins --skip-themes --path=%s" % (
VHuser, FinalPHPPath, Finaldbuser, newWPpath) # VHuser, FinalPHPPath, Finaldbuser, newWPpath)
#
result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) # result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1)
#
if stdout.find('Error:') > -1: # if stdout.find('Error:') > -1:
raise BaseException(stdout) # raise BaseException(stdout)
#
##set DBpasswd # ##set DBpasswd
command = "sudo -u %s %s /usr/bin/wp config set DB_PASSWORD %s --skip-plugins --skip-themes --path=%s" % ( # command = "sudo -u %s %s /usr/bin/wp config set DB_PASSWORD %s --skip-plugins --skip-themes --path=%s" % (
VHuser, FinalPHPPath, Finaldbpasswd, newWPpath) # VHuser, FinalPHPPath, Finaldbpasswd, newWPpath)
result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) # result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1)
#
if stdout.find('Error:') > -1: # if stdout.find('Error:') > -1:
raise BaseException(stdout) # raise BaseException(stdout)
logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90')
########Now Replace URL's ########Now Replace URL's
@@ -5421,57 +5425,59 @@ class ApplicationInstaller(multi.Thread):
VHuser = wpsite.owner.externalApp VHuser = wpsite.owner.externalApp
PhpVersion = WPobj.owner.phpSelection PhpVersion = WPobj.owner.phpSelection
newWPpath = WPobj.path newWPpath = WPobj.path
WPpath = newWPpath
php = PHPManager.getPHPString(PhpVersion) php = PHPManager.getPHPString(PhpVersion)
FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php)
Newurl = finalurl
unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % (self.tempPath, oldtemppath) # unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % (self.tempPath, oldtemppath)
#
command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, newWPpath) # command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, newWPpath)
result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) # result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1)
#
if result == 0: # if result == 0:
raise BaseException(stdout) # raise BaseException(stdout)
#
command = "sudo -u %s cp -R %s.[^.]* %s" % (VHuser, unzippath, newWPpath) # command = "sudo -u %s cp -R %s.[^.]* %s" % (VHuser, unzippath, newWPpath)
result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) # result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1)
#
if result == 0: # if result == 0:
raise BaseException(stdout) # raise BaseException(stdout)
#
logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') # logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90')
########Now Replace URL's # ########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 = '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"' % (
VHuser, newWPpath, oldurl, finalurl) # VHuser, newWPpath, oldurl, finalurl)
result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) # result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1)
#
if stdout.find('Error:') > -1: # if stdout.find('Error:') > -1:
raise BaseException(stdout) # 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 --path=https://%s "http://%s" "%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=https://%s "http://%s" "%s"' % (
VHuser, newWPpath, finalurl, finalurl) # VHuser, newWPpath, finalurl, finalurl)
result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) # result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1)
#
if stdout.find('Error:') > -1: # if stdout.find('Error:') > -1:
raise BaseException(stdout) # 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 = '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"' % (
VHuser, newWPpath, finalurl, finalurl) # VHuser, newWPpath, finalurl, finalurl)
result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) # result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1)
#
if stdout.find('Error:') > -1: # if stdout.find('Error:') > -1:
raise BaseException(stdout) # 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} /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp litespeed-purge all --path={newWPpath}'
ProcessUtilities.outputExecutioner(command, None, None, None, 1) # ProcessUtilities.outputExecutioner(command, None, None, None, 1)
#
# ##Remove temppath # # ##Remove temppath
command = f'rm -rf {self.tempPath}' # 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: # if result == 0:
raise BaseException(stdout) # raise BaseException(stdout)
except: except:
####Website found --> WPsite Found --> Final URL Not Match ####Website found --> WPsite Found --> Final URL Not Match
@@ -5485,51 +5491,6 @@ class ApplicationInstaller(multi.Thread):
### Create secure folder ### Create secure folder
ACLManager.CreateSecureDir()
RandomPath = str(randint(1000, 9999))
self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath)
command = f'mkdir -p {self.tempPath}'
result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1)
if result == 0:
raise BaseException(stdout)
command = f'chown -R {wpsite.owner.externalApp}:{wpsite.owner.externalApp} {self.tempPath}'
result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1)
if result == 0:
raise BaseException(stdout)
logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,30')
###First copy backup file to temp and then Unzip
command = "sudo -u %s cp -R /home/backup/%s* %s" % (
VHuser, BackUpFileName, self.tempPath)
result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1)
if result == 0:
raise BaseException(stdout)
#### Make temp dir ab for unzip
command = "sudo -u %s mkdir %s/ab" % (VHuser, self.tempPath)
result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1)
if result == 0:
raise BaseException(stdout)
command = f'chown {VHuser}:{VHuser} {self.tempPath}/{BackUpFileName}.tar.gz'
result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1)
if result == 0:
raise BaseException(stdout)
command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % (
VHuser, self.tempPath, BackUpFileName, self.tempPath)
result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1)
if result == 0:
raise BaseException(stdout)
unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % (self.tempPath, oldtemppath) unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/" % (self.tempPath, oldtemppath)
@@ -5545,28 +5506,30 @@ class ApplicationInstaller(multi.Thread):
if result == 0: if result == 0:
raise BaseException(stdout) raise BaseException(stdout)
logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') ### why replace urls in only website data restore???
########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"' % (
VHuser, WPpath, oldurl, Newurl)
result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1)
if stdout.find('Error:') > -1: # logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90')
raise BaseException(stdout) # ########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 = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "http://%s" "https://%s"' % ( # VHuser, WPpath, oldurl, Newurl)
VHuser, WPpath, Newurl, Newurl) # result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1)
result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) #
# if stdout.find('Error:') > -1:
if stdout.find('Error:') > -1: # raise BaseException(stdout)
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 --path=%s "http://%s" "https://%s"' % (
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"' % ( # VHuser, WPpath, Newurl, Newurl)
VHuser, WPpath, Newurl, Newurl) # result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1)
result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) #
# if stdout.find('Error:') > -1:
if stdout.find('Error:') > -1: # raise BaseException(stdout)
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"' % (
# VHuser, WPpath, 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={WPpath}' command = f'sudo -u {VHuser} /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp litespeed-purge all --path={WPpath}'
ProcessUtilities.outputExecutioner(command, None, None, None, 1) ProcessUtilities.outputExecutioner(command, None, None, None, 1)
@@ -6366,7 +6329,6 @@ class ApplicationInstaller(multi.Thread):
logging.statusWriter(self.tempStatusPath, f'{str(msg)}. [404]') logging.statusWriter(self.tempStatusPath, f'{str(msg)}. [404]')
return 0, str(msg) return 0, str(msg)
def UpdateDownloadStatus(self, transferred, total): def UpdateDownloadStatus(self, transferred, total):
percentage = (transferred / total) * 100 percentage = (transferred / total) * 100

View File

@@ -231,9 +231,16 @@ class WebsiteManager:
Data['FileName'] = config['name'] Data['FileName'] = config['name']
try: try:
Data['Backuptype'] = config['Backuptype'] Data['Backuptype'] = config['Backuptype']
if Data['Backuptype'] == 'DataBase Backup' or Data['Backuptype'] == 'Website Backup':
Data['WPsites'] = [WPSites.objects.get(pk=Data['backupobj'].WPSiteID)]
else:
Data['WPsites'] = ACLManager.GetALLWPObjects(currentACL, userID)
except: except:
Data['Backuptype'] = None Data['Backuptype'] = None
Data['WPsites'] = ACLManager.GetALLWPObjects(currentACL, userID) Data['WPsites'] = ACLManager.GetALLWPObjects(currentACL, userID)
proc = httpProc(request, 'websiteFunctions/WPRestoreHome.html', proc = httpProc(request, 'websiteFunctions/WPRestoreHome.html',
Data, 'createWebsite') Data, 'createWebsite')
return proc.render() return proc.render()