mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-16 10:16:12 +01:00
fix issues in backups wp
This commit is contained in:
@@ -6,8 +6,6 @@ import time
|
|||||||
|
|
||||||
from loginSystem.models import Administrator
|
from loginSystem.models import Administrator
|
||||||
from plogical.acl import ACLManager
|
from plogical.acl import ACLManager
|
||||||
|
|
||||||
|
|
||||||
sys.path.append('/usr/local/CyberCP')
|
sys.path.append('/usr/local/CyberCP')
|
||||||
import django
|
import django
|
||||||
|
|
||||||
@@ -2285,14 +2283,22 @@ $parameters = array(
|
|||||||
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'{FinalPHPPath} -d error_reporting=0 /usr/bin/wp config get DB_NAME --skip-plugins --skip-themes --path={WPsitepath}'
|
||||||
stdoutput = ProcessUtilities.outputExecutioner(command, VHuser)
|
|
||||||
DataBaseName = stdoutput.rstrip("\n")
|
retStatus, stdoutput = ProcessUtilities.outputExecutioner(command, VHuser, None, None, 1)
|
||||||
|
|
||||||
|
if stdoutput.find('Error:') == -1:
|
||||||
|
DataBaseName = stdoutput.rstrip("\n")
|
||||||
|
else:
|
||||||
|
raise BaseException(stdoutput)
|
||||||
|
|
||||||
|
|
||||||
command = f'{FinalPHPPath} -d error_reporting=0 /usr/bin/wp config get DB_USER --skip-plugins --skip-themes --path={WPsitepath}'
|
command = f'{FinalPHPPath} -d error_reporting=0 /usr/bin/wp config get DB_USER --skip-plugins --skip-themes --path={WPsitepath}'
|
||||||
stdoutput = ProcessUtilities.outputExecutioner(command,VHuser)
|
retStatus, stdoutput = ProcessUtilities.outputExecutioner(command,VHuser, None, None, 1)
|
||||||
DataBaseUser = stdoutput.rstrip("\n")
|
|
||||||
|
|
||||||
|
if stdoutput.find('Error:') == -1:
|
||||||
|
DataBaseUser = stdoutput.rstrip("\n")
|
||||||
|
else:
|
||||||
|
raise BaseException(stdoutput)
|
||||||
|
|
||||||
### Create secure folder
|
### Create secure folder
|
||||||
|
|
||||||
@@ -2346,40 +2352,52 @@ $parameters = array(
|
|||||||
os.chmod(configPath, 0o600)
|
os.chmod(configPath, 0o600)
|
||||||
|
|
||||||
command = f"cp -R {configPath} {self.tempPath}"
|
command = f"cp -R {configPath} {self.tempPath}"
|
||||||
ProcessUtilities.executioner(command, VHuser)
|
if ProcessUtilities.executioner(command, VHuser) == 0:
|
||||||
|
raise BaseException('Failed to config to temp path.')
|
||||||
|
|
||||||
|
|
||||||
command = f"rm -r {configPath}"
|
command = f"rm -r {configPath}"
|
||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
|
if ProcessUtilities.executioner(command, VHuser) == 0:
|
||||||
|
raise BaseException('Failed to remove config.')
|
||||||
|
|
||||||
logging.statusWriter(self.tempStatusPath, 'Copying website data.....,50')
|
logging.statusWriter(self.tempStatusPath, 'Copying website data.....,50')
|
||||||
|
|
||||||
############## Copy Public_htnl to backup
|
############## Copy Public_htnl to backup
|
||||||
command = "sudo -u %s cp -R %s* %s/public_html" % (VHuser, WPsitepath, self.tempPath)
|
command = "sudo -u %s cp -R %s* %s/public_html" % (VHuser, WPsitepath, self.tempPath)
|
||||||
result = ProcessUtilities.outputExecutioner(command)
|
retStatus, result = ProcessUtilities.outputExecutioner(command, None, None, None, 1)
|
||||||
|
|
||||||
|
if retStatus == 0:
|
||||||
|
raise BaseException(result)
|
||||||
|
|
||||||
if os.path.exists(ProcessUtilities.debugPath):
|
if os.path.exists(ProcessUtilities.debugPath):
|
||||||
logging.writeToFile(result)
|
logging.writeToFile(result)
|
||||||
|
|
||||||
command = "sudo -u %s cp -R %s.[^.]* %s/public_html/" % (VHuser, WPsitepath, self.tempPath)
|
command = "sudo -u %s cp -R %s.[^.]* %s/public_html/" % (VHuser, WPsitepath, self.tempPath)
|
||||||
result = ProcessUtilities.outputExecutioner(command)
|
retStatus, result = ProcessUtilities.outputExecutioner(command, None, None, None, 1)
|
||||||
|
|
||||||
|
if retStatus == 0:
|
||||||
|
raise BaseException(result)
|
||||||
|
|
||||||
if os.path.exists(ProcessUtilities.debugPath):
|
if os.path.exists(ProcessUtilities.debugPath):
|
||||||
logging.writeToFile(result)
|
logging.writeToFile(result)
|
||||||
|
|
||||||
logging.statusWriter(self.tempStatusPath, 'Copying DataBase.....,70')
|
logging.statusWriter(self.tempStatusPath, 'Copying database.....,70')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
##### SQLDUMP database into new directory
|
##### SQLDUMP database into new directory
|
||||||
|
|
||||||
command = "mysqldump %s --result-file %s/%s.sql" % (DataBaseName, self.tempPath, DataBaseName)
|
command = "mysqldump %s --result-file %s/%s.sql" % (DataBaseName, self.tempPath, DataBaseName)
|
||||||
result = ProcessUtilities.outputExecutioner(command)
|
retStatus, result = ProcessUtilities.outputExecutioner(command, None, None, None, 1)
|
||||||
|
|
||||||
|
if retStatus == 0:
|
||||||
|
raise BaseException(result)
|
||||||
|
|
||||||
if os.path.exists(ProcessUtilities.debugPath):
|
if os.path.exists(ProcessUtilities.debugPath):
|
||||||
logging.writeToFile(result)
|
logging.writeToFile(result)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
######## Zip backup directory
|
######## Zip backup directory
|
||||||
logging.statusWriter(self.tempStatusPath, 'Compressing backup files.....,80')
|
logging.statusWriter(self.tempStatusPath, 'Compressing backup files.....,80')
|
||||||
|
|
||||||
@@ -2391,13 +2409,17 @@ $parameters = array(
|
|||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
command = f"tar -czvf /home/backup/{config['name']}.tar.gz -P {self.tempPath}"
|
command = f"tar -czvf /home/backup/{config['name']}.tar.gz -P {self.tempPath}"
|
||||||
result = ProcessUtilities.outputExecutioner(command)
|
retStatus, result = ProcessUtilities.outputExecutioner(command, None, None, None, 1)
|
||||||
|
|
||||||
|
if retStatus == 0:
|
||||||
|
raise BaseException(result)
|
||||||
|
|
||||||
|
if os.path.exists(ProcessUtilities.debugPath):
|
||||||
|
logging.writeToFile(result)
|
||||||
|
|
||||||
|
|
||||||
backupobj = WPSitesBackup(owner=Adminobj, WPSiteID=wpsite.id, WebsiteID=website.id, config=json_object)
|
backupobj = WPSitesBackup(owner=Adminobj, WPSiteID=wpsite.id, WebsiteID=website.id, config=json_object)
|
||||||
backupobj.save()
|
backupobj.save()
|
||||||
if os.path.exists(ProcessUtilities.debugPath):
|
|
||||||
logging.writeToFile(result)
|
|
||||||
|
|
||||||
command = f'rm -rf {self.tempPath}'
|
command = f'rm -rf {self.tempPath}'
|
||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
@@ -2449,6 +2471,7 @@ $parameters = array(
|
|||||||
# command = "sudo -u %s touch /home/cyberpanel/config.json" % (VHuser)
|
# command = "sudo -u %s touch /home/cyberpanel/config.json" % (VHuser)
|
||||||
# ProcessUtilities.executioner(command)
|
# ProcessUtilities.executioner(command)
|
||||||
###### write into config
|
###### write into config
|
||||||
|
|
||||||
json_object = json.dumps(config, indent=4)
|
json_object = json.dumps(config, indent=4)
|
||||||
configPath = "/home/cyberpanel/" + str(randint(1000, 9999))
|
configPath = "/home/cyberpanel/" + str(randint(1000, 9999))
|
||||||
file = open(configPath, "w")
|
file = open(configPath, "w")
|
||||||
@@ -2458,22 +2481,33 @@ $parameters = array(
|
|||||||
os.chmod(configPath, 0o600)
|
os.chmod(configPath, 0o600)
|
||||||
|
|
||||||
command = f"cp -R {configPath} {self.tempPath}"
|
command = f"cp -R {configPath} {self.tempPath}"
|
||||||
ProcessUtilities.executioner(command, VHuser)
|
|
||||||
|
if ProcessUtilities.executioner(command, VHuser) == 0:
|
||||||
|
raise BaseException('Failed to copy config to temp path.')
|
||||||
|
|
||||||
command = f"rm -r {configPath}"
|
command = f"rm -r {configPath}"
|
||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
if ProcessUtilities.executioner(command, VHuser) == 0:
|
||||||
|
raise BaseException('Failed to remove config temp file.')
|
||||||
|
|
||||||
logging.statusWriter(self.tempStatusPath, 'Copying website data.....,50')
|
logging.statusWriter(self.tempStatusPath, 'Copying website data.....,50')
|
||||||
|
|
||||||
############## Copy Public_htnl to backup
|
############## Copy Public_htnl to backup
|
||||||
command = "sudo -u %s cp -R %s* %s/public_html" % (VHuser, WPsitepath, self.tempPath)
|
command = "sudo -u %s cp -R %s* %s/public_html" % (VHuser, WPsitepath, self.tempPath)
|
||||||
result = ProcessUtilities.outputExecutioner(command)
|
retStatus, result = ProcessUtilities.outputExecutioner(command, None, None, None, 1)
|
||||||
|
|
||||||
|
if retStatus == 0:
|
||||||
|
raise BaseException(result)
|
||||||
|
|
||||||
if os.path.exists(ProcessUtilities.debugPath):
|
if os.path.exists(ProcessUtilities.debugPath):
|
||||||
logging.writeToFile(result)
|
logging.writeToFile(result)
|
||||||
|
|
||||||
command = "sudo -u %s cp -R %s.[^.]* %s/public_html/" % (VHuser, WPsitepath, self.tempPath)
|
command = "sudo -u %s cp -R %s.[^.]* %s/public_html/" % (VHuser, WPsitepath, self.tempPath)
|
||||||
result = ProcessUtilities.outputExecutioner(command)
|
retStatus, result = ProcessUtilities.outputExecutioner(command, None, None, None, 1)
|
||||||
|
|
||||||
|
if retStatus == 0:
|
||||||
|
raise BaseException(result)
|
||||||
|
|
||||||
if os.path.exists(ProcessUtilities.debugPath):
|
if os.path.exists(ProcessUtilities.debugPath):
|
||||||
logging.writeToFile(result)
|
logging.writeToFile(result)
|
||||||
@@ -2489,7 +2523,10 @@ $parameters = array(
|
|||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
command = f"tar -czvf /home/backup/{config['name']}.tar.gz -P {self.tempPath}"
|
command = f"tar -czvf /home/backup/{config['name']}.tar.gz -P {self.tempPath}"
|
||||||
result = ProcessUtilities.outputExecutioner(command)
|
retStatus, result = ProcessUtilities.outputExecutioner(command, None, None, None, 1)
|
||||||
|
|
||||||
|
if retStatus == 0:
|
||||||
|
raise BaseException(result)
|
||||||
|
|
||||||
backupobj = WPSitesBackup(owner=Adminobj, WPSiteID=wpsite.id, WebsiteID=website.id,
|
backupobj = WPSitesBackup(owner=Adminobj, WPSiteID=wpsite.id, WebsiteID=website.id,
|
||||||
config=json_object)
|
config=json_object)
|
||||||
@@ -2605,9 +2642,12 @@ $parameters = array(
|
|||||||
|
|
||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
logging.writeToFile("Error WPCreateBackup ....... %s" % str(msg))
|
logging.writeToFile("Error WPCreateBackup ....... %s" % str(msg))
|
||||||
command = f'rm -rf {self.tempPath}'
|
try:
|
||||||
ProcessUtilities.executioner(command)
|
command = f'rm -rf {self.tempPath}'
|
||||||
logging.statusWriter(self.tempStatusPath, str(msg))
|
ProcessUtilities.executioner(command)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
logging.statusWriter(self.tempStatusPath, f'{str(msg)}. [404]')
|
||||||
return 0, str(msg)
|
return 0, str(msg)
|
||||||
|
|
||||||
def RestoreWPbackupNow(self):
|
def RestoreWPbackupNow(self):
|
||||||
@@ -2625,7 +2665,6 @@ $parameters = array(
|
|||||||
userID = self.extraArgs['adminID']
|
userID = self.extraArgs['adminID']
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#### First get BAckup file from backupobj
|
#### First get BAckup file from backupobj
|
||||||
|
|
||||||
backupobj = WPSitesBackup.objects.get(pk=backupid)
|
backupobj = WPSitesBackup.objects.get(pk=backupid)
|
||||||
@@ -3268,8 +3307,11 @@ $parameters = array(
|
|||||||
logging.statusWriter(self.tempStatusPath, 'Completed.[200]')
|
logging.statusWriter(self.tempStatusPath, 'Completed.[200]')
|
||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
logging.writeToFile("Error RestoreWPbackupNow ....... %s" % str(msg))
|
logging.writeToFile("Error RestoreWPbackupNow ....... %s" % str(msg))
|
||||||
command = f'rm -rf {self.tempPath}'
|
try:
|
||||||
ProcessUtilities.executioner(command)
|
command = f'rm -rf {self.tempPath}'
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
logging.statusWriter(self.tempStatusPath, str(msg))
|
logging.statusWriter(self.tempStatusPath, str(msg))
|
||||||
return 0, str(msg)
|
return 0, str(msg)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user