Copy an Odoo Production Database Safely: Why a Plain Restore Is Not Enough

Aditya Oryza Mahendra
9 min Read
6 views

Copy an Odoo Production Database Safely: Why a Plain Restore Is Not Enough

Copying a production database to your laptop is a routine task: reproduce a bug, test an upgrade, try a feature on real data. Until the day the copy sends a real e-mail to a real customer.

This post covers the cause, two fixes that were not enough, and the one that worked.

The symptom

You restore the production database, start Odoo, and a few minutes later a customer receives an e-mail from your laptop, or a cron job pushes data to a live service. Nothing in the restore warned you. The data is fine; the connections to the outside world came along with it.

The root cause: a database carries live connections

A production database is not only tables and rows. It also stores:

  • the outgoing mail server (SMTP) and its credentials,
  • active scheduled actions (crons) that send reminders, recurring invoices or syncs,
  • object storage keys (S3) and remote backup targets,
  • tokens and webhooks of third-party integrations.

Restoring the database copies all of it. Starting Odoo on the copy brings it to life.

First fix: restore, then switch things off by hand

The quickest step is a checklist: disable the mail server, archive the crons, remove the keys. It works until someone forgets one item, or until a module adds a setting that is not on the list. A manual checklist is a mitigation, not a protection.

Second fix: neutralize

Odoo has a built-in answer: odoo-bin db load -n restores the database and neutralizes it. Outgoing mail goes to a fake server, crons are disabled, and the modules that declare a neutralization step clean up their own data.

This is much better, but it only covers what Odoo and the installed modules declare. A custom module that stores an S3 key or a backup target, for example, is not touched.

The fix that worked: neutralize, sanitize, verify

The solution is to never trust a single step. odoo-mirror runs three layers every time:

  1. Neutralize with Odoo's own mechanism, always on (the wizard does not even offer a restore without it).
  2. Sanitize what the standard neutralization does not know about, such as object storage keys and remote backup targets.
  3. Verify the result instead of assuming it.

A simplified version of the sanitize step:

-- object storage credentials: a copy must never reach the real bucket DELETE FROM ir_config_parameter WHERE key ILIKE 's3.%'; -- remote backup targets: disable them only if the table and column exist DO $$ BEGIN IF to_regclass('public.db_backup_configure') IS NULL THEN RETURN; END IF; UPDATE db_backup_configure SET active = false; END $$;

(The snippet above is simplified from the real implementation.)

The flow is now:

  1. The database and the filestore are streamed over SSH. Nothing is written on the server.
  2. A zip in the Odoo format is built locally (dump.sql, manifest.json, filestore/).
  3. The zip is restored with odoo-bin db load -n.
  4. The sanitize step removes what is left.
  5. The verify step checks the copy: neutralized flag on, no active cron, no storage keys, data present, filestore present.

The run ends with a summary that names the new local database, so there is nothing to look up in the logs.

Two details that are easy to miss

Verify the result, not the step. A step that exits with success only says that a command ran. The checks that matter are on the database: the neutralized flag, the number of active crons, the number of storage keys. These are what the verify step reads.

Match the Odoo version before downloading. A database from Odoo 17 cannot be restored with an Odoo 19 checkout: the neutralization SQL of version 19 refers to columns that do not exist in a version 17 schema. The restore fails at the end, after the download. odoo-mirror reads the Odoo version of the database during the inspect step and stops before downloading when it differs from the local Odoo.

Why not just block outgoing traffic?

A firewall rule or a hosts entry for the mail server is a good extra layer, but it protects only the traffic you thought of. Neutralization removes the reason for the traffic: the credentials and the schedules. Use both if you can.

Install and first run

odoo-mirror is a Bash tool (MIT license) for Linux and WSL2. On Windows, install WSL2 once (wsl --install in an administrator PowerShell), open the Ubuntu terminal, and work from there. macOS is not supported yet.

1. Prerequisites (Ubuntu / Debian / WSL2). No Python package is needed: the tool only uses the standard library.

# to download a database and its filestore sudo apt update && sudo apt install -y openssh-client python3 gzip tar gawk sed findutils coreutils # to restore it (you provide the local Odoo and PostgreSQL server) sudo apt install -y postgresql-client unzip # optional: a nicer progress bar sudo apt install -y pv

The local PostgreSQL client must be recent enough to read dumps from your server (14.19, 15.14, 16.10, 17.6 or later); the restore step checks it and tells you.

2. Install with one command. The installer verifies the SHA-256 of the release and needs no sudo:

curl -fsSL https://github.com/adityaoryza/odoo-mirror/releases/latest/download/install.sh | bash

Prefer to read the script first? Download it with curl -fsSLO https://github.com/adityaoryza/odoo-mirror/releases/latest/download/install.sh, read it, then run bash install.sh. Open a new terminal afterwards and check:

odoo-mirror --version

3. First run. Start it with no arguments: a menu asks what you want to do (mirror a database, back up to a zip, restore a zip, list the databases of a server, run a saved profile, check the machine, update). The wizard then asks for the SSH host, port and user, the database (leave it empty to list the databases of the server and pick one, read only), whether the server needs sudo, and whether to anonymize personal data.

odoo-mirror

At the end it offers to save your answers as a profile (no password is stored), so the next time one word is enough:

odoo-mirror staging # repeats what was saved; only the passwords are asked odoo-mirror profiles # lists the saved profiles

Commands and options you will use

CommandWhat it does
odoo-mirrorMenu and wizard (the default all: download and restore).
odoo-mirror backupDownload only: builds the Odoo-format zip.
odoo-mirror restore --zip FILERestore a zip you already have, without downloading.
odoo-mirror discoverList the databases of a server (read only).
odoo-mirror checkVerify that this machine has what it needs.
odoo-mirror updateInstall the newest release (update --check only looks).
OptionMeaning
--host, --port, --user, --keySSH connection (a host alias from ~/.ssh/config works too).
--remote-db NAMEThe database to copy.
--local-db NAMEThe local database to create. Default auto: <remote-db>_<YYMMDD>, then _2, _3... while the name is taken.
--odoo-bin, --odoo-python, --odoo-confThe local Odoo to restore with. It must have the same major version as the database.
--anonymizeReplace the personal data of private individuals (companies and addresses are kept).
--sanitize-sql FILEExtra SQL for your own modules, run on the copy.
--dry-runPrint the plan and do nothing.
--steps a,b / --skip aRun only some steps (connect inspect dump filestore assemble restore sanitize verify cleanup) or skip some.
--allow-version-mismatchWarn instead of stopping when the Odoo versions differ.
--profile NAME, --save-profile NAMEUse or save a profile (plain KEY="value" files in ~/.config/odoo-mirror/profiles/, non-secret, never executed).

Every run writes a log file under ~/odoo-mirror/logs/, and zips and work files go to ~/odoo-mirror/ (keep it on the Linux side of WSL for speed).

What happens to your passwords

The SSH password or passphrase is asked by ssh itself, once; key authentication and ssh-agent work as usual. The sudo password is asked with a hidden prompt and sent through stdin only: never in arguments, history, logs or ps. A profile holds non-secret settings only.

Trade-offs to know about

  • Attachments stored in S3 are not available in the copy, because the keys are removed on purpose. They show up empty.
  • Bugs that only appear with a live integration (a payment provider, a webhook) cannot be reproduced on a neutralized copy.
  • Large databases take time: the dump and the filestore are streamed, and the restore is the longest step.
  • The tool runs on Linux and WSL2, and it was tested with Odoo 17 and Odoo 19. Other versions are unverified.

How to test it

Start with a dry run, which prints the plan without doing anything:

odoo-mirror my-profile --dry-run

After a real run, open the copy and look for the red banner "Database neutralized for testing: no emails sent, etc.", then check that no cron is active. The tool has unit tests for its decisions (names, versions, profiles, output), but the neutralization itself belongs to Odoo, so a manual check of the first copy is worth the minute it takes.

Takeaways

  1. A restore copies connections, not only data. Treat every copy as live until proven otherwise.
  2. Neutralize is necessary, not sufficient. It cannot clean what it does not know about.
  3. Verify the outcome. Check the database, not the exit code of the step.
  4. Fail early. A version mismatch found before the download costs seconds, found after it costs an afternoon.
  5. Layers beat checklists. Neutralize, sanitize, verify, and a network rule on top.

If you copy production databases regularly, give odoo-mirror a try and open an issue if something does not fit your setup.

A

Author: Aditya Oryza Mahendra

Software Engineer with expertise in backend systems, Odoo ERP development (v11–19), and Web3/dApp development. Experienced in building scalable applications using Node.js, Express.js, React, and Next.js, alongside deep customization of Odoo ERP across logistics, finance, CRM, and manufacturing domains. Currently advancing into Web3 with hands-on experience building and deploying smart contracts and decentralized applications using Solidity, Hardhat, and Ethers.js. Strong background in SQL/NoSQL databases, Docker, and VPS/Linux server administration. Contributed to the automation of 500+ daily shipments at a national logistics company.

Connect on LinkedIn