mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-08 22:36:12 +01:00
Fix the Remote Backup Storage Issue
This commit is contained in:
81
plogical/remoteTransferUtilities.py
Normal file → Executable file
81
plogical/remoteTransferUtilities.py
Normal file → Executable file
@@ -1,7 +1,6 @@
|
||||
import argparse
|
||||
import os
|
||||
import CyberCPLogFileWriter as logging
|
||||
import remoteBackup as rBackup
|
||||
import backupUtilities as backupUtil
|
||||
import time
|
||||
from multiprocessing import Process
|
||||
@@ -12,6 +11,8 @@ import shlex
|
||||
from shutil import move
|
||||
from plogical.virtualHostUtilities import virtualHostUtilities
|
||||
from plogical.processUtilities import ProcessUtilities
|
||||
from backupSchedule import backupSchedule
|
||||
import shutil
|
||||
|
||||
class remoteTransferUtilities:
|
||||
|
||||
@@ -129,7 +130,6 @@ class remoteTransferUtilities:
|
||||
## dir is without forward slash
|
||||
|
||||
for virtualHost in accountsToTransfer:
|
||||
|
||||
try:
|
||||
|
||||
writeToFile = open(backupLogPath, "a")
|
||||
@@ -137,64 +137,40 @@ class remoteTransferUtilities:
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + " Currently generating local backups for: " + virtualHost + "\n")
|
||||
writeToFile.close()
|
||||
|
||||
finalData = json.dumps({'websiteToBeBacked': virtualHost})
|
||||
r = requests.post("http://localhost:5003/backup/submitBackupCreation", data=finalData,
|
||||
verify=False)
|
||||
retValue = backupSchedule.createLocalBackup(virtualHost, backupLogPath)
|
||||
|
||||
data = json.loads(r.text)
|
||||
if retValue[0] == 1:
|
||||
writeToFile = open(backupLogPath, 'a')
|
||||
writeToFile.writelines("[" + time.strftime(
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + " Local Backup Completed for: " + virtualHost + "\n")
|
||||
|
||||
fileName = data['tempStorage'] + ".tar.gz"
|
||||
completePathToBackupFile = retValue[1] + '.tar.gz'
|
||||
|
||||
completePathToBackupFile = fileName
|
||||
## move the generated backup file to specified destination
|
||||
|
||||
while (1):
|
||||
time.sleep(2)
|
||||
r = requests.post("http://localhost:5003/backup/backupStatus", data=finalData, verify=False)
|
||||
data = json.loads(r.text)
|
||||
if os.path.exists(completePathToBackupFile):
|
||||
move(completePathToBackupFile, dir)
|
||||
|
||||
writeToFile = open(backupLogPath, "a")
|
||||
completedPathToSend = dir + "/" + completePathToBackupFile.split("/")[-1]
|
||||
|
||||
writeToFile.writelines("[" + time.strftime(
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + " Waiting for backup to complete.. " + "\n")
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + " Sending " + completedPathToSend + " to " + ipAddress + ".\n")
|
||||
|
||||
remoteTransferUtilities.sendBackup(completedPathToSend, ipAddress, str(folderNumber),
|
||||
writeToFile)
|
||||
writeToFile.writelines("[" + time.strftime(
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + " Sent " + completedPathToSend + " to " + ipAddress + ".\n")
|
||||
|
||||
writeToFile.writelines("[" + time.strftime(
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + " #############################################" + "\n")
|
||||
|
||||
writeToFile.close()
|
||||
else:
|
||||
writeToFile.writelines("[" + time.strftime(
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + "Failed to generate local backup for: " + virtualHost + "\n")
|
||||
|
||||
if data['backupStatus'] == 0:
|
||||
writeToFile.writelines("[" + time.strftime(
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + "Failed to generate local backup for: " + virtualHost + ". Error message: " +
|
||||
data['error_message'] + "\n")
|
||||
break
|
||||
|
||||
elif data['abort'] == 1:
|
||||
|
||||
writeToFile = open(backupLogPath, "a")
|
||||
|
||||
writeToFile.writelines("[" + time.strftime(
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + " Local Backup Completed for: " + virtualHost + " with status: " +
|
||||
data['status'] + "\n")
|
||||
|
||||
## move the generated backup file to specified destination
|
||||
|
||||
if os.path.exists(completePathToBackupFile):
|
||||
move(completePathToBackupFile, dir)
|
||||
|
||||
completedPathToSend = dir + "/" + completePathToBackupFile.split("/")[-1]
|
||||
|
||||
writeToFile.writelines("[" + time.strftime(
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + " Sending " + completedPathToSend + " to " + ipAddress + ".\n")
|
||||
|
||||
remoteTransferUtilities.sendBackup(completedPathToSend, ipAddress, str(folderNumber), writeToFile)
|
||||
|
||||
writeToFile.writelines("[" + time.strftime(
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + " Sent " + completedPathToSend + " to " + ipAddress + ".\n")
|
||||
|
||||
writeToFile.writelines("[" + time.strftime(
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + " #############################################" + "\n")
|
||||
|
||||
writeToFile.close()
|
||||
break
|
||||
except BaseException, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [remoteTransferUtilities.backupProcess:173]")
|
||||
pass
|
||||
|
||||
writeToFile = open(backupLogPath, "a")
|
||||
@@ -217,6 +193,8 @@ class remoteTransferUtilities:
|
||||
command = "sudo scp -o StrictHostKeyChecking=no -i /root/.ssh/cyberpanel " + completedPathToSend + " root@" + IPAddress + ":/home/backup/transfer-" + folderNumber + "/"
|
||||
subprocess.call(shlex.split(command), stdout=writeToFile)
|
||||
|
||||
os.remove(completedPathToSend)
|
||||
|
||||
except BaseException, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startBackup]")
|
||||
|
||||
@@ -343,6 +321,11 @@ class remoteTransferUtilities:
|
||||
"%I-%M-%S-%a-%b-%Y") + "]" + " Backup Restore complete\n")
|
||||
writeToFile.writelines("completed[success]")
|
||||
|
||||
try:
|
||||
shutil.rmtree("/home/backup/transfer-" + dir)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
except BaseException, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [remoteTransferUtilities.startRestore]")
|
||||
|
||||
Reference in New Issue
Block a user