In my previous article I have discussed how to backup and restore a large odoo database, by modifying the odoo controller. After some time using this method in several projects, it turns out that this method has weaknesses. Sometimes the backup file cannot be restored. The backup file seems to be corrupt, so it failed when we restore it on another server. I still don’t know what causes this problem.
Some time ago I posted the above article on twitter, and got some feedbacks. One of them is information about a library that can be used to backup and restore the odoo database via the command line, which is worth trying.
I would like to thank Laurent Mignon for providing information about a library to backup and restore the odoo database via the command line.
In order to use the library above, we must install it first. Type the command below on the terminal/command line.
sudo pip3 install click-odoo-contrib
Important!!!
Depending on how you install odoo, you may not be able to use this library on your server. As far as I know, if we install odoo with a .deb file this library can be used smoothly. But if we install odoo with Yenthe666/InstallScript this library cannot be used. My conclusion so far is, if the odoo files and folders are located in the python library folder (/usr/lib/python3/dist-packages) this library can be used, otherwise, it doesn’t. I haven’t tried this library on any other odoo installation method, other than the 2 methods above.
To backup the database we can use the command like in the library documentation on github. But I don’t recommend you to backup the database in zip format. Because after I tried it, the process took a long time. Based on my experience, when I backed up the database with a size of 1.2GB and used the zip format, the process was still not finished after I waited for more than 3 hours. Meanwhile, if I change the format to folder the backup process can be completed within 1 hour 30 minutes.
This is the command how to backup a database with the name of my_database to be saved as a new folder with the name of my_database_backup in the /home/ngasturi/Documents folder assuming the odoo configuration file is located in /etc/odoo/odoo.conf.
click-odoo-backupdb -c /etc/odoo/odoo.conf --format folder my_database /home/ngasturi/Documents/my_database_backup
The result will look like in the image below.
This is the command how to restore the backup folder above into a new database with the name of my_restored_database.
click-odoo-restoredb -c /etc/odoo/odoo.conf my_restored_database /home/ngasturi/Documents/my_database_backup
Unfortunately, when we restore the backup folder, its content, the filestore folder will be moved (cut) to the odoo filestore location, so we can’t perform the restore process a second time. Therefore, before you perform the restore process, I recommend you to back up the folder.
I have tried to compress the backup folder into a .zip file but the result can’t be restored. The contents of the backup results with the folder format are different from the contents of the backup results with the zip format.
It is my review and experience about this library. So far I’m still testing this library, and still haven’t used it much in the projects I’m working on, so I’m still not sure if this library can solve the problem in the first method or not.
If you have any other impressions about this library or know a better library out there, I would be happy if you can share with us by using the comments feature below.