diff --git a/IncBackups/IncBackupsControl.py b/IncBackups/IncBackupsControl.py index f804b1c1b..39a3654f1 100644 --- a/IncBackups/IncBackupsControl.py +++ b/IncBackups/IncBackupsControl.py @@ -718,7 +718,7 @@ class IncJobs(multi.Thread): if not os.path.exists(self.passwordFile): password = randomPassword.generate_pass() command = 'echo "%s" > %s' % (password, self.passwordFile) - ProcessUtilities.executioner(command, self.website.externalApp) + ProcessUtilities.executioner(command, self.website.externalApp, True) command = 'chmod 600 %s' % (self.passwordFile) ProcessUtilities.executioner(command) diff --git a/IncBackups/IncScheduler.py b/IncBackups/IncScheduler.py index 9319c82d0..4d948ca55 100644 --- a/IncBackups/IncScheduler.py +++ b/IncBackups/IncScheduler.py @@ -1,90 +1,7 @@ -#!/usr/local/CyberCP/bin/python2 -import os -import os.path +import argparse import sys sys.path.append('/usr/local/CyberCP') -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings") - -import django -try: - django.setup() -except: - pass -from 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)) - +from plogical.processUtilities import ProcessUtilities def main(): @@ -92,7 +9,8 @@ def main(): parser.add_argument('function', help='Specific a function to call!') args = parser.parse_args() - IncScheduler.startBackup(args.function) + command = '/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/IncScheduler.py %s' % (args.function) + ProcessUtilities.normalExecutioner(command) if __name__ == "__main__": diff --git a/IncBackups/templates/IncBackups/backupSchedule.html b/IncBackups/templates/IncBackups/backupSchedule.html index 1925bc2a7..625b8603e 100755 --- a/IncBackups/templates/IncBackups/backupSchedule.html +++ b/IncBackups/templates/IncBackups/backupSchedule.html @@ -135,6 +135,25 @@ +
+ +
+ + + + +
+ + +
diff --git a/plogical/IncScheduler.py b/plogical/IncScheduler.py new file mode 100644 index 000000000..6e874bf7c --- /dev/null +++ b/plogical/IncScheduler.py @@ -0,0 +1,96 @@ +#!/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() \ No newline at end of file diff --git a/plogical/processUtilities.py b/plogical/processUtilities.py index c3061bb6a..568a84c49 100755 --- a/plogical/processUtilities.py +++ b/plogical/processUtilities.py @@ -87,9 +87,13 @@ class ProcessUtilities(multi.Thread): logging.writeToFile(str(msg) + "[stopLitespeed]") @staticmethod - def normalExecutioner(command): + def normalExecutioner(command, shell=False): try: - res = subprocess.call(shlex.split(command)) + if shell == False: + res = subprocess.call(shlex.split(command)) + else: + res = subprocess.call(command, shell=shell) + if res == 0: return 1 else: @@ -217,10 +221,10 @@ class ProcessUtilities(multi.Thread): return "0" + str(msg) @staticmethod - def executioner(command, user=None): + def executioner(command, user=None, shell=False): try: if getpass.getuser() == 'root': - ProcessUtilities.normalExecutioner(command) + ProcessUtilities.normalExecutioner(command, shell) return 1 ret = ProcessUtilities.sendCommand(command, user) @@ -241,7 +245,7 @@ class ProcessUtilities(multi.Thread): def outputExecutioner(command, user=None): try: if getpass.getuser() == 'root': - return subprocess.check_output(shlex.split(command)) + return subprocess.check_output(command, shell=True) if type(command) == str or type(command) == unicode: pass