[IMP]Odoo backups plan : usage of env OBPLAN

This commit is contained in:
Fabien BOURGEOIS 2023-12-22 15:37:14 +01:00
parent c3962fc74a
commit 1ed86ce696

View File

@ -12,9 +12,12 @@ Keep :
""" """
from datetime import datetime from datetime import datetime
from os import unlink from os import unlink, environ
from glob import glob from glob import glob
OBPLAN = environ.get('OBPLAN', u'365,31,7')
OBPLAN = map(int, OBPLAN.split(u','))
DT = datetime.now() DT = datetime.now()
def notkeep(fname): def notkeep(fname):
@ -26,12 +29,12 @@ def notkeep(fname):
save_date = fname[0] save_date = fname[0]
save_date = datetime.strptime(save_date, '%Y-%m-%d') save_date = datetime.strptime(save_date, '%Y-%m-%d')
delta = DT - save_date delta = DT - save_date
if delta.days > 365: if delta.days > OBPLAN[0]:
return True return True
elif delta.days > 31: elif delta.days > OBPLAN[1]:
if save_date.day != 1: if save_date.day != 1:
return True return True
elif delta.days > 7: elif delta.days > OBPLAN[2]:
if (save_date.weekday() != 0) and (save_date.day != 1): if (save_date.weekday() != 0) and (save_date.day != 1):
return True return True
else: else: