This question has been flagged

Hi All,

Not a question, but a feedback after I encountered issues restoring an instance of Odoo on another machine.

BACKUP FROM SOURCE:

1. Dump your database

sudo -u postgres pg_dump -U postgres -E UTF-8 -F p -b -C -f <<your_backup_filename.sql>> <<your_odoo_database_name>>

Replace <<your_backup_filename.sql>> with a name of your choice and <<your_odoo_database_name>> with the name of your Odoo database. Ensure the postgres user has right permissions on the target directory (consider using /tmp/ for example)

This will produce a complete SQL dump of your Odoo database including statements to create the database itself when restoring.

2. Archive your files

$ tar -cf <<your_directory>>/odoo-filestore.tar /var/lib/odoo/.local/share/Odoo/filestore/<<your_odoo_database_name>>/
$ tar -cf <<your_directory>>/odoo-local-addons.tar /var/lib/odoo/.local/share/Odoo/addons
$ tar -cf <<your_directory>>/odoo-global-addons.tar /usr/lib/python2.7/dist-packages/odoo/addons

Make an archive of:

  • the file-store relative to your database (since Odoo 8, files are not stored in database but on the file system), replace <<your_odoo_database_name>> with the name of your Odoo database.

  • the addons downloaded from the UI (local to your Odoo instance),

  • the global addons available with all your Odoo instances.

RESTORE ON TARGET:

1. Stop Odoo

/etc/init.d/odoo stop

2. Expend file archives

Remove folder /var/lib/odoo/.local/share/Odoo/filestore/<<your_odoo_database_name>>/

Remove folder /var/lib/odoo/.local/share/Odoo/addons

Remove folder /usr/lib/python2.7/dist-packages/odoo/addons

$ tar xvf <<archive-name.tar>>

Expend all 3 archives and move directories on the target machine to their respective locations .

3. Restore database

$ sudo -u postgres psql
postgres=# DROP DATABASE <<your_odoo_database_name>>
postgres=# \i <<path_to/your_backup_filename.sql>>
postgres=# \q

Connect to your PostgreSQL server, drop the current database and import your database dump. This file will create the database and make it owned by user odoo.

4. Update your filestore

$ sudo -u odoo odoo -c /etc/odoo/odoo.conf -u all

Start Odoo from command line as user odoo and force update (-u all option), then browse to your Odoo server from http://<<your_odoo_url>>:<<your_odoo_port>>. Example : http://127.0.0.1:8069.

The first request will require a little moment to run: Odoo proceeds to an complete update.

When done, type CTRL+C to stop Odoo.

$ /etc/init.d/odoo start

Restart odoo as a daemon. Done. \o/


Avatar
Discard

Thanks for the write up. For the next time, it would be better to create it as a Q&A, like here: https://www.odoo.com/forum/help-1/question/ubuntu-16-04-how-to-install-sass-for-odoo-123090 .

What I'm looking for since a long time: how is it possible to restore a database without stopping Odoo?

Author Best Answer

@F. P.,

The SQL script generated by pg_dump restores the database ownership when recreating the database (-C option).

@Ermin Trevisan

Odoo keeps data in memory cache for performance considerations. Some data may not be saved yet on the source, some data in memory may differ from those in the database on the target. Trying to backup or restore Odoo database without stopping the application before may lead to data inconsistencies or data losses. Do always stop Odoo before doing maintenance operations on its database.

Avatar
Discard
Best Answer

 nice write up. one thing: when db owner changes, odoo will give you access errors. need to run change owner queries in db to get rid of them.

Avatar
Discard
Best Answer

This addon do Automatic Backup DB and Filestore separate to the specified path.

Available Backup DB/Filestore Modes:

  • Local
  • Remote Server
  • Google Drive
  • Dropbox

Module For backup ODOO databases and automating the backup process of ODOO.

  • Multiple Backup Modes
  • Filestore Backup
  • Backup ODOO Databases in specified path
  • Detailed Message Log
  • Backup Status Information and History
  • User can select the format to dump, either custom archive, plain text SQL or tar archive
  • Archive Backup Process
  • Repeat Missed Backup Process

Features

  • Dump ODOO Database in specified format
  • Output a custom archive suitable for input into pg_restore. This is the most flexible format in that it allows the reordering of loading data as well as to object definitions. This format is also compressed by default. Here we user gzip ie, test.gz, We also recommend you to select Custom, because Using the custom format you can restore single objects from a backup.
  • Output a plain-text SQL script file (the default). The plain text format is useful for very small databases with a minimal number of objects but other than that, it should be avoided.
  • Output a tar archive suitable for input into pg_restore. Using this archive format allows reordering and/or exclusion of database objects at the time the database is restored. It is also possible to limit which data is reloaded at restore time. we use tar with gzip
  • Backup Filestore
  • Multiple backup modes at sametime

https://apps.odoo.com/apps/modules/13.0/auto_backup_odoo/

Avatar
Discard