How-to restore an Odoo backup (quick help)

Emergency

If you need this how-to, your best option is to use the Lynx web browser in a terminal session on the server. It is text-mode only. Obviously, you will first copy the backup on the server file-system.

Terminal based

Often, you don’t need to restore images or attachments. They are recorded in the  server filesystem. In this case, you can remove the filestore/ part from the backup file and use the one already on your server (see below). It is the heavier part of the backup. Assuming the database name is www and the owner is odoo, proceed as below (this way you can reuse your filestore/ folder) :

$ sudo su postgres
$ dropdb www
$ createdb -O odoo www
$ psql www < dump.sql

Restoring database from web browser

First, increase http server time-out, don’t forget to restart the daemon.

Following nginx documentation, you can set client_max_body_size to 25M ( or any value you need ) in the following context : http, server, location. So just set it wherever you want. For example :

# increase size to 300 MB for restoring backups
client_max_body_size 300M;

Launch the database manager https://[odoo_url]/web/database/manager and follow the instructions to upload your backup file.

Restoring database from Terminal

Understanding the backup file

The Odoo 10 backup utility does a classical Postgresql dump and agregate metadatas and static files. Unzip the backup file, you will get :

  • filestore/
    static files stored on disk, like images, attachments, …
  • dump.sql
    Postgresql backup — your datas
  • manifest.json
    contains list of modules, Odoo version, db name, Postgresql version, etc.

As a direct result of Postgresgl command, the dump.sql part can be restored with a simple Postgresql command, and the filestore/ part copied to the server (usually in /var/lib/odoo).

Replacing the current database

In case you want to restore with the same database name, you will first delete your database before recreate it. This way you can reuse your filestore/ folder :

$ dropdb database_name

Restoring dump file

Before restoring you have to create a new database (you need to create the database using the same Postgresql user of Odoo or you won’t be able to use it) :

$ createdb new_database_name

Or pass the Postgresql user name :

$ createdb -O db_user_name new_database_name

Unzip the backup, filestore/ files goes to:

/var/lib/odoo/filestore/[new_database_name]]

and dump.sql will be restored with :

$ psql new_database_name < dump.sql

One can’t use the pg_restore utility because Odoo creates sql backup in text format instead of archive format.
If you created you own backup using pg_dump utility, it is in archive format. In this case only use pg_restore like this (the -C option will force Postgresql to use the database name stored in the dump file) :

$ pg_restore -d any_database_name -U root -C dump.sql

NB : use below command to restore large backup file

What is the default modules folder in Odoo ?

I host my Odoo servers on Centos 7 and Debian Linux. This short answer is also right for any Linux distribution using packages downloaded from Odoo website either RPM (Red-Hat, SuSE, Mageia, …) or DEB (Ubuntu, Linux Mint, …).

Odoo RPM and DEB packages comes with 2 default modules folder :

  1. Python packages folder which is default addons folder in odoo.conf. It is used only by packages (rpm, deb and Python packages). It is reserved for Odoo default modules, do not use it. Rpm and Deb use quite the same folder :
    • For RPM (Centos 7) it is /usr/lib/python2.7/site-packages/odoo/addons
    • For DEB (Debian 9) it is /usr/lib/python2.7/dist-packages/odoo/addons
  2. Customized addons folder which is not writed in odoo.conf as it is allways read. It is a good location for your downloaded modules.
    • For RPM (Centos 7) it is /var/lib/odoo/addons/[Odoo #version]
    • For DEB (Debian 9) it is /var/lib/odoo/.local/share/Odoo/addons/[Odoo #version]

You can allways add several modules folder at you prefered locations, as long as you add those locations path in /etc/odoo/odoo.conf

Install packaged Odoo on Debian / Ubuntu / Linux Mint without python-pypdf dependency

This is a fast and easy way to install Odoo 10 official package on Debian 9 or Ubuntu 16.04 LTS server. Just create a fake python-pypdf 1.13 deb package.

Odoo 10 deb package depends on the old Python PyPdf unmaintained package. This is only a dependency problem against Python-PyPdf package. That package is no more available in several distributions, notably Debian 9 (stretch) and Ubuntu since 16.04 LTS. It is replaced by the new PyPDF2 package which claims to be fully compatible, but does not provide PyPdf  as a virtual package. The problem is the same if you want to install  Odoo 8 and Odoo 9 on recent Debian based distros.

However, there is an easy workaround : create a fake python-pdf package and install python-pyPdf from Pipy (Python repository). All of this will be done as root. There is no need to use the source Github version.

Tutorial :

  • install equivs to create fake packages and python-pip to install pypdf package from Python repository ;
  • run equivs-control python-pypdf, this will create and populate the file python-pypdf ;
  • edit the file (dot and space under Description are mandatory) like below :
    Section: python
     Package: python-pypdf
     Version: 1.13
     Description: fake package to provide python-pypdf
     This package provide the dependency needed by Odoo. 
     python-pypdf2 replace python-pypdf, but while compatible, 
     does not provide python-pypdf
     .
     python-pypdf will need to be installed with 
     "pip install pyPdf"
  • run equivs-build python-pypdf, this will create the fake package python-pypdf_1.13_all.deb ;
  • install the package with dpkg -i python-pypdf_1.13_all.deb ;
  • run pip install pyPdf ;
  • install Odoo 10 (or install the 100% free Odoo 8) on your Debian/Ubuntu box.

Your feedback will be appreciated.

Quickly done NAS with Webmin (DIY NAS)

Looking for a better NAS than the one my girlfriend own (Synology). Caveat : she don’t care about it, she understand nothing on it, I hate those slow graphical « web desktop » interfaces, I need a lot of free Ram, I want to install everything I need, I bet free/libre NAS are better.

There is three active NAS projects. They can be use on personal and small networks (but not limited to). Have a look : FreeNAS (FreeBSD), NAS4Free (derived from FreeNAS 7), and OpenMediaVault (Debian, from former FreeNAS leader). OpenFiler is for bigger needs and seems unmaintained.

FreedomBox or Yunohost (and others, look at Wikipedia) target end users. They are easy to set up and maintained. While they are not NAS project, they can, in some parts, do the job at home.

SME Server (Centos, also known as e-smith) and  Superb Mini Server (Slackware) provides something like ADSL boxes on steroids, coming with webmail and email server, virus protection, printer server, etc.

But what did I choose ? I find easier to install Debian with the Webmin control panel. I don’t really need Webmin, but as I tends to do a lot of daily work from the web browser, I keep it open in a tab. It let me do what I want, help to not forget something to configure, has a lot of modules, can report (by email) about problems and new packages, can burn CD/DVD, etc. All in all, it takes only a few minutes to install a Debian server and the webmin package — Debian is not mandatory, you can use your favorite distribution.

Installer Linux en copiant

On n’a pas toujours une distribution sous la main pour ré-installer Linux (ou tout autre Unix, comme la famille BSD) sur un disque neuf. Or c’est facile d’installer le système en se contentant de copier les fichiers depuis le disque précédent.

Branchons le nouveau disque et démarrons sur l’ancien!

Pour faire simple ici, je partitionne le nouveau disque en deux : une partition de swap et tout dans le même système de fichier. Je place la partition de swap à la fin du disque et j’active la partition du système de fichier (on la rend bootable).

Copier les fichiers

  • Créer le système de fichier et le swap sans oublier de vérifier l’état du disque (noter les UUID ou les obtenir plus tard avec lsblk -f ou blkid). Monter le système de fichiers dans /mnt.
  • Tout copier, sauf /proc /sys /dev /run et /mnt, avec ~# cp -a source /mnt/ ou bien ~# cp -a -t /mnt/ source qui est plus pratique.
  • Créer /proc /sys /dev /run et /mnt (vides)
  • Voir la doc Linux From Scratch pour le remplissage de /dev :
~# mknod -m 600 /mnt/dev/console c 5 1
~# mknod -m 666 /mnt/dev/null c 1 3
~# mount -v --bind /dev /mnt/dev
  • Refaire /mnt/etc/fstab avec les UUID, il vaut mieux éviter les /dev parce que l’ordre des périphérique pourrait changer quand on enlèvera l’ancien disque.

Installer le chargeur de démarrage (bootloader)

J’installe GRUB, la procédure est identique avec les autres. Il faut le faire depuis le nouveau système de fichier, en changeant la racine pour /mnt (chroot).

  • Monter les systèmes de fichiers virtuels :
~# mount -vt devpts devpts /mnt/dev/pts -o gid=5,mode=620
~# mount -vt proc proc /mnt/proc
~# mount -vt sysfs sysfs /mnt/sys
~# mount -vt tmpfs tmpfs /mnt/run
  • Changer la racine ~# chroot /mnt ; la racine / devient /mnt, toutes les opérations suivantes se font dans le chroot (/etc est en fait /mnt/etc, c’est transparent).
  • Modifier /etc/initramfs-tools/conf.d/resume (partition de swap pour l’hibernation) et refaire l’initramfs ~# mkinitramfs ou bien ~# update-initramfs -u sous Debian .
  • Modifier /boot/grub/grub.cfg ou utiliser grub-mkconfig (avec l’option -o et le nom du fichier de sortie, sinon ça n’en créera pas). Comme on a plusieurs disques, il vaut mieux utiliser des UUIDs plutôt que des noms de périphériques qui pourraient changer (de toute façon, GRUB ne nomme pas les périphériques comme sous Linux).
  • Installer GRUB ~# grub-install /dev/[nouveau disque]
  • Sortir du chroot, éteindre et redémarrer sur le nouveau disque.

Ou bien installer Grub une fois le système démarré

Pas facile d’avoir en tête le montage des systèmes de fichiers virtuels! On peut faire autrement, installer Grub sans chroot : il faut ajouter une entrée dans le fichier grub.cfg du disque source afin de pouvoir démarrer sur le nouveau disque (en gros, recopier l’entrée de l’ancien en changeant l’UUID). Redémarrer. Une fois démarré sur le nouveau disque, on lance ~# grub-mkconfig -o /boot/grub/grub.cfg puis ~# grub-install /dev/[nouveau disque], sans oublier de refaire l’initramfs.

Quelques usages du swap et leurs besoins

Le swap est lent par définition : c’est un espace de stockage utilisé comme de la mémoire, or le stockage est beaucoup beaucoup plus lent que la mémoire Ram. On peut quand même augmenter la vitesse du swap en faisant attention à son emplacement, sa fragmentation, sa répartition sur plusieurs disques, etc. Compliqué ? C’est pire que ça : en 2017 les ordinateurs sont équipés d’une quantité de Ram et d’espace disque qui suffisent largement aux besoins des programmes. Certains ne s’embarrassent donc plus du swap. Alors que faire ? et si on veut du swap, comment l’optimiser ?

Les prescriptions sur le swap sont anciennes. Il y a quelques années les disques durs étaient petits et lents, la mémoire se comptait en mégas, l’ordinateur mettait du temps à démarrer, les batteries des portables ne tenaient pas la route, … La situation a changé, voici donc un tableau résumant quelques usages du swap : hibernation, bouée de secours, déplacement en swap d’un programme inutilisé, besoin de libération de la mémoire Ram.

 Usage Pourquoi Pour qui Besoin
hibernation éteindre sans fermer les programmes ordi perso taille
bouée de secours ne pas planter serveur taille
programme inutilisé occupation mémoire inutile serveur
 libérer de la Ram mémoire insuffisante ordi perso vitesse

L’hibernation est un cas particulier : on enregistre l’état du système sur le disque avant l’extinction, ce qui permet au démarrage de restaurer programmes, fenêtres et documents comme si on n’avait pas éteint. Grosso-modo le processus d’hibernation transfère le contenu de la mémoire dans le swap. Il faut un swap au moins égal à la taille de la mémoire.
Dans le second cas, on veut éviter de bloquer le système si des processus consomment toute la Ram. Comme bouée de secours, la taille du swap importe plus que sa vitesse. Or les disques durs actuels ne nous limitent pas en espace. On peut donc choisir un swap égal à deux fois la taille de la Ram — ou plus ? ça dépend de ce qu’on fait tourner…
Le système peut déplacer en swap l’espace occuppé en mémoire par un programme ouvert mais qui n’est pas utilisé. Ça demande peu d’espace. L’évènement inverse étant occasionnel (réutilisation du programme), la vitesse n’est pas primordiale.
Enfin libérer de la Ram parce qu’un programme en a besoin est un usage qui diminue, mais se rencontre encore et se rencontrera probablement encore. Le système ralentit temporairement pendant que la Ram est déplacée en swap. La vitesse du swap est essentielle pour éviter les crispations devant l’écran.

Soyons clair, la vitesse du swap importe toujours et les usages énumérés se retrouvent sur toute sorte de bécane. Mais comme tout dépend de ce qu’on fait avec, on n’a pas toujours besoin de se compliquer la vie :

  • le swap sert peu sur un serveur, on peut réserver la rapidité aux données ;
  • les disques durs sont très très gros, on évite de se poser trop de question : plus de swap ne fait pas de mal, deux fois la Ram ça roule.

Recettes pour augmenter la vitesse du swap

  • Le placer entre les programmes et les données. C’est un bon compromis : la tête de lecture passera constament au-dessus. Mais attention, les données concernées ne sont pas toujours dans les dossiers personnels! en plus des images ouvertes dans Gimp et du cache du navigateur web, on peut penser aux fichiers journaux (logs), aux bases de données, aux dossiers temporaires, …
  • Le répartir sur plusieurs disques. Linux optimisera la gestion du swap (sans Linux on utilisera du Raid ou un gestionnaire de volumes logiques).

J’ai aussi lu cette idée : le placer à la périphérie du disque, au début donc, puisque la tête de lecture peut y aller très vite. Ça suppose que la tête de lecture est plus souvent parquée au bord du disque, c’est vrai. Mais quand on a besoin du swap, la tête est généralement déjà en train de faire le yoyo entre les programmes et les données ! Ne commettez pas non plus l’erreur de penser que ça écrit plus vite au bord du disque parce que « ça tourne » plus vite. N’oubliez pas que la densité d’écriture est plus faible, un secteur occuppe plus de place mais ne contient pas plus de données.

P2V tools – Physical to virtual system conversion

How to virtualize a physical computer ?

While you can find a lot of web pages and blogs asserting that you need to change some esoteric things (Windows registry and so on) in the running system before running it virtualized, fact is that it is not true :

You just need to clone the harddrive(s) in a file. End of story.

Basic disk utilities can do that (under Linux, BSD and MacOSX one can use dd), many backup tools too. Later on, you will convert the file to the desired virtualization format, which is trivial to do (tools depends on your virtual hypervisor engine).

Things are a bit more complicated if your system use several disks or partitions. But once again you just need to clone them. Several small utilities can do that for you, directly converting disks images in one file only. Under Windows, Microsoft provide the small and freely available Disk2vhd (go to the Windows Sysinternals page and download the utility) or you may prefer an automated tool like the free AOMEI Backupper. Again, many free tools exists, P2V is trivial.

How to do an Odoo inventory import

In Odoo, inventories are managed through Inventory / Inventory Control / Inventory Adjustments. Importing your stock, means creating an inventory adjustment. You will import your first stock (initial inventory), using exactly the same procedure as later stock’s imports.

Minimal prerequisites

  • At least one warehouse created (should be done automaticaly)
  • Products and variants already imported

First obvious option is to create a new Inventory Adjustment, checking the « All products » option. Then press Start Inventory button : products will be populated. You can modify stock inline in Real Quantity column. But with lots of products, you will prefer to do that in a spreadsheet :

  1. keep your first Inventory Adjustment in draft mode,
  2. go back to Inventory Adjustments, select your inventory, export it (select the required fields as the below list),
  3. update your spreadsheet and import it back.

Required fields to export / import

  • Company (company id) : company_id/id, usually « base.main_company »
    (this field should have only one record)
  • Inventoried Location (warehouse) : location_id/id, with only one warehouse it will be « stock.stock_location_stock »
    (this field should have only one record)
  • Inventory Reference (inventory name) : name, whatever
    (this field should have only one record)
  • Inventories / Product (product external id) : line_ids/product_id/id
  • Inventories / Product Name : line_ids/product_name
  • Inventories /Checked Quantity (product stock) : line_ids/product_qty

You will get also (automaticaly added) :

  • Stock inventory id (external id) : id
  • Inventories : line_ids/location_id/id

Step by step how-to import products stock in Odoo

Open a spreadsheet, populate it with your product names, product external id and product quantity — much easier to export them from Odoo ; export from product’s variants if you use them.

Rename your columns as follow :

  • Product name : line_ids/product_name
  • Product external id : line_ids/product_id/id
  • Product quantity : line_ids/product_qty

Add following columns (corresponding to field’s name) at the end. The order doesn’t matter :

  • company_id/id
    (this column will contain one record on the first line only, usually « base.main_company »)
  • location_id/id
    (this column will contain one record on the first line only, usually « stock.stock_location_stock »)
  • name
    (this column will contain one record on the first line only, put whatever you want)
  • line_ids/location_id/id
    (every line will contain the same value as the first line of location_id/id)

Save it as a CSV file. Open Odoo Inventory menu, go to Inventory Adjustment and press the Import button.

Once imported, a new entry will be created in Draft status. Open the entry and press Start Inventory. Validate the inventory if everything is ok.

 

How to export an aging inventory with Odoo

Odoo apps are well integrated. Products datas are shared accros modules, and the accounting module can « talk » very well with the inventory one. Doing everything in Odoo is easy. But sometimes you need just a spreadsheet with your past inventory at a precise date. That functionality is a bit hidden. Here’s how to enable it :

  1. install the Accounting module
  2. enable multi-location inventory
  3. switch to developper mode to see hidden menus
  4. go to Inventory / Reports / Aging inventory

To export :

Quickly done

… but product name, stock and stock value only

  1. on the right of the list view, click on Tableau Croisé dynamique
  2. now click on the download icon (xls file)

Complete nightmare

… but you may be able to export every needed field

  1. from list view unfold all products, check the checkbox
  2. click on Action / Export
  3. click on all available fields
  4. choose your fields, don’t forget inventory moves, quants and associated dates
  5. export
  6. try to play with your spreadsheet
  7. go to Quickly done