Last active
February 8, 2025 13:27
-
-
Save justinmassiot/d3aa8f590fe3a131b9980a645a77be8d to your computer and use it in GitHub Desktop.
Database management example with OdooRPC: https://pythonhosted.org/OdooRPC/ref_db.html#odoorpc.db.DB Dump an Odoo Online database: https://{{db_name}}.odoo.com/saas_worker/dump Dump any database: https://pythonhosted.org/OdooRPC/ref_db.html#odoorpc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://pythonhosted.org/OdooRPC/ref_db.html#odoorpc.db.DB | |
import sys # in order to capture stdin | |
import os | |
import argparse | |
import odoorpc # pip install odoorpc | |
from datetime import datetime | |
argParser = argparse.ArgumentParser() | |
argParser.add_argument('-d', '--desthost', help='Destination server address') | |
argParser.add_argument('-p', '--masterpw', help='Master Password of the destination server') | |
argParser.add_argument('dumpfile', help='Input dump file, ZIP archive format') | |
args = argParser.parse_args() | |
print('Connecting to', args.desthost, '...', flush=True) | |
odoo = odoorpc.ODOO(args.desthost, protocol='jsonrpc', port=8069) | |
print('> Version:', odoo.version) | |
# restore from a dump file: | |
print('Loading database file', args.dumpfile, 'onto server', args.desthost, '...', flush=True) | |
with open(args.dumpfile, 'rb') as dump_file: | |
timeout_backup = odoo.config['timeout'] | |
odoo.config['timeout'] = 3600 # timeout set to 1 hour | |
#now = datetime.now() | |
#odoo.db.restore(args.masterpw, 'dump-restore_{}'.format(now.strftime("%Y%m%d-%H%M%S")), dump_file, copy=False) | |
odoo.db.restore(args.masterpw, os.path.basename(os.path.splitext(args.dumpfile)[0]), dump_file, copy=False) | |
odoo.config['timeout'] = timeout_backup | |
print('> Done!') | |
print('Listing databases ...', flush=True) | |
for dbitem in odoo.db.list(): | |
print('>', dbitem) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment