[IMP]Odoo backup : handle dump/SQL formats for backups too (default zip)
This commit is contained in:
parent
d97cd98130
commit
5e2519c024
@ -1 +1 @@
|
||||
python backup.py -oh ${HOST} -pw ${ADMIN_PASSWORD} -D backups/ -n ${DATABASES}
|
||||
python backup.py -oh ${HOST} -pw ${ADMIN_PASSWORD} -f ${FMT} -D backups/ -n ${DATABASES}
|
||||
|
@ -11,7 +11,8 @@ do
|
||||
HOST=${host}
|
||||
ADMIN_PASSWORD=${ODOO_ADMIN_PASSWORD[$index]}
|
||||
DATABASES=${ODOO_DATABASES[$index]}
|
||||
export HOST ADMIN_PASSWORD DATABASES
|
||||
FMT=${ODOO_FMT:='zip'}
|
||||
export HOST ADMIN_PASSWORD DATABASES FMT
|
||||
envsubst < /home/odoo/backup.template >> /home/odoo/backup.sh
|
||||
((index++))
|
||||
done
|
||||
|
@ -40,7 +40,7 @@ def notkeep(fname):
|
||||
# Filters zip files and keeps only legitimate ones
|
||||
# ================================================
|
||||
|
||||
FILES = glob('backups/*.zip')
|
||||
FILES = glob('backups/*.zip') + glob('backups/*.dump')
|
||||
BACKUPS_TO_REMOVE = filter(notkeep, FILES)
|
||||
|
||||
if len(BACKUPS_TO_REMOVE) > 0:
|
||||
|
@ -1,5 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
""" Odoo backup script """
|
||||
|
||||
from datetime import datetime
|
||||
import argparse
|
||||
import common
|
||||
@ -11,21 +13,22 @@ def datefmt():
|
||||
return today.strftime('%Y-%m-%d_%Hh%Mm%Ss')
|
||||
|
||||
|
||||
def dump(odoo, bakpath, password, dbnames):
|
||||
def dump(odoo, bakpath, password, dbnames, format_):
|
||||
""" Dumps a database list """
|
||||
for dbname in dbnames:
|
||||
dump = odoo.db.dump(password, dbname)
|
||||
fpath = '{bakpath}/{date}_{dbname}.zip'.format(bakpath=bakpath,
|
||||
dbname=dbname,
|
||||
date=datefmt())
|
||||
dumpf = odoo.db.dump(password, dbname, format_)
|
||||
fpath = '{bakpath}/{date}_{dbname}.{fmt}'.format(bakpath=bakpath,
|
||||
dbname=dbname,
|
||||
date=datefmt(),
|
||||
fmt=format_)
|
||||
with open(fpath, 'wb') as zipf:
|
||||
zipf.write(dump.read())
|
||||
zipf.write(dumpf.read())
|
||||
return True
|
||||
|
||||
|
||||
def dump_all(odoo, bakpath, password):
|
||||
def dump_all(odoo, bakpath, password, format_):
|
||||
""" Dump all databases """
|
||||
return dump(odoo, bakpath, password, odoo.db.list())
|
||||
return dump(odoo, bakpath, password, odoo.db.list(), format_)
|
||||
|
||||
|
||||
def main():
|
||||
@ -38,6 +41,8 @@ def main():
|
||||
help='the directory path where to save backups')
|
||||
parser.add_argument('-n', '--names', type=str,
|
||||
help='optional database names (default:all)')
|
||||
parser.add_argument('-f', '--format', type=str, default='zip',
|
||||
help='optional database format (default:zip)')
|
||||
args = parser.parse_args()
|
||||
|
||||
# Connection
|
||||
@ -45,9 +50,9 @@ def main():
|
||||
|
||||
# Backup actions
|
||||
if not args.names:
|
||||
dump_all(odoo, args.directory, args.password)
|
||||
dump_all(odoo, args.directory, args.password, args.format)
|
||||
else:
|
||||
dump(odoo, args.directory, args.password, args.names.split(','))
|
||||
dump(odoo, args.directory, args.password, args.names.split(','), args.format)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user