added schedule backend to v2backups

This commit is contained in:
usman@cyberpersons.com
2023-04-05 23:03:49 +05:00
parent 193b82eed7
commit e803e3b9d2
4 changed files with 100 additions and 3 deletions

View File

@@ -10,11 +10,17 @@
{% if PremStat %}
<div class="container">
<div id="page-title">
<h2>{% trans "SSL v2" %} - <a target="_blank" href="http://go.cyberpanel.net/dns-records"
<h2>{% trans "SSL v2" %} - <a target="_blank" href="https://youtu.be/kDUANNvtOwE"
style="height: 23px;line-height: 21px;"
class="btn btn-border btn-alt border-red btn-link font-red"
title=""><span>{% trans "DNS Docs" %}</span></a></h2>
<p>{% trans "On this page, you have the option to configure DNS providers that CyberPanel can utilize for issuing SSL certificates, providing enhanced flexibility and ease of renewal." %}</p>
<p align="center" style="margin-top: 2%; margin-bottom: 2%">
<iframe width="788.54" height="443" src="https://youtu.be/kDUANNvtOwE"
title="YouTube video player" frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen></iframe>
</p>
</div>
<div ng-controller="sslIssueCtrlV2" class="panel">
<div class="panel-body">
@@ -166,7 +172,7 @@
protected. Don't wait any longer to upgrade your website's security - get SSL v2 today!<br></p>
</div>
<p align="center">
<iframe width="788.54" height="443" src="https://www.youtube.com/embed/c-ffIKgjrBU"
<iframe width="788.54" height="443" src="https://youtu.be/kDUANNvtOwE"
title="YouTube video player" frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen></iframe>

View File

@@ -420,6 +420,7 @@ token = {token}
return 0
self.UpdateStatus('Backup config created,5', CPBackupsV2.RUNNING)
except BaseException as msg:
self.UpdateStatus(f'Failed during config generation, Error: {str(msg)}', CPBackupsV2.FAILED)
return 0
@@ -453,6 +454,7 @@ token = {token}
self.MergeSnapshots()
self.UpdateStatus('Completed', CPBackupsV2.COMPLETED)
return 1
break
except BaseException as msg:
@@ -725,6 +727,19 @@ token = {token}
self.website.BackupLock = 0
self.website.save()
### Delete Snapshots
def DeleteSnapshots(self, deleteString):
### if restore then status file should be restore status file
from websiteFunctions.models import Websites
self.website = Websites.objects.get(domain=self.data['domain'])
command = f'rustic -r {self.repo} forget {deleteString} --prune --password "" 2>/dev/null'
result = ProcessUtilities.outputExecutioner(command, None, True)
# def BackupEmails(self):
#
# ### This function will backup emails of the website, also need to take care of emails that we need to exclude

View File

@@ -1393,6 +1393,77 @@ Automatic backup failed for %s on %s.
for website in Websites.objects.all():
virtualHostUtilities.setupAutoDiscover(1, '/home/cyberpanel/templogs', website.domain, website.admin)
@staticmethod
def v2Backups(function):
try:
# print("....start remote backup...............")
from websiteFunctions.models import Websites
from loginSystem.models import Administrator
import json
import time
if os.path.exists('/home/cyberpanel/v2backups'):
for website in Websites.objects.all():
finalConfigPath = f'/home/cyberpanel/v2backups/{website.domain}'
if os.path.exists(finalConfigPath):
command = f'cat {finalConfigPath}'
RetResult = ProcessUtilities.outputExecutioner(command)
print(repr(RetResult))
BackupConfig = json.loads(ProcessUtilities.outputExecutioner(command).rstrip('\n'))
for key, value in BackupConfig.items():
try:
print(key, '->', value)
if key == 'site':
continue
if value['frequency'] == function:
extra_args = {}
extra_args['function'] = 'InitiateBackup'
extra_args['website'] = website.domain
extra_args['domain'] = website.domain
extra_args['BasePath'] = '/home/backup'
extra_args['BackendName'] = key
extra_args['BackupData'] = value['websiteData'] if 'websiteData' in value else False
extra_args['BackupEmails'] = value['websiteEmails'] if 'websiteEmails' in value else False
extra_args['BackupDatabase'] = value['websiteDatabases'] if 'websiteDatabases' in value else False
from plogical.Backupsv2 import CPBackupsV2
background = CPBackupsV2(extra_args)
RetStatus = background.InitiateBackup()
print(RetStatus)
if RetStatus == 0:
SUBJECT = "Automatic Backupv2 failed for %s on %s." % (website.domain, time.strftime("%m.%d.%Y_%H-%M-%S"))
adminEmailPath = '/home/cyberpanel/adminEmail'
adminEmail = open(adminEmailPath, 'r').read().rstrip('\n')
sender = 'root@%s' % (socket.gethostname())
error = ProcessUtilities.outputExecutioner(f'cat {background.StatusFile}')
TO = [adminEmail]
message = f"""\
From: %s
To: %s
Subject: %s
Automatic Backupv2 failed for %s on %s.
{error}
""" % (sender, ", ".join(TO), SUBJECT, website.domain, time.strftime("%m.%d.%Y_%H-%M-%S"))
logging.SendEmail(sender, TO, message)
else:
BackupConfig[key]['lastRun'] = time.strftime("%m.%d.%Y_%H-%M-%S")
except BaseException as msg:
print("Error: [v2Backups]: %s" % str(msg))
logging.writeToFile('%s. [v2Backups]' % (str(msg)))
FinalContent = json.dumps(BackupConfig)
WriteToFile = open(finalConfigPath, 'w')
WriteToFile.write(FinalContent)
WriteToFile.close()
except BaseException as msg:
print("Error: [v2Backups]: %s" % str(msg))
logging.writeToFile('%s. [v2Backups]' % (str(msg)))
def main():
parser = argparse.ArgumentParser(description='CyberPanel Installer')
@@ -1404,8 +1475,9 @@ def main():
IncScheduler.CalculateAndUpdateDiskUsage()
return 0
if args.function == '30 Minutes' or args.function == '30 Minutes'or args.function == 'Daily' or args.function == '1 Hour' or args.function == '6 Hours' or args.function == '12 Hours' or args.function == '1 Day' or args.function == '3 Days' or args.function == '1 Week':
if args.function == '30 Minutes' or args.function == 'Daily' or args.function == '1 Hour' or args.function == '6 Hours' or args.function == '12 Hours' or args.function == '1 Day' or args.function == '3 Days' or args.function == '1 Week':
IncScheduler.RemoteBackup(args.function)
IncScheduler.v2Backups(args.function)
return 0
if args.function == 'forceRunAWSBackup':

View File

@@ -294,6 +294,10 @@ class ProcessUtilities(multi.Thread):
if getpass.getuser() == 'root':
if os.path.exists(ProcessUtilities.debugPath):
logging.writeToFile(command)
if user!=None:
if not command.startswith('sudo'):
command = f'sudo -u {user} {command}'
if shell == None or shell == True:
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
else: