prevent local backup from running multiple processes

This commit is contained in:
Usman Nasir
2020-05-22 16:03:49 +05:00
parent 5d2255ecf2
commit df4cea0ebb
2 changed files with 21 additions and 2 deletions

View File

@@ -228,6 +228,13 @@ class backupSchedule:
backupLogPath = "/usr/local/lscp/logs/backup_log."+time.strftime("%m.%d.%Y_%H-%M-%S") backupLogPath = "/usr/local/lscp/logs/backup_log."+time.strftime("%m.%d.%Y_%H-%M-%S")
jobSuccessSites = 0
jobFailedSites = 0
backupSchedule.backupLog = BackupJob(logFile=backupLogPath, location=backupSchedule.REMOTE,
jobSuccessSites=jobSuccessSites, jobFailedSites=jobFailedSites)
backupSchedule.backupLog.save()
backupSchedule.remoteBackupLogging(backupLogPath,"#################################################") backupSchedule.remoteBackupLogging(backupLogPath,"#################################################")
backupSchedule.remoteBackupLogging(backupLogPath," Backup log for: " +time.strftime("%m.%d.%Y_%H-%M-%S")) backupSchedule.remoteBackupLogging(backupLogPath," Backup log for: " +time.strftime("%m.%d.%Y_%H-%M-%S"))
backupSchedule.remoteBackupLogging(backupLogPath,"#################################################\n") backupSchedule.remoteBackupLogging(backupLogPath,"#################################################\n")

View File

@@ -21,11 +21,22 @@ from websiteFunctions.models import BackupJob, BackupJobLogs
class backupScheduleLocal: class backupScheduleLocal:
localBackupPath = '/home/cyberpanel/localBackupPath' localBackupPath = '/home/cyberpanel/localBackupPath'
runningPath = '/home/cyberpanel/localBackupPID'
now = datetime.now() now = datetime.now()
@staticmethod @staticmethod
def prepare(): def prepare():
try: try:
if os.path.exists(backupScheduleLocal.runningPath):
pid = open(backupScheduleLocal.runningPath, 'r').read()
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))
return 0
writeToFile = open(backupScheduleLocal.runningPath, 'w')
writeToFile.write(str(os.getpid()))
writeToFile.close()
backupRunTime = time.strftime("%m.%d.%Y_%H-%M-%S") backupRunTime = time.strftime("%m.%d.%Y_%H-%M-%S")
backupLogPath = "/usr/local/lscp/logs/local_backup_log." + backupRunTime backupLogPath = "/usr/local/lscp/logs/local_backup_log." + backupRunTime
@@ -70,8 +81,6 @@ class backupScheduleLocal:
backupSchedule.remoteBackupLogging(backupLogPath, backupSchedule.remoteBackupLogging(backupLogPath,
'[ERROR] Backup failed for %s, error: %s moving on..' % (virtualHost, str(msg)), backupSchedule.ERROR) '[ERROR] Backup failed for %s, error: %s moving on..' % (virtualHost, str(msg)), backupSchedule.ERROR)
backupSchedule.remoteBackupLogging(backupLogPath, "") backupSchedule.remoteBackupLogging(backupLogPath, "")
backupSchedule.remoteBackupLogging(backupLogPath, "") backupSchedule.remoteBackupLogging(backupLogPath, "")
@@ -89,6 +98,9 @@ class backupScheduleLocal:
job.jobSuccessSites = jobSuccessSites job.jobSuccessSites = jobSuccessSites
job.save() job.save()
if os.path.exists(backupScheduleLocal.runningPath):
os.remove(backupScheduleLocal.runningPath)
except BaseException as msg: except BaseException as msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [214:startBackup]") logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [214:startBackup]")