YouTube Icon

Code Playground.

How to Setup Automatic Odoo Backup

CFG

How to Setup Automatic Odoo Backup

In this instructional exercise we will walk you through the way toward making programmed every day reinforcements of your Odoo information bases. Odoo is the most famous open-source ERP framework written in Python and utilizations PostgreSQL as information base back-end. 

Odoo is putting away its information in a PostgreSQL information base. Consistently backing up the information base will shield you from possibly calamitous information misfortune and it is totally basic for anybody and each and every individual who has an Odoo establishment. 

Odoo database management interface

The Odoo information base administration interface gives instruments to reinforcement, copy, erase, make and reestablish a data set. Making a reinforcement utilizing the information base administration interface is an easy decision. Basically open your program and explore to http://your_server_ip:8069/web/information base/director. 

You will be given the accompanying screen: 

information base administrator 

Snap on the Backup connect and another popup will be shown. 

information base administrator reinforcement 

Enter your Odoo information base Master Password and make a reinforcement by tapping on the blue Backup button. 

Contingent upon the information base size, the reinforcement may take some time prior to being prepared. 

Create a database backup from the command line

Since we realize how to make a reinforcement through the Odoo information base administration interface, how might we utilize a similar device to make a reinforcement from the order line? The appropriate response is basic. Use wget or twist . The two devices can send information with POST which we can use to pass the important factors to the Odoo information base instrument. 

In the model underneath our the Master Password is ADMIN_PASSWORD and we are making a reinforcement record back_up_filename.zip of an information base named DB_NAME which will be saved in the backup_dir index. 

curl -X POST -F 'master_pwd=ADMIN_PASSWORD' -F 'name=DB_NAME' -F 'backup_format=zip' -o /backup_dir/back_up_filename.zip http://localhost:8069/web/database/backup

In the event that you incline toward wget over twist, you can utilize the accompanying order: 

wget --post-data 'master_pwd=ADMIN_PASSWORD&name=DB_NAME&backup_format=zip' -O /backup_dir/back_up_filename.zip http://localhost:8069/web/database/backup

On the off chance that you need to make a reinforcement from a distant area rather than localhost you need to enter the URL to your Odoo occasion. For this situation it is prescribed to utilize HTTPS since you don't need your secret phrase to be send through Internet as a plain content. 

You can discover more data about how to arrange Odoo with Nginx as a converse intermediary here . 

Setup Automatic Odoo Backup

To mechanize the reinforcement cycle and reinforcement our Odoo information base at normal spans we can make a cron work . 

Suppose that we need to reinforcement our Odoo information base every day at 01:30 am and keep the most recent 7 reinforcements. 

We will make a basic slam content which you can name it as you need: 

~/backup_odoo.sh

#!/bin/bash

# vars
BACKUP_DIR=~/odoo_backups
ODOO_DATABASE=db1
ADMIN_PASSWORD=superadmin_passwd

# create a backup directory
mkdir -p ${BACKUP_DIR}

# create a backup
curl -X POST \
    -F "master_pwd=${ADMIN_PASSWORD}" \
    -F "name=${ODOO_DATABASE}" \
    -F "backup_format=zip" \
    -o ${BACKUP_DIR}/${ODOO_DATABASE}.$(date +%F).zip \
    http://localhost:8069/web/database/backup


# delete old backups
find ${BACKUP_DIR} -type f -mtime +7 -name "${ODOO_DATABASE}.*.zip" -delete

Make the content executable with chmod : 

sudo chmod +x ~/backup_odoo.sh

Remember to change the BACKUP_DIR, ODOO_DATABASE and ADMIN_PASSWORD factors as per your requirements. 

The last advance is to make another cron work which will run every day at 01:30 am: 

crontab -e
30 1 * * * /home/<yourusername>/backup_odoo.sh

Remember to set the right name and way to the reinforcement content. 

You can alter the content and actualize a more strong reinforcement arrangement, for example, utilizing a distant reinforcement stockpiling, keep week after week and month to month reinforcements ..and so on 

Restore an Odoo Database

To reestablish an information base reinforcement utilizing the data set administration interface, open your program and explore to http://your_server_ip:8069/web/information base/supervisor. 

information base director 

Snap on the Restore Database button and another popup will be shown. 

information base administrator reestablish 

Enter your Odoo information base Master Password, select the reinforcement File, enter the new Database Name and reestablish the data set by tapping on the blue Continue button. 

Prior to reestablishing the information base you should either erase the data set or utilize another data set name. 

Contingent upon the information base size and your Internet speed, the reclamation cycle may take some time. 

We can likewise reestablish the information base from the order line: 

curl -F 'master_pwd=superadmin_passwd' -F backup_file=@/opt/odoo/odoo_backups/db1.2018-04-14.zip -F 'copy=true' -F 'name=db3' http://localhost:8069/web/database/restore

Obviously you should change the order with your Odoo Master secret phrase, the way to the information base reinforcement and the information base name. 

On the off chance that the rebuilding is fruitful the yield should resemble this: 

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>Redirecting...</title>
<h1>Redirecting...</h1>
<p>You should be redirected automatically to target URL: <a href="/web/database/manager">/web/database/manager</a>.  If not click the link.

Conclusion

This instructional exercise strolled you through making programmed day by day reinforcements of your Odoo information bases utilizing a cronjob. 

On the off chance that you have any inquiries or criticism, don't hesitate to leave a remark.




CFG