|
1 | | -#!/usr/local/CyberCP/bin/python2 |
2 | | -import os |
3 | | -import os.path |
| 1 | +import argparse |
4 | 2 | import sys |
5 | 3 | sys.path.append('/usr/local/CyberCP') |
6 | | -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings") |
7 | | - |
8 | | -import django |
9 | | -try: |
10 | | - django.setup() |
11 | | -except: |
12 | | - pass |
13 | | -from IncBackupsControl import IncJobs |
14 | | -from IncBackups.models import BackupJob |
15 | | -from random import randint |
16 | | -import argparse |
17 | | -try: |
18 | | - from plogical.virtualHostUtilities import virtualHostUtilities |
19 | | - from plogical.mailUtilities import mailUtilities |
20 | | - from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging |
21 | | -except: |
22 | | - pass |
23 | | - |
24 | | -class IncScheduler(): |
25 | | - logPath = '/home/cyberpanel/incbackuplogs' |
26 | | - |
27 | | - @staticmethod |
28 | | - def startBackup(type): |
29 | | - try: |
30 | | - logging.statusWriter(IncScheduler.logPath, 'Starting Incremental Backup job..', 1) |
31 | | - tempPath = "/home/cyberpanel/" + str(randint(1000, 9999)) |
32 | | - for job in BackupJob.objects.all(): |
33 | | - logging.statusWriter(IncScheduler.logPath, 'Job Description:\n\n Destination: %s, Frequency: %s.\n ' % (job.destination, job.frequency), 1) |
34 | | - if job.frequency == type: |
35 | | - for web in job.jobsites_set.all(): |
36 | | - logging.statusWriter(IncScheduler.logPath, 'Backing up %s.' % (web.website), 1) |
37 | | - extraArgs = {} |
38 | | - extraArgs['website'] = web.website |
39 | | - extraArgs['tempPath'] = tempPath |
40 | | - extraArgs['backupDestinations'] = job.destination |
41 | | - |
42 | | - if job.websiteData == 1: |
43 | | - extraArgs['websiteData'] = True |
44 | | - else: |
45 | | - extraArgs['websiteData'] = False |
46 | | - |
47 | | - if job.websiteDatabases == 1: |
48 | | - extraArgs['websiteDatabases'] = True |
49 | | - else: |
50 | | - extraArgs['websiteDatabases'] = False |
51 | | - |
52 | | - if job.websiteDataEmails == 1: |
53 | | - extraArgs['websiteEmails'] = True |
54 | | - else: |
55 | | - extraArgs['websiteEmails'] = False |
56 | | - |
57 | | - extraArgs['websiteSSLs'] = False |
58 | | - |
59 | | - startJob = IncJobs('createBackup', extraArgs) |
60 | | - startJob.start() |
61 | | - |
62 | | - ### Checking status |
63 | | - |
64 | | - while True: |
65 | | - if os.path.exists(tempPath): |
66 | | - result = open(tempPath, 'r').read() |
67 | | - |
68 | | - if result.find("Completed") > -1: |
69 | | - |
70 | | - ### Removing Files |
71 | | - |
72 | | - os.remove(tempPath) |
73 | | - |
74 | | - logging.statusWriter(IncScheduler.logPath, 'Backed up %s.' % (web.website), 1) |
75 | | - break |
76 | | - elif result.find("[5009]") > -1: |
77 | | - ## removing status file, so that backup can re-runn |
78 | | - try: |
79 | | - os.remove(tempPath) |
80 | | - except: |
81 | | - pass |
82 | | - |
83 | | - logging.statusWriter(IncScheduler.logPath, 'Failed backup for %s, error: %s.' % (web.website, result), 1) |
84 | | - break |
85 | | - except BaseException, msg: |
86 | | - logging.writeToFile(str(msg)) |
87 | | - |
| 4 | +from plogical.processUtilities import ProcessUtilities |
88 | 5 |
|
89 | 6 | def main(): |
90 | 7 |
|
91 | 8 | parser = argparse.ArgumentParser(description='CyberPanel Installer') |
92 | 9 | parser.add_argument('function', help='Specific a function to call!') |
93 | 10 | args = parser.parse_args() |
94 | 11 |
|
95 | | - IncScheduler.startBackup(args.function) |
| 12 | + command = '/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/IncScheduler.py %s' % (args.function) |
| 13 | + ProcessUtilities.normalExecutioner(command) |
96 | 14 |
|
97 | 15 |
|
98 | 16 | if __name__ == "__main__": |
|
0 commit comments