mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-12 00:06:09 +01:00
setup auto deletion for aws backups
This commit is contained in:
@@ -686,12 +686,15 @@ Automatic backup failed for %s on %s.
|
|||||||
|
|
||||||
ts = time.time()
|
ts = time.time()
|
||||||
|
|
||||||
|
retentionSeconds = 86400 * plan.retention
|
||||||
|
|
||||||
for bucket in s3.buckets.all():
|
for bucket in s3.buckets.all():
|
||||||
for file in bucket.objects.all():
|
if bucket.name == plan.bucket:
|
||||||
result = float(ts - file.last_modified.timestamp())
|
for file in bucket.objects.all():
|
||||||
if result > 100.0:
|
result = float(ts - file.last_modified.timestamp())
|
||||||
file.delete()
|
if result > retentionSeconds:
|
||||||
print(result)
|
file.delete()
|
||||||
|
break
|
||||||
|
|
||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
logging.writeToFile(str(msg) + ' [S3Backups.runBackupPlan]')
|
logging.writeToFile(str(msg) + ' [S3Backups.runBackupPlan]')
|
||||||
@@ -699,71 +702,11 @@ Automatic backup failed for %s on %s.
|
|||||||
BackupLogs(owner=plan, timeStamp=time.strftime("%b %d %Y, %H:%M:%S"), level='ERROR', msg=str(msg)).save()
|
BackupLogs(owner=plan, timeStamp=time.strftime("%b %d %Y, %H:%M:%S"), level='ERROR', msg=str(msg)).save()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def runAWSBackups():
|
def runAWSBackups(freq):
|
||||||
try:
|
try:
|
||||||
for plan in BackupPlan.objects.all():
|
for plan in BackupPlan.objects.all():
|
||||||
lastRunDay = plan.lastRun.split(':')[0]
|
if plan.freq == 'Daily' == freq:
|
||||||
lastRunMonth = plan.lastRun.split(':')[1]
|
|
||||||
|
|
||||||
if plan.freq == 'Daily' and lastRunDay != time.strftime("%d"):
|
|
||||||
IncScheduler.forceRunAWSBackup(plan.name)
|
IncScheduler.forceRunAWSBackup(plan.name)
|
||||||
else:
|
|
||||||
if lastRunMonth == time.strftime("%m"):
|
|
||||||
days = int(time.strftime("%d")) - int(lastRunDay)
|
|
||||||
if days >= 6:
|
|
||||||
IncScheduler.forceRunAWSBackup(plan.name)
|
|
||||||
else:
|
|
||||||
days = 30 - int(lastRunDay)
|
|
||||||
days = days + int(time.strftime("%d"))
|
|
||||||
if days >= 6:
|
|
||||||
IncScheduler.forceRunAWSBackup(plan.name)
|
|
||||||
|
|
||||||
# for plan in BackupPlanDO.objects.all():
|
|
||||||
# lastRunDay = plan.lastRun.split(':')[0]
|
|
||||||
# lastRunMonth = plan.lastRun.split(':')[1]
|
|
||||||
#
|
|
||||||
# if plan.freq == 'Daily' and lastRunDay != time.strftime("%d"):
|
|
||||||
# self.data = {}
|
|
||||||
# self.data['planName'] = plan.name
|
|
||||||
# self.forceRunAWSBackupDO()
|
|
||||||
# else:
|
|
||||||
# if lastRunMonth == time.strftime("%m"):
|
|
||||||
# days = int(time.strftime("%d")) - int(lastRunDay)
|
|
||||||
# if days >= 6:
|
|
||||||
# self.data = {}
|
|
||||||
# self.data['planName'] = plan.name
|
|
||||||
# self.forceRunAWSBackupDO()
|
|
||||||
# else:
|
|
||||||
# days = 30 - int(lastRunDay)
|
|
||||||
# days = days + int(time.strftime("%d"))
|
|
||||||
# if days >= 6:
|
|
||||||
# self.data = {}
|
|
||||||
# self.data['planName'] = plan.name
|
|
||||||
# self.forceRunAWSBackupDO()
|
|
||||||
#
|
|
||||||
# for plan in BackupPlanMINIO.objects.all():
|
|
||||||
# lastRunDay = plan.lastRun.split(':')[0]
|
|
||||||
# lastRunMonth = plan.lastRun.split(':')[1]
|
|
||||||
#
|
|
||||||
# if plan.freq == 'Daily' and lastRunDay != time.strftime("%d"):
|
|
||||||
# self.data = {}
|
|
||||||
# self.data['planName'] = plan.name
|
|
||||||
# self.forceRunAWSBackupMINIO()
|
|
||||||
# else:
|
|
||||||
# if lastRunMonth == time.strftime("%m"):
|
|
||||||
# days = int(time.strftime("%d")) - int(lastRunDay)
|
|
||||||
# if days >= 6:
|
|
||||||
# self.data = {}
|
|
||||||
# self.data['planName'] = plan.name
|
|
||||||
# self.forceRunAWSBackupMINIO()
|
|
||||||
# else:
|
|
||||||
# days = 30 - int(lastRunDay)
|
|
||||||
# days = days + int(time.strftime("%d"))
|
|
||||||
# if days >= 6:
|
|
||||||
# self.data = {}
|
|
||||||
# self.data['planName'] = plan.name
|
|
||||||
# self.forceRunAWSBackupMINIO()
|
|
||||||
|
|
||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
logging.writeToFile(str(msg) + ' [S3Backups.runAWSBackups]')
|
logging.writeToFile(str(msg) + ' [S3Backups.runAWSBackups]')
|
||||||
|
|
||||||
@@ -785,7 +728,7 @@ def main():
|
|||||||
IncScheduler.git(args.function)
|
IncScheduler.git(args.function)
|
||||||
IncScheduler.checkDiskUsage()
|
IncScheduler.checkDiskUsage()
|
||||||
IncScheduler.startNormalBackups(args.function)
|
IncScheduler.startNormalBackups(args.function)
|
||||||
IncScheduler.runAWSBackups()
|
IncScheduler.runAWSBackups(args.function)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user