[ADD]Odoo image backup service
This commit is contained in:
parent
9c82fca298
commit
f8bc904153
16
odoo/backups/Dockerfile
Normal file
16
odoo/backups/Dockerfile
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
FROM odoocmd:8.0
|
||||||
|
MAINTAINER Yaltik - Fabien Bourgeois <fabien@yaltik.com>
|
||||||
|
|
||||||
|
ENV ODOO_ADMIN_PASSWORD admin
|
||||||
|
ENV ODOO_DATABASES demo
|
||||||
|
WORKDIR /home/odoo
|
||||||
|
USER root
|
||||||
|
RUN mkdir backups
|
||||||
|
RUN apt-get install -y --no-install-recommends cron gettext-base
|
||||||
|
COPY crontab /etc/crontab
|
||||||
|
RUN chmod 644 /etc/crontab
|
||||||
|
COPY backup.template .
|
||||||
|
COPY launch.sh .
|
||||||
|
RUN chown -R odoo:odoo .
|
||||||
|
VOLUME /home/odoo/backups
|
||||||
|
CMD bash launch.sh
|
3
odoo/backups/backup.template
Normal file
3
odoo/backups/backup.template
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
python backup.py -oh golem -pw ${ODOO_ADMIN_PASSWORD} -D backups/ -n ${ODOO_DATABASES}
|
3
odoo/backups/crontab
Normal file
3
odoo/backups/crontab
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# daily odoo backup
|
||||||
|
# m h dom mon dow user command
|
||||||
|
0 0 * * * odoo /bin/bash /opt/odoo/backup.sh
|
5
odoo/backups/launch.sh
Normal file
5
odoo/backups/launch.sh
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
envsubst < /home/odoo/backup.template > /home/odoo/backup.sh
|
||||||
|
chown odoo:odoo /home/odoo/backup.sh
|
||||||
|
cron -f
|
@ -23,3 +23,7 @@ services:
|
|||||||
odoocmd:
|
odoocmd:
|
||||||
build: ./scripts
|
build: ./scripts
|
||||||
image: odoocmd:8.0
|
image: odoocmd:8.0
|
||||||
|
|
||||||
|
odoobackup:
|
||||||
|
build: ./backups
|
||||||
|
image: odoobackup:8.0
|
||||||
|
@ -9,3 +9,4 @@ RUN useradd odoo -m -s /bin/bash
|
|||||||
USER odoo
|
USER odoo
|
||||||
COPY *.py /home/odoo/
|
COPY *.py /home/odoo/
|
||||||
WORKDIR /home/odoo
|
WORKDIR /home/odoo
|
||||||
|
CMD /bin/true
|
||||||
|
@ -11,20 +11,21 @@ def datefmt():
|
|||||||
return today.strftime('%Y-%m-%d_%Hh%Mm%Ss')
|
return today.strftime('%Y-%m-%d_%Hh%Mm%Ss')
|
||||||
|
|
||||||
|
|
||||||
def dump(odoo, bakpath, password, dbname):
|
def dump(odoo, bakpath, password, dbnames):
|
||||||
""" Dumps a database """
|
""" Dumps a database list """
|
||||||
dump = odoo.db.dump(password, dbname)
|
for dbname in dbnames:
|
||||||
fpath = '{bakpath}/{date}_{dbname}.zip'.format(bakpath=bakpath,
|
dump = odoo.db.dump(password, dbname)
|
||||||
dbname=dbname,
|
fpath = '{bakpath}/{date}_{dbname}.zip'.format(bakpath=bakpath,
|
||||||
date=datefmt())
|
dbname=dbname,
|
||||||
with open(fpath, 'wb') as zipf:
|
date=datefmt())
|
||||||
zipf.write(dump.read())
|
with open(fpath, 'wb') as zipf:
|
||||||
return fpath
|
zipf.write(dump.read())
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def dump_all(odoo, bakpath, password):
|
def dump_all(odoo, bakpath, password):
|
||||||
""" Dump all databases """
|
""" Dump all databases """
|
||||||
return [dump(bakpath, password, db) for db in odoo.db.list()]
|
return dump(odoo, bakpath, password, odoo.db.list())
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@ -35,18 +36,18 @@ def main():
|
|||||||
help='the odoo master password')
|
help='the odoo master password')
|
||||||
parser.add_argument('-D', '--directory', type=str, required=True,
|
parser.add_argument('-D', '--directory', type=str, required=True,
|
||||||
help='the directory path where to save backups')
|
help='the directory path where to save backups')
|
||||||
parser.add_argument('-n', '--name', type=str,
|
parser.add_argument('-n', '--names', type=str,
|
||||||
help='optional database name (default:all)')
|
help='optional database names (default:all)')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Connection
|
# Connection
|
||||||
odoo = common.connection(args)
|
odoo = common.connection(args)
|
||||||
|
|
||||||
# Backup actions
|
# Backup actions
|
||||||
if not args.name:
|
if not args.names:
|
||||||
dump_all(odoo, args.directory, args.password)
|
dump_all(odoo, args.directory, args.password)
|
||||||
else:
|
else:
|
||||||
dump(odoo, args.directory, args.password, args.name)
|
dump(odoo, args.directory, args.password, args.names.split(','))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user