mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-07 22:06:05 +01:00
s3backupuplaoddone
This commit is contained in:
@@ -991,8 +991,8 @@ Automatic backup failed for %s on %s.
|
|||||||
Currenttime = float(time.time())
|
Currenttime = float(time.time())
|
||||||
if config.timeintervel == "30 Minutes":
|
if config.timeintervel == "30 Minutes":
|
||||||
al = float(Currenttime) - float(1800)
|
al = float(Currenttime) - float(1800)
|
||||||
# if float(al) >= float(Lastrun):
|
if float(al) >= float(Lastrun):
|
||||||
if 1 == 1:
|
#if 1 == 1:
|
||||||
extraArgs = {}
|
extraArgs = {}
|
||||||
extraArgs['adminID'] = Admin.pk
|
extraArgs['adminID'] = Admin.pk
|
||||||
extraArgs['WPid'] = wpsite.pk
|
extraArgs['WPid'] = wpsite.pk
|
||||||
@@ -1013,7 +1013,7 @@ Automatic backup failed for %s on %s.
|
|||||||
obj.lastrun = time.time()
|
obj.lastrun = time.time()
|
||||||
obj.save()
|
obj.save()
|
||||||
elif config.RemoteBackupConfig.configtype == "S3":
|
elif config.RemoteBackupConfig.configtype == "S3":
|
||||||
IncScheduler.SendToS3Cloud(filename, config.RemoteBackupConfig_id, backupID)
|
IncScheduler.SendToS3Cloud(filename, config.RemoteBackupConfig_id, backupID, config.id)
|
||||||
command = f"rm -r {filename}"
|
command = f"rm -r {filename}"
|
||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
||||||
@@ -1043,7 +1043,8 @@ Automatic backup failed for %s on %s.
|
|||||||
obj.lastrun = time.time()
|
obj.lastrun = time.time()
|
||||||
obj.save()
|
obj.save()
|
||||||
elif config.RemoteBackupConfig.configtype == "S3":
|
elif config.RemoteBackupConfig.configtype == "S3":
|
||||||
IncScheduler.SendToS3Cloud(filename, config.RemoteBackupConfig_id, backupID)
|
IncScheduler.SendToS3Cloud(filename, config.RemoteBackupConfig_id, backupID,
|
||||||
|
config.id)
|
||||||
command = f"rm -r {filename}"
|
command = f"rm -r {filename}"
|
||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
||||||
@@ -1072,7 +1073,8 @@ Automatic backup failed for %s on %s.
|
|||||||
obj.lastrun = time.time()
|
obj.lastrun = time.time()
|
||||||
obj.save()
|
obj.save()
|
||||||
elif config.RemoteBackupConfig.configtype == "S3":
|
elif config.RemoteBackupConfig.configtype == "S3":
|
||||||
IncScheduler.SendToS3Cloud(filename, config.RemoteBackupConfig_id, backupID)
|
IncScheduler.SendToS3Cloud(filename, config.RemoteBackupConfig_id, backupID,
|
||||||
|
config.id)
|
||||||
command = f"rm -r {filename}"
|
command = f"rm -r {filename}"
|
||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
||||||
@@ -1101,7 +1103,8 @@ Automatic backup failed for %s on %s.
|
|||||||
obj.lastrun = time.time()
|
obj.lastrun = time.time()
|
||||||
obj.save()
|
obj.save()
|
||||||
elif config.RemoteBackupConfig.configtype == "S3":
|
elif config.RemoteBackupConfig.configtype == "S3":
|
||||||
IncScheduler.SendToS3Cloud(filename, config.RemoteBackupConfig_id, backupID)
|
IncScheduler.SendToS3Cloud(filename, config.RemoteBackupConfig_id, backupID,
|
||||||
|
config.id)
|
||||||
command = f"rm -r {filename}"
|
command = f"rm -r {filename}"
|
||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
||||||
@@ -1130,7 +1133,8 @@ Automatic backup failed for %s on %s.
|
|||||||
obj.lastrun = time.time()
|
obj.lastrun = time.time()
|
||||||
obj.save()
|
obj.save()
|
||||||
elif config.RemoteBackupConfig.configtype == "S3":
|
elif config.RemoteBackupConfig.configtype == "S3":
|
||||||
IncScheduler.SendToS3Cloud(filename, config.RemoteBackupConfig_id, backupID)
|
IncScheduler.SendToS3Cloud(filename, config.RemoteBackupConfig_id, backupID,
|
||||||
|
config.id)
|
||||||
command = f"rm -r {filename}"
|
command = f"rm -r {filename}"
|
||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
||||||
@@ -1159,7 +1163,8 @@ Automatic backup failed for %s on %s.
|
|||||||
obj.lastrun = time.time()
|
obj.lastrun = time.time()
|
||||||
obj.save()
|
obj.save()
|
||||||
elif config.RemoteBackupConfig.configtype == "S3":
|
elif config.RemoteBackupConfig.configtype == "S3":
|
||||||
IncScheduler.SendToS3Cloud(filename, config.RemoteBackupConfig_id, backupID)
|
IncScheduler.SendToS3Cloud(filename, config.RemoteBackupConfig_id, backupID,
|
||||||
|
config.id)
|
||||||
command = f"rm -r {filename}"
|
command = f"rm -r {filename}"
|
||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
||||||
@@ -1188,7 +1193,8 @@ Automatic backup failed for %s on %s.
|
|||||||
obj.lastrun = time.time()
|
obj.lastrun = time.time()
|
||||||
obj.save()
|
obj.save()
|
||||||
elif config.RemoteBackupConfig.configtype == "S3":
|
elif config.RemoteBackupConfig.configtype == "S3":
|
||||||
IncScheduler.SendToS3Cloud(filename, config.RemoteBackupConfig_id, backupID)
|
IncScheduler.SendToS3Cloud(filename, config.RemoteBackupConfig_id, backupID,
|
||||||
|
config.id)
|
||||||
command = f"rm -r {filename}"
|
command = f"rm -r {filename}"
|
||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
obj = RemoteBackupSchedule.objects.get(pk=config.id)
|
||||||
@@ -1236,11 +1242,11 @@ Automatic backup failed for %s on %s.
|
|||||||
logging.writeToFile('%s. [SendTORemote]' % (str(msg)))
|
logging.writeToFile('%s. [SendTORemote]' % (str(msg)))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def SendToS3Cloud(FileName, RemoteBackupCofigID, backupID):
|
def SendToS3Cloud(FileName, RemoteBackupCofigID, backupID, scheduleID):
|
||||||
import boto3
|
import boto3
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
from websiteFunctions.models import RemoteBackupConfig, WPSitesBackup
|
from websiteFunctions.models import RemoteBackupConfig, WPSitesBackup, RemoteBackupSchedule
|
||||||
import plogical.randomPassword as randomPassword
|
import plogical.randomPassword as randomPassword
|
||||||
try:
|
try:
|
||||||
print("UPloading to S3")
|
print("UPloading to S3")
|
||||||
@@ -1270,16 +1276,21 @@ Automatic backup failed for %s on %s.
|
|||||||
verify=False
|
verify=False
|
||||||
)
|
)
|
||||||
|
|
||||||
############Creating Bucket
|
# ############Creating Bucket
|
||||||
BucketName = randomPassword.generate_pass().lower()
|
# BucketName = randomPassword.generate_pass().lower()
|
||||||
print("BucketName...%s"%BucketName)
|
# print("BucketName...%s"%BucketName)
|
||||||
|
#
|
||||||
|
# try:
|
||||||
|
# client.create_bucket(Bucket=BucketName)
|
||||||
|
# except BaseException as msg:
|
||||||
|
# print("Error in Creating bucket...: %s" % str(msg))
|
||||||
|
# logging.writeToFile("Create bucket error---%s:" % str(msg))
|
||||||
|
|
||||||
try:
|
|
||||||
client.create_bucket(Bucket=BucketName)
|
|
||||||
except BaseException as msg:
|
|
||||||
print("Error in Creating bucket...: %s" % str(msg))
|
|
||||||
logging.writeToFile("Create bucket error---%s:" % str(msg))
|
|
||||||
|
|
||||||
|
####getting Bucket from backup schedule
|
||||||
|
Scheduleobj = RemoteBackupSchedule.objects.get(pk=scheduleID)
|
||||||
|
Scheduleconfig = json.loads(Scheduleobj.config)
|
||||||
|
BucketName = Scheduleconfig['BucketName']
|
||||||
#####Uploading File
|
#####Uploading File
|
||||||
|
|
||||||
uploadfilename = 'backup-' + websitedomain + "-" + time.strftime("%m.%d.%Y_%H-%M-%S")
|
uploadfilename = 'backup-' + websitedomain + "-" + time.strftime("%m.%d.%Y_%H-%M-%S")
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ from plogical.mailUtilities import mailUtilities
|
|||||||
from random import randint
|
from random import randint
|
||||||
import time
|
import time
|
||||||
import re
|
import re
|
||||||
|
import boto3
|
||||||
from plogical.childDomain import ChildDomainManager
|
from plogical.childDomain import ChildDomainManager
|
||||||
from math import ceil
|
from math import ceil
|
||||||
from plogical.alias import AliasManager
|
from plogical.alias import AliasManager
|
||||||
@@ -1226,11 +1227,46 @@ class WebsiteManager:
|
|||||||
ScheduleName = data['ScheduleName']
|
ScheduleName = data['ScheduleName']
|
||||||
RemoteConfigID = data['RemoteConfigID']
|
RemoteConfigID = data['RemoteConfigID']
|
||||||
BackupType = data['BackupType']
|
BackupType = data['BackupType']
|
||||||
config = {
|
|
||||||
'BackupType': BackupType
|
|
||||||
}
|
|
||||||
|
|
||||||
RemoteBackupConfigobj = RemoteBackupConfig.objects.get(pk=RemoteConfigID)
|
RemoteBackupConfigobj = RemoteBackupConfig.objects.get(pk=RemoteConfigID)
|
||||||
|
Rconfig = json.loads(RemoteBackupConfigobj.config)
|
||||||
|
provider = Rconfig['Provider']
|
||||||
|
if provider == "Backblaze":
|
||||||
|
EndURl = Rconfig['EndUrl']
|
||||||
|
elif provider == "Amazon":
|
||||||
|
EndURl = "https://s3.us-east-1.amazonaws.com"
|
||||||
|
elif provider == "Wasabi":
|
||||||
|
EndURl = "https://s3.wasabisys.com"
|
||||||
|
|
||||||
|
AccessKey = Rconfig['AccessKey']
|
||||||
|
SecertKey = Rconfig['SecertKey']
|
||||||
|
|
||||||
|
session = boto3.session.Session()
|
||||||
|
|
||||||
|
client = session.client(
|
||||||
|
's3',
|
||||||
|
endpoint_url=EndURl,
|
||||||
|
aws_access_key_id=AccessKey,
|
||||||
|
aws_secret_access_key=SecertKey,
|
||||||
|
verify=False
|
||||||
|
)
|
||||||
|
|
||||||
|
############Creating Bucket
|
||||||
|
BucketName = randomPassword.generate_pass().lower()
|
||||||
|
|
||||||
|
try:
|
||||||
|
client.create_bucket(Bucket=BucketName)
|
||||||
|
except BaseException as msg:
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile("Creating Bucket Error: %s"%str(msg))
|
||||||
|
data_ret = {'status': 0, 'error_message': str(msg)}
|
||||||
|
json_data = json.dumps(data_ret)
|
||||||
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
|
config = {
|
||||||
|
'BackupType': BackupType,
|
||||||
|
'BucketName': BucketName
|
||||||
|
}
|
||||||
|
|
||||||
svobj = RemoteBackupSchedule( RemoteBackupConfig=RemoteBackupConfigobj, Name=ScheduleName,
|
svobj = RemoteBackupSchedule( RemoteBackupConfig=RemoteBackupConfigobj, Name=ScheduleName,
|
||||||
timeintervel=Backfrequency, fileretention=FileRetention, config=json.dumps(config),
|
timeintervel=Backfrequency, fileretention=FileRetention, config=json.dumps(config),
|
||||||
|
|||||||
Reference in New Issue
Block a user