bug fix: remote backup and backup restore

This commit is contained in:
Usman Nasir
2022-04-28 16:40:22 +05:00
parent 00c70bfe18
commit 80a08d4966
6 changed files with 60 additions and 6 deletions

View File

@@ -72,7 +72,7 @@ class secMiddleware:
final_json = json.dumps(final_dic) final_json = json.dumps(final_dic)
return HttpResponse(final_json) return HttpResponse(final_json)
if request.build_absolute_uri().find('api/verifyConn') > -1 or request.build_absolute_uri().find('webhook') > -1 or request.build_absolute_uri().find('saveSpamAssassinConfigurations') > -1 or request.build_absolute_uri().find('docker') > -1 or request.build_absolute_uri().find('cloudAPI') > -1 or request.build_absolute_uri().find('verifyLogin') > -1 or request.build_absolute_uri().find('submitUserCreation') > -1: if request.build_absolute_uri().find('api/remoteTransfer') > -1 or request.build_absolute_uri().find('api/verifyConn') > -1 or request.build_absolute_uri().find('webhook') > -1 or request.build_absolute_uri().find('saveSpamAssassinConfigurations') > -1 or request.build_absolute_uri().find('docker') > -1 or request.build_absolute_uri().find('cloudAPI') > -1 or request.build_absolute_uri().find('verifyLogin') > -1 or request.build_absolute_uri().find('submitUserCreation') > -1:
continue continue
if key == 'key' or key == 'cert' or key == 'recordContentAAAA' or key == 'backupDestinations' or key == 'ports' \ if key == 'key' or key == 'cert' or key == 'recordContentAAAA' or key == 'backupDestinations' or key == 'ports' \
or key == 'imageByPass' or key == 'passwordByPass' or key == 'cronCommand' \ or key == 'imageByPass' or key == 'passwordByPass' or key == 'cronCommand' \

View File

@@ -435,10 +435,14 @@ def remoteTransfer(request):
## Accounts to transfer is a path to file, containing accounts. ## Accounts to transfer is a path to file, containing accounts.
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/remoteTransferUtilities.py" execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/remoteTransferUtilities.py"
execPath = execPath + " remoteTransfer --ipAddress " + ipAddress + " --dir " + dir + " --accountsToTransfer " + path execPath = execPath + " remoteTransfer --ipAddress " + ipAddress.rstrip('\n') + " --dir " + dir + " --accountsToTransfer " + path
ProcessUtilities.popenExecutioner(execPath) ProcessUtilities.popenExecutioner(execPath)
if os.path.exists('/usr/local/CyberCP/debug'):
logging.writeToFile('Repor of %s' % repr(execPath))
return HttpResponse(json.dumps({"transferStatus": 1, "dir": dir})) return HttpResponse(json.dumps({"transferStatus": 1, "dir": dir}))
## ##

View File

@@ -1163,6 +1163,10 @@ class BackupManager:
r = requests.post(url, data=finalData, verify=False) r = requests.post(url, data=finalData, verify=False)
if os.path.exists('/usr/local/CyberCP/debug'):
message = 'Remote transfer initiation status: %s' % (r.text)
logging.CyberCPLogFileWriter.writeToFile(message)
data = json.loads(r.text) data = json.loads(r.text)
if data['transferStatus'] == 1: if data['transferStatus'] == 1:

View File

@@ -89,8 +89,21 @@ class backupSchedule:
ifRunning = ProcessUtilities.outputExecutioner('ps aux') ifRunning = ProcessUtilities.outputExecutioner('ps aux')
if os.path.exists('/usr/local/CyberCP/debug'):
message = 'Output of px aux when running remote backup status check: %s' % (ifRunning)
logging.CyberCPLogFileWriter.writeToFile(message)
if (ifRunning.find('startBackup') > -1 or ifRunning.find('BackupRoot') > -1) and ifRunning.find('/%s/' % (backupDomain)): if (ifRunning.find('startBackup') > -1 or ifRunning.find('BackupRoot') > -1) and ifRunning.find('/%s/' % (backupDomain)):
if os.path.exists('/usr/local/CyberCP/debug'):
message = 'If running found.'
logging.CyberCPLogFileWriter.writeToFile(message)
if os.path.exists(status): if os.path.exists(status):
if os.path.exists('/usr/local/CyberCP/debug'):
message = 'If running found. and status file exists'
logging.CyberCPLogFileWriter.writeToFile(message)
status = open(status, 'r').read() status = open(status, 'r').read()
time.sleep(2) time.sleep(2)
@@ -115,6 +128,9 @@ class backupSchedule:
return 1, tempStoragePath return 1, tempStoragePath
elif status.find("[5009]") > -1: elif status.find("[5009]") > -1:
if os.path.exists('/usr/local/CyberCP/debug'):
message = 'If running found. status file exists but error'
logging.CyberCPLogFileWriter.writeToFile(message)
## removing status file, so that backup can re-run ## removing status file, so that backup can re-run
try: try:
command = 'sudo rm -f ' + status command = 'sudo rm -f ' + status
@@ -150,6 +166,9 @@ class backupSchedule:
return 0, tempStoragePath return 0, tempStoragePath
elif os.path.exists(schedulerPath): elif os.path.exists(schedulerPath):
if os.path.exists('/usr/local/CyberCP/debug'):
message = 'If running found. status file exists, scheduler path also exists hence killed'
logging.CyberCPLogFileWriter.writeToFile(message)
backupSchedule.remoteBackupLogging(backupLogPath, 'Backup process killed. Error: %s' % ( backupSchedule.remoteBackupLogging(backupLogPath, 'Backup process killed. Error: %s' % (
open(schedulerPath, 'r').read()), open(schedulerPath, 'r').read()),
backupSchedule.ERROR) backupSchedule.ERROR)
@@ -157,8 +176,15 @@ class backupSchedule:
command = 'rm -rf %s' % (tempStoragePath) command = 'rm -rf %s' % (tempStoragePath)
ProcessUtilities.normalExecutioner(command) ProcessUtilities.normalExecutioner(command)
return 0, 'Backup process killed.' return 0, 'Backup process killed.'
else: else:
if os.path.exists('/usr/local/CyberCP/debug'):
message = 'If running not found.'
logging.CyberCPLogFileWriter.writeToFile(message)
if os.path.exists(status): if os.path.exists(status):
if os.path.exists('/usr/local/CyberCP/debug'):
message = 'if running not found, Status file exists'
logging.CyberCPLogFileWriter.writeToFile(message)
status = open(status, 'r').read() status = open(status, 'r').read()
time.sleep(2) time.sleep(2)
@@ -182,6 +208,11 @@ class backupSchedule:
pass pass
return 1, tempStoragePath return 1, tempStoragePath
elif os.path.exists(schedulerPath): elif os.path.exists(schedulerPath):
if os.path.exists('/usr/local/CyberCP/debug'):
message = 'if running not found, Status file exists, scheduler path exists thus killed.'
logging.CyberCPLogFileWriter.writeToFile(message)
backupSchedule.remoteBackupLogging(backupLogPath, 'Backup process killed. Error: %s' % (open(schedulerPath, 'r').read()), backupSchedule.remoteBackupLogging(backupLogPath, 'Backup process killed. Error: %s' % (open(schedulerPath, 'r').read()),
backupSchedule.ERROR) backupSchedule.ERROR)
os.remove(schedulerPath) os.remove(schedulerPath)
@@ -189,13 +220,23 @@ class backupSchedule:
ProcessUtilities.normalExecutioner(command) ProcessUtilities.normalExecutioner(command)
return 0, 'Backup process killed.' return 0, 'Backup process killed.'
else: else:
if os.path.exists('/usr/local/CyberCP/debug'):
message = 'Status file does not exists.'
logging.CyberCPLogFileWriter.writeToFile(message)
if killCounter == 1: if killCounter == 1:
if os.path.exists('/usr/local/CyberCP/debug'):
message = 'if running not found, Status file does not exists, kill counter 1, thus killed'
logging.CyberCPLogFileWriter.writeToFile(message)
command = 'rm -rf %s' % (tempStoragePath) command = 'rm -rf %s' % (tempStoragePath)
ProcessUtilities.normalExecutioner(command) ProcessUtilities.normalExecutioner(command)
return 0, 'Backup process killed without reporting any error. [184]' return 0, 'Backup process killed without reporting any error. [184]'
elif os.path.exists(schedulerPath): elif os.path.exists(schedulerPath):
if os.path.exists('/usr/local/CyberCP/debug'):
message = 'if running not found, Status file does not exists, scheduler path found thus killed'
logging.CyberCPLogFileWriter.writeToFile(message)
backupSchedule.remoteBackupLogging(backupLogPath, 'Backup process killed. Error: %s' % ( backupSchedule.remoteBackupLogging(backupLogPath, 'Backup process killed. Error: %s' % (
open(schedulerPath, 'r').read()), open(schedulerPath, 'r').read()),
backupSchedule.ERROR) backupSchedule.ERROR)

View File

@@ -645,7 +645,7 @@ class backupUtilities:
dbName = database.find('dbName').text dbName = database.find('dbName').text
if VERSION == '2.1' and int(BUILD) >= 1: if (VERSION == '2.1' or VERSION == '2.3') and int(BUILD) >= 1:
logging.CyberCPLogFileWriter.writeToFile('Backup version 2.1.1+ detected..') logging.CyberCPLogFileWriter.writeToFile('Backup version 2.1.1+ detected..')
databaseUsers = database.findall('databaseUsers') databaseUsers = database.findall('databaseUsers')
@@ -912,7 +912,7 @@ class backupUtilities:
dbName = database.find('dbName').text dbName = database.find('dbName').text
if VERSION == '2.1' and int(BUILD) >= 1: if (VERSION == '2.1' or VERSION == '2.3') and int(BUILD) >= 1:
logging.CyberCPLogFileWriter.writeToFile('Backup version 2.1.1+ detected..') logging.CyberCPLogFileWriter.writeToFile('Backup version 2.1.1+ detected..')
@@ -963,6 +963,7 @@ class backupUtilities:
# /home/backup/backup-example.com-02.13.2018_10-24-52/public_html.tar.gz # /home/backup/backup-example.com-02.13.2018_10-24-52/public_html.tar.gz
## Moving above v2.0.0 extracting webhome data is not required, thus commenting below lines ## Moving above v2.0.0 extracting webhome data is not required, thus commenting below lines
if not twoPointO: if not twoPointO:
tar = tarfile.open(pathToCompressedHome) tar = tarfile.open(pathToCompressedHome)
tar.extractall(websiteHome) tar.extractall(websiteHome)

View File

@@ -225,7 +225,8 @@ class ProcessUtilities(multi.Thread):
command = 'sudo %s' % (command) command = 'sudo %s' % (command)
if os.path.exists(ProcessUtilities.debugPath): if os.path.exists(ProcessUtilities.debugPath):
logging.writeToFile(ProcessUtilities.token + command) if command.find('cat') == -1:
logging.writeToFile(ProcessUtilities.token + command)
if dir == None: if dir == None:
sock.sendall((ProcessUtilities.token + command).encode('utf-8')) sock.sendall((ProcessUtilities.token + command).encode('utf-8'))
@@ -238,8 +239,11 @@ class ProcessUtilities(multi.Thread):
else: else:
command = '%s-u %s -d %s %s' % (ProcessUtilities.token, user, dir, command) command = '%s-u %s -d %s %s' % (ProcessUtilities.token, user, dir, command)
command = command.replace('sudo', '') command = command.replace('sudo', '')
if os.path.exists(ProcessUtilities.debugPath): if os.path.exists(ProcessUtilities.debugPath):
logging.writeToFile(command) if command.find('cat') == -1:
logging.writeToFile(command)
sock.sendall(command.encode('utf-8')) sock.sendall(command.encode('utf-8'))