Files
CyberPanel/plogical/backupScheduleLocal.py

61 lines
2.5 KiB
Python
Raw Normal View History

2019-12-12 08:46:07 +05:00
import CyberCPLogFileWriter as logging
2017-10-24 19:16:36 +05:00
import os
import time
2019-12-11 10:40:35 +05:00
from .backupSchedule import backupSchedule
from plogical.processUtilities import ProcessUtilities
from re import match,I,M
2017-10-24 19:16:36 +05:00
class backupScheduleLocal:
localBackupPath = '/home/cyberpanel/localBackupPath'
2017-10-24 19:16:36 +05:00
@staticmethod
def prepare():
try:
backupLogPath = "/usr/local/lscp/logs/local_backup_log." + time.strftime("%m.%d.%Y_%H-%M-%S")
2017-10-24 19:16:36 +05:00
writeToFile = open(backupLogPath, "a")
2018-08-18 03:56:25 +05:00
backupSchedule.remoteBackupLogging(backupLogPath, "#################################################")
backupSchedule.remoteBackupLogging(backupLogPath," Local Backup log for: " + time.strftime("%m.%d.%Y_%H-%M-%S"))
2018-08-18 03:56:25 +05:00
backupSchedule.remoteBackupLogging(backupLogPath, "#################################################\n")
2017-10-24 19:16:36 +05:00
2018-08-18 03:56:25 +05:00
backupSchedule.remoteBackupLogging(backupLogPath, "")
backupSchedule.remoteBackupLogging(backupLogPath, "")
2017-10-24 19:16:36 +05:00
for virtualHost in os.listdir("/home"):
if match(r'([\da-z\.-]+\.[a-z\.]{2,12}|[\d\.]+)([\/:?=&#]{1}[\da-z\.-]+)*[\/\?]?', virtualHost, M | I):
retValues = backupSchedule.createLocalBackup(virtualHost, backupLogPath)
if os.path.exists(backupScheduleLocal.localBackupPath):
backupPath = retValues[1] + ".tar.gz"
localBackupPath = '%s/%s' % (open(backupScheduleLocal.localBackupPath, 'r').read().rstrip('/'), time.strftime("%b-%d-%Y"))
command = 'mkdir -p %s' % (localBackupPath)
ProcessUtilities.normalExecutioner(command)
command = 'mv %s %s' % (backupPath, localBackupPath)
ProcessUtilities.normalExecutioner(command)
2018-08-18 03:56:25 +05:00
backupSchedule.remoteBackupLogging(backupLogPath, "")
backupSchedule.remoteBackupLogging(backupLogPath, "")
backupSchedule.remoteBackupLogging(backupLogPath, "#################################################")
backupSchedule.remoteBackupLogging(backupLogPath, "")
backupSchedule.remoteBackupLogging(backupLogPath, "")
2017-10-24 19:16:36 +05:00
2018-08-18 03:56:25 +05:00
backupSchedule.remoteBackupLogging(backupLogPath, "Local backup job completed.\n")
2017-10-24 19:16:36 +05:00
writeToFile.close()
2019-12-10 15:09:10 +05:00
except BaseException as msg:
2019-07-18 14:08:00 +05:00
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [214:startBackup]")
2017-10-24 19:16:36 +05:00
2018-08-18 15:16:15 +05:00
def main():
backupScheduleLocal.prepare()
2017-10-24 19:16:36 +05:00
2018-08-18 15:16:15 +05:00
if __name__ == "__main__":
main()