mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-12-16 21:39:42 +01:00
Fix backup restore permission error and improve SFTP fallback
- Ensure /home/cyberpanel directory exists with proper permissions before download - Set directory permissions to 755 to allow application write access - Refactor SCP/SFTP fallback logic to work regardless of debug mode - Add better status messages during download process
This commit is contained in:
@@ -6706,6 +6706,15 @@ class ApplicationInstaller(multi.Thread):
|
|||||||
|
|
||||||
####
|
####
|
||||||
|
|
||||||
|
# Ensure /home/cyberpanel directory exists with proper permissions
|
||||||
|
if not os.path.exists('/home/cyberpanel'):
|
||||||
|
command = 'mkdir -p /home/cyberpanel'
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
# Set proper permissions to allow application to write to the directory
|
||||||
|
command = 'chmod 755 /home/cyberpanel'
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
sftp = ssh.open_sftp()
|
sftp = ssh.open_sftp()
|
||||||
|
|
||||||
logging.statusWriter(self.tempStatusPath, 'Downloading Backups...,15')
|
logging.statusWriter(self.tempStatusPath, 'Downloading Backups...,15')
|
||||||
@@ -6724,26 +6733,33 @@ class ApplicationInstaller(multi.Thread):
|
|||||||
successRet = stdout.read().decode().strip()
|
successRet = stdout.read().decode().strip()
|
||||||
errorRet = stderr.read().decode().strip()
|
errorRet = stderr.read().decode().strip()
|
||||||
|
|
||||||
if os.path.exists(ProcessUtilities.debugPath):
|
# Check if SCP had errors and fallback to SFTP if needed
|
||||||
logging.writeToFile(f"Command used to retrieve backup {command}")
|
if errorRet:
|
||||||
if errorRet:
|
if os.path.exists(ProcessUtilities.debugPath):
|
||||||
logging.writeToFile(f"Error in scp command to retrieve backup {errorRet}")
|
logging.writeToFile(f"Error in scp command to retrieve backup {errorRet}")
|
||||||
|
logging.writeToFile(f"Command used to retrieve backup {command}")
|
||||||
|
|
||||||
|
statusFile = open(tempStatusPath, 'w')
|
||||||
|
statusFile.writelines(f"SCP failed, falling back to SFTP...,20")
|
||||||
|
statusFile.close()
|
||||||
|
|
||||||
|
try:
|
||||||
|
sftp.get(f'cpbackups/{folder}/{backupfile}', f'/home/cyberpanel/{backupfile}',
|
||||||
|
callback=self.UpdateDownloadStatus)
|
||||||
|
|
||||||
|
if os.path.exists(ProcessUtilities.debugPath):
|
||||||
|
logging.writeToFile(f"Successfully downloaded via SFTP")
|
||||||
|
|
||||||
|
except BaseException as msg:
|
||||||
|
logging.writeToFile(f"Failed to download file {str(msg)} [404]")
|
||||||
statusFile = open(tempStatusPath, 'w')
|
statusFile = open(tempStatusPath, 'w')
|
||||||
statusFile.writelines(f"Error in scp command to retrieve backup {errorRet}.")
|
statusFile.writelines(f"Failed to download file {str(msg)} [404]")
|
||||||
statusFile.close()
|
statusFile.close()
|
||||||
|
return 0
|
||||||
try:
|
else:
|
||||||
sftp.get(f'cpbackups/{folder}/{backupfile}', f'/home/cyberpanel/{backupfile}',
|
if os.path.exists(ProcessUtilities.debugPath):
|
||||||
callback=self.UpdateDownloadStatus)
|
|
||||||
except BaseException as msg:
|
|
||||||
logging.writeToFile(f"Failed to download file {str(msg)} [404]")
|
|
||||||
statusFile = open(tempStatusPath, 'w')
|
|
||||||
statusFile.writelines(f"Failed to download file {str(msg)} [404]")
|
|
||||||
statusFile.close()
|
|
||||||
return 0
|
|
||||||
|
|
||||||
else:
|
|
||||||
logging.writeToFile(f"Success in scp command to retrieve backup {successRet}")
|
logging.writeToFile(f"Success in scp command to retrieve backup {successRet}")
|
||||||
|
logging.writeToFile(f"Command used to retrieve backup {command}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user