Last active
October 12, 2021 08:11
-
-
Save alorence/7e9da8754b6c0427b16e147f803d8bcf to your computer and use it in GitHub Desktop.
Very simple script to dump a named Odoo database into restorable zip file (with filestore)
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
import base64 | |
import os.path | |
import sys | |
from datetime import datetime | |
from xmlrpc.client import ServerProxy | |
full_host = os.getenv("ODOO_HOST", "http://localhost:8069") | |
master_pwd = os.getenv("ODOO_MASTER_PASSWORD") | |
if master_pwd is None: | |
exit("You must set ODOO_MASTER_PASSWORD environment variale, and probably ODOO_HOST (https://odoo_server.com:port)") | |
try: | |
_, db_name, target_dir = sys.argv | |
except ValueError as e: | |
print("Usage: odoo_backup.py <db_to_backup> <target_dir>") | |
exit(-1) | |
full_path = os.path.abspath(target_dir) | |
if not os.path.exists(full_path): | |
print("Missing target directory, try to create it") | |
os.mkdir(full_path) | |
date_str = datetime.now().strftime("%Y-%m-%d_%H-%M-%S") | |
full_path = "{full_path}/{db_name}_{date_str}.zip".format(full_path=full_path, db_name=db_name, date_str=date_str) | |
if os.path.exists(full_path): | |
sys.exit("The target file already exists !") | |
p = ServerProxy('{}/xmlrpc/db'.format(full_host)) | |
with open(full_path, "wb") as f: | |
f.write(base64.b64decode(p.dump(master_pwd, db_name, "zip"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please don't use this ! For a big enough database, the download will fail due to Xml-RPC timeout which is difficult to increase. Simply perform a POST request: