Skip to content

Commit fde41d4

Browse files
committed
bug fix: inc backups
1 parent db444c7 commit fde41d4

File tree

5 files changed

+129
-92
lines changed

5 files changed

+129
-92
lines changed

IncBackups/IncBackupsControl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ def createBackup(self):
718718
if not os.path.exists(self.passwordFile):
719719
password = randomPassword.generate_pass()
720720
command = 'echo "%s" > %s' % (password, self.passwordFile)
721-
ProcessUtilities.executioner(command, self.website.externalApp)
721+
ProcessUtilities.executioner(command, self.website.externalApp, True)
722722

723723
command = 'chmod 600 %s' % (self.passwordFile)
724724
ProcessUtilities.executioner(command)

IncBackups/IncScheduler.py

Lines changed: 4 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,16 @@
1-
#!/usr/local/CyberCP/bin/python2
2-
import os
3-
import os.path
1+
import argparse
42
import sys
53
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
885

896
def main():
907

918
parser = argparse.ArgumentParser(description='CyberPanel Installer')
929
parser.add_argument('function', help='Specific a function to call!')
9310
args = parser.parse_args()
9411

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)
9614

9715

9816
if __name__ == "__main__":

IncBackups/templates/IncBackups/backupSchedule.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,25 @@ <h3 class="title-hero">
135135
</tr>
136136
</tbody>
137137
</table>
138+
<div class="row">
139+
140+
<div class="col-sm-4 col-sm-offset-8">
141+
142+
<nav aria-label="Page navigation">
143+
<ul class="pagination">
144+
145+
<li ng-repeat="page in pagination"
146+
ng-click="getFurtherWebsitesFromDB($index+1)" id="webPages"><a
147+
href="">{$ $index + 1 $}</a></li>
148+
149+
</ul>
150+
</nav>
151+
152+
153+
</div>
154+
155+
156+
</div>
138157
</div>
139158
</div>
140159

plogical/IncScheduler.py

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

plogical/processUtilities.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,13 @@ def stopLitespeed():
8787
logging.writeToFile(str(msg) + "[stopLitespeed]")
8888

8989
@staticmethod
90-
def normalExecutioner(command):
90+
def normalExecutioner(command, shell=False):
9191
try:
92-
res = subprocess.call(shlex.split(command))
92+
if shell == False:
93+
res = subprocess.call(shlex.split(command))
94+
else:
95+
res = subprocess.call(command, shell=shell)
96+
9397
if res == 0:
9498
return 1
9599
else:
@@ -217,10 +221,10 @@ def sendCommand(command, user=None):
217221
return "0" + str(msg)
218222

219223
@staticmethod
220-
def executioner(command, user=None):
224+
def executioner(command, user=None, shell=False):
221225
try:
222226
if getpass.getuser() == 'root':
223-
ProcessUtilities.normalExecutioner(command)
227+
ProcessUtilities.normalExecutioner(command, shell)
224228
return 1
225229

226230
ret = ProcessUtilities.sendCommand(command, user)
@@ -241,7 +245,7 @@ def executioner(command, user=None):
241245
def outputExecutioner(command, user=None):
242246
try:
243247
if getpass.getuser() == 'root':
244-
return subprocess.check_output(shlex.split(command))
248+
return subprocess.check_output(command, shell=True)
245249

246250
if type(command) == str or type(command) == unicode:
247251
pass

0 commit comments

Comments
 (0)