Skip to content
Tutorials Center
My learning

Topics

Lesson 35 of 39 ยท Deployment and Customisation

Backups, Restores and Upgrades

Protect an Odoo database: backups with pg_dump and the filestore, the database manager zip, automated rotation, restore tests, and a safe plan for module and major-version upgrades.

An Odoo system holds invoices, stock and payroll, so two questions matter more than any feature: "can we get it back?" and "can we move forward safely?". This lesson answers both. The commands are read-only examples, and the stand-ins model a backup bundle and a rotation policy so you can test the logic.

What a complete backup contains

Odoo state lives in two places:

  1. The PostgreSQL database, holding records, users, views, configuration.
  2. The filestore, a folder of attachments and images named by hash, normally at ~/.local/share/Odoo/filestore/<db_name> or the data_dir you configured, and /var/lib/odoo in the official Docker image.

A backup of only one half is broken: the database references files that do not exist, or files have no owner. Your custom modules and odoo.conf come from version control and configuration management, but include them in your disaster-recovery plan too.

Three ways to back up

Database manager. The page /web/database/manager produces a zip containing dump.sql (or a custom-format dump), the filestore folder and a manifest.json. It is convenient for small databases, but protected only by the master password and can time out on big ones.

Command line. The reliable choice for production:

Terminal
# database, compressed custom format
pg_dump -Fc -h 127.0.0.1 -U odoo mycompany > /backups/mycompany-$(date +%F).dump

# filestore (hard-linked incremental copy)
rsync -a --delete /var/lib/odoo/filestore/mycompany/ /backups/filestore/mycompany/

Restoring:

Terminal
createdb -U odoo mycompany_restored
pg_restore -U odoo -d mycompany_restored /backups/mycompany-2026-05-01.dump
rsync -a /backups/filestore/mycompany/ /var/lib/odoo/filestore/mycompany_restored/

Snapshots. Disk or virtual-machine snapshots can capture both halves at once, but the database must be consistent: use PostgreSQL's backup mode or stop writes first.

Good practice includes off-site copies (different provider or region), encryption of backup files, a retention policy (for example daily for 7 days, weekly for 4 weeks, monthly for a year) and a restore test on a schedule. A backup you have never restored is a hope, not a backup.

flowchart LR
    A["Production DB + filestore"] --> B["Nightly dump + rsync"]
    B --> C["Local backup folder"]
    C --> D["Encrypt and copy off-site"]
    D --> E["Monthly restore test<br/>on a staging server"]

The loop only counts as complete when the restore test passes.

Restore carefully

When restoring a production copy for testing, neutralise it so it cannot email real customers or run live integrations. Odoo's --neutralize option (and the "duplicate with neutralise" choice in the manager) disables outgoing mail, cron jobs and payment providers. Do this before the first start of a copied database.

A backup manifest stand-in

This first stand-in builds a zip in memory with a dump file, a mock filestore and a manifest that records checksums, then verifies it. This mirrors what a restore test should do: prove that the files match the manifest.

Python Create and verify a backup bundle

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A retention policy stand-in

Keeping every backup forever costs money; keeping too few loses history. This stand-in applies a daily, weekly and monthly retention rule to a list of dates.

Python Daily, weekly and monthly retention

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Upgrading modules (minor changes)

When you change your own module, update it with -u. Do this on a copy of production first:

  1. Restore last night's backup to a staging database.
  2. Run odoo -d staging -u my_module --stop-after-init and read the log for warnings.
  3. Click through the key flows.
  4. Repeat on production in a maintenance window, after a fresh backup.

For schema changes that need data movement, a module can ship migration scripts: files in migrations/<version>/pre-migrate.py and post-migrate.py. Pre scripts run before the ORM updates the tables (for example to rename a column), and post scripts run afterwards (to fill the new column).

Major-version upgrades

Moving from, say, 17.0 to 18.0 changes the database schema, the standard modules and often your custom code. Odoo Enterprise customers can use Odoo's upgrade platform, and the open-source route is the community OpenUpgrade project. The method is always the same:

  • Never upgrade in place. Upgrade a copy.
  • Upgrade one major version at a time where the tool requires it.
  • Port your custom modules first (renamed views such as <tree> to <list>, removed attrs, API changes) and run their tests.
  • Check reports, integrations and mail templates, because they hide the most surprises.
  • Keep the old system read-only until the new one is signed off.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which two parts must a complete Odoo backup include?

    Records are in PostgreSQL, while attachments and images are in the filestore; each is incomplete without the other.
  2. 2. Why restore a production backup on a staging server regularly?

    An untested backup may be unusable. Restore tests and upgrade rehearsals catch problems safely.
  3. 3. What does neutralising a restored database do?

    A test copy must not send real emails or trigger live integrations.
  4. 4. When does a pre-migrate script run?

    Pre scripts run before the schema update, for tasks like renaming columns; post scripts run after it.

Summary

  • Back up both the database (pg_dump) and the filestore, plus config and code from version control.
  • Encrypt, copy off-site, rotate with a retention policy and test restores.
  • Neutralise restored copies before starting them.
  • Update modules on a staging copy first; use pre and post migration scripts for data changes.
  • Upgrade major versions on a copy, one step at a time, with your custom code ported first.

Next: Customising with View Inheritance