Skip to content

Instantly share code, notes, and snippets.

@alorence
Last active October 12, 2021 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alorence/7e9da8754b6c0427b16e147f803d8bcf to your computer and use it in GitHub Desktop.
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)
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")))
@alorence
Copy link
Author

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:

wget --post-data "master_pwd=$ODOO_MASTER_PASSWORD&name=$ODOO_DATABASE_NAME&backup_format=zip" -O default_$(date +%Y-%m-%d_%H-%M-%S).zip -T 300 $ODOO_HOST/web/database/backup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment