[ADD]Odoo backup image with integrated plan
This commit is contained in:
parent
cf14fc9d21
commit
fb83b0aeab
@ -15,6 +15,7 @@ RUN chmod 644 /etc/crontab
|
||||
RUN touch /var/log/cron.log
|
||||
|
||||
COPY backup.template .
|
||||
COPY plan.py .
|
||||
COPY launch.sh .
|
||||
|
||||
RUN chown -R odoo:odoo . && chown odoo:odoo /var/log/cron.log
|
||||
|
@ -1,5 +1,6 @@
|
||||
# daily odoo backup
|
||||
# m h dom mon dow user command
|
||||
0 2 * * * odoo /bin/bash /home/odoo/backup.sh >> /var/log/cron.log 2>&1
|
||||
10 2 * * * odoo /usr/bin/python /home/odoo/plan.py >> /var/log/cron.log 2>&1
|
||||
# empty line required at the end of this file for a valid cron file.
|
||||
|
||||
|
53
odoo/backups/plan.py
Normal file
53
odoo/backups/plan.py
Normal file
@ -0,0 +1,53 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Backup plan for Odoo databases
|
||||
::::::::::::::::::::::::::::::
|
||||
|
||||
Keep :
|
||||
|
||||
- all saves the last week
|
||||
- one save per week the last month
|
||||
- one save per month the last year
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
from os import unlink
|
||||
from glob import glob
|
||||
|
||||
DT = datetime.now()
|
||||
|
||||
def notkeep(fname):
|
||||
""" Filter all obsolete save files """
|
||||
fname = fname.split('/')[-1]
|
||||
fname = fname.split('_')
|
||||
if len(fname) <= 1:
|
||||
return False
|
||||
save_date = fname[0]
|
||||
save_date = datetime.strptime(save_date, '%Y-%m-%d')
|
||||
delta = DT - save_date
|
||||
if delta.days > 365:
|
||||
return True
|
||||
elif delta.days > 31:
|
||||
# if (delta.days %% 30) != 0:
|
||||
if save_date.day != 1:
|
||||
return True
|
||||
elif delta.days > 7:
|
||||
# if (delta.days %% 7) != 0:
|
||||
if (save_date.weekday() != 0) and (save_date.day != 1):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
# Filters zip files and keeps only legitimate ones
|
||||
# ================================================
|
||||
|
||||
FILES = glob('backups/*.zip')
|
||||
BACKUPS_TO_REMOVE = filter(notkeep, FILES)
|
||||
|
||||
if len(BACKUPS_TO_REMOVE) > 0:
|
||||
print('Save files outdated, will be deleted : \n\n* ' +
|
||||
'\n* '.join(BACKUPS_TO_REMOVE))
|
||||
|
||||
for b in BACKUPS_TO_REMOVE:
|
||||
unlink(b)
|
Loading…
Reference in New Issue
Block a user