Skip to content

Commit df4cea0

Browse files
committed
prevent local backup from running multiple processes
1 parent 5d2255e commit df4cea0

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

plogical/backupSchedule.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,13 @@ def prepare():
228228

229229
backupLogPath = "/usr/local/lscp/logs/backup_log."+time.strftime("%m.%d.%Y_%H-%M-%S")
230230

231+
jobSuccessSites = 0
232+
jobFailedSites = 0
233+
234+
backupSchedule.backupLog = BackupJob(logFile=backupLogPath, location=backupSchedule.REMOTE,
235+
jobSuccessSites=jobSuccessSites, jobFailedSites=jobFailedSites)
236+
backupSchedule.backupLog.save()
237+
231238
backupSchedule.remoteBackupLogging(backupLogPath,"#################################################")
232239
backupSchedule.remoteBackupLogging(backupLogPath," Backup log for: " +time.strftime("%m.%d.%Y_%H-%M-%S"))
233240
backupSchedule.remoteBackupLogging(backupLogPath,"#################################################\n")

plogical/backupScheduleLocal.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,22 @@
2121

2222
class backupScheduleLocal:
2323
localBackupPath = '/home/cyberpanel/localBackupPath'
24+
runningPath = '/home/cyberpanel/localBackupPID'
2425
now = datetime.now()
2526

2627
@staticmethod
2728
def prepare():
2829
try:
30+
31+
if os.path.exists(backupScheduleLocal.runningPath):
32+
pid = open(backupScheduleLocal.runningPath, 'r').read()
33+
print('Local backup is already running with PID: %s. If you want to run againly kindly kill the backup process: \n\n kill -9 %s.\n\n' % (pid, pid))
34+
return 0
35+
36+
writeToFile = open(backupScheduleLocal.runningPath, 'w')
37+
writeToFile.write(str(os.getpid()))
38+
writeToFile.close()
39+
2940
backupRunTime = time.strftime("%m.%d.%Y_%H-%M-%S")
3041
backupLogPath = "/usr/local/lscp/logs/local_backup_log." + backupRunTime
3142

@@ -70,8 +81,6 @@ def prepare():
7081
backupSchedule.remoteBackupLogging(backupLogPath,
7182
'[ERROR] Backup failed for %s, error: %s moving on..' % (virtualHost, str(msg)), backupSchedule.ERROR)
7283

73-
74-
7584
backupSchedule.remoteBackupLogging(backupLogPath, "")
7685
backupSchedule.remoteBackupLogging(backupLogPath, "")
7786

@@ -89,6 +98,9 @@ def prepare():
8998
job.jobSuccessSites = jobSuccessSites
9099
job.save()
91100

101+
if os.path.exists(backupScheduleLocal.runningPath):
102+
os.remove(backupScheduleLocal.runningPath)
103+
92104
except BaseException as msg:
93105
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [214:startBackup]")
94106

0 commit comments

Comments
 (0)