mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-06 21:35:55 +01:00
96 lines
3.6 KiB
Python
96 lines
3.6 KiB
Python
|
|
#!/usr/local/CyberCP/bin/python2
|
||
|
|
import os.path
|
||
|
|
import sys
|
||
|
|
sys.path.append('/usr/local/CyberCP')
|
||
|
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
|
||
|
|
import django
|
||
|
|
django.setup()
|
||
|
|
from IncBackups.IncBackupsControl import IncJobs
|
||
|
|
from IncBackups.models import BackupJob
|
||
|
|
from random import randint
|
||
|
|
import argparse
|
||
|
|
try:
|
||
|
|
from plogical.virtualHostUtilities import virtualHostUtilities
|
||
|
|
from plogical.mailUtilities import mailUtilities
|
||
|
|
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging
|
||
|
|
except:
|
||
|
|
pass
|
||
|
|
|
||
|
|
class IncScheduler():
|
||
|
|
logPath = '/home/cyberpanel/incbackuplogs'
|
||
|
|
|
||
|
|
@staticmethod
|
||
|
|
def startBackup(type):
|
||
|
|
try:
|
||
|
|
logging.statusWriter(IncScheduler.logPath, 'Starting Incremental Backup job..', 1)
|
||
|
|
tempPath = "/home/cyberpanel/" + str(randint(1000, 9999))
|
||
|
|
for job in BackupJob.objects.all():
|
||
|
|
logging.statusWriter(IncScheduler.logPath, 'Job Description:\n\n Destination: %s, Frequency: %s.\n ' % (job.destination, job.frequency), 1)
|
||
|
|
if job.frequency == type:
|
||
|
|
for web in job.jobsites_set.all():
|
||
|
|
logging.statusWriter(IncScheduler.logPath, 'Backing up %s.' % (web.website), 1)
|
||
|
|
|
||
|
|
extraArgs = {}
|
||
|
|
extraArgs['website'] = web.website
|
||
|
|
extraArgs['tempPath'] = tempPath
|
||
|
|
extraArgs['backupDestinations'] = job.destination
|
||
|
|
|
||
|
|
if job.websiteData == 1:
|
||
|
|
extraArgs['websiteData'] = True
|
||
|
|
else:
|
||
|
|
extraArgs['websiteData'] = False
|
||
|
|
|
||
|
|
if job.websiteDatabases == 1:
|
||
|
|
extraArgs['websiteDatabases'] = True
|
||
|
|
else:
|
||
|
|
extraArgs['websiteDatabases'] = False
|
||
|
|
|
||
|
|
if job.websiteDataEmails == 1:
|
||
|
|
extraArgs['websiteEmails'] = True
|
||
|
|
else:
|
||
|
|
extraArgs['websiteEmails'] = False
|
||
|
|
|
||
|
|
extraArgs['websiteSSLs'] = False
|
||
|
|
|
||
|
|
startJob = IncJobs('createBackup', extraArgs)
|
||
|
|
startJob.start()
|
||
|
|
|
||
|
|
### Checking status
|
||
|
|
|
||
|
|
while True:
|
||
|
|
if os.path.exists(tempPath):
|
||
|
|
result = open(tempPath, 'r').read()
|
||
|
|
|
||
|
|
if result.find("Completed") > -1:
|
||
|
|
|
||
|
|
### Removing Files
|
||
|
|
|
||
|
|
os.remove(tempPath)
|
||
|
|
|
||
|
|
logging.statusWriter(IncScheduler.logPath, 'Backed up %s.' % (web.website), 1)
|
||
|
|
break
|
||
|
|
elif result.find("[5009]") > -1:
|
||
|
|
## removing status file, so that backup can re-runn
|
||
|
|
try:
|
||
|
|
os.remove(tempPath)
|
||
|
|
except:
|
||
|
|
pass
|
||
|
|
|
||
|
|
logging.statusWriter(IncScheduler.logPath, 'Failed backup for %s, error: %s.' % (web.website, result), 1)
|
||
|
|
break
|
||
|
|
|
||
|
|
except BaseException, msg:
|
||
|
|
logging.writeToFile(str(msg))
|
||
|
|
|
||
|
|
|
||
|
|
def main():
|
||
|
|
|
||
|
|
parser = argparse.ArgumentParser(description='CyberPanel Installer')
|
||
|
|
parser.add_argument('function', help='Specific a function to call!')
|
||
|
|
args = parser.parse_args()
|
||
|
|
|
||
|
|
IncScheduler.startBackup(args.function)
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|