Oct 6, 2023 5 min read

How to Set up Automatic Odoo Backup

Set up Automatic Odoo Backup with our step-by-step tutorial. Odoo is a popular Python-based ERP system with PostgreSQL as the database backend.

Set up Automatic Odoo Backup
Set up Automatic Odoo Backup
Table of Contents

Introduction

Before we begin talking about how to set up automatic Odoo Backup, let's briefly understand – What is Odoo?

Odoo is the most widely used open ERP system written in Python, with PostgreSQL serving as the database backend.

Odoo is widely used open ERP with Python & PostgreSQL.

Odoo stores its data on a PostgreSQL database. Every person who has an Odoo installation must regularly back up their database in order to prevent possible catastrophic data loss.

In this tutorial, you will set up automatic Odoo Backup. We will also address a few FAQs on how to set up automatic Odoo Backup.

Odoo database management interface

The Odoo database management interface includes tools for backing up, replicating, deleting, creating, and restoring databases. The database management interface makes it simple to create a backup. All you have to do is launch your browser and go to http://your_server_ip:8069/web/database/manager.

The following display will be shown to you:

A new popup will appear once you click the Backup link.

After entering your Odoo database master password, click the blue Backup button to start a backup.

The amount of time it takes for the backup to be ready will depend on the size of the database.

Create a database backup from the command line

Now that we understand how to generate a backup using the Odoo database management interface, how can we use the same tool to create a backup from the command line? The solution is simple. Use curl or wget. We can use POST to transfer data from both tools to the Odoo database tool in order to pass the required variables to it.

In the example below, the Master Password is ADMIN_PASSWORD, and we are making a back_up_filename.zip of a database named DB_NAME, which will be saved in the backup_dirdirectory.

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

You can use the following command if you prefer wget to curl:

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

Enter the URL to your Odoo instance if you wish to create a backup from a remote location rather than localhost. It is advisable to utilize HTTPS in this case, since you do not want your password to be sent as plain text over the Internet.

More information on configuring Odoo with Nginx as a reverse-proxy may be found here.

Setup Automatic Odoo Backup

We may set up a cron job to automatically back up our Odoo database at regular intervals.

Let's assume we want to back up our Odoo database every day at 1:30 am and save the seven most recent backups.

We will develop a simple bash script that you can name however you prefer:

#!/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

Using chmod, make the script executable:

sudo chmod +x ~/backup_odoo.sh
Remember to modify the BACKUP_DIR, ODOO_DATABASE and ADMIN_PASSWORD variables as necessary.

The final step is to set up a new cron job to run every day at 1:30 am:

crontab -e
30 1 * * * /home/<yourusername>/backup_odoo.sh
Do not forget to give the backup script the proper name and location.

The script can be changed to adopt a more reliable backup strategy, such as using remote backup storage, performing weekly and monthly backups, etc.

Restore an Odoo Database

Go to http://your_server_ip:8069/web/database/manager in your browser to restore a database backup using the database management interface.

When you click the Restore Database button, a new popup window will appear.

Enter your Odoo database master password, choose the backup file, type in the new database name, and then click the blue Continue button to restore the database.

💡
You must either delete the database or use a different database name before you can restore it.

The restoration procedure could take some time, depending on the size of the database and your Internet speed.

We can also use the command line to restore the database:

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

You will need to modify the command with your Odoo Master password, the location of the database backup, and the name of the database, of course.

The output should appear as follows if the restoration is successful:

Output

!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.

FAQs to Set up Automatic Odoo Backup

Where are the backup files stored? 

By default, Odoo stores backups in the filestore directory under the Odoo server root folder. However, you can configure a different backup path or even set up cloud storage options for increased security.

Can I automate backup scheduling? 

Yes, you can schedule automated backups by creating an action with the desired backup frequency. For example, you can set up daily, weekly, or monthly backups based on your business needs.

How can I customize backup filenames? 

By modifying the backup filename format in Odoo's configuration settings, you can customize the name based on various variables such as the database name, date, time, etc. This helps in easily identifying backups.

Can I choose which databases to back up? 

Yes, you can specify which databases to include in the automated backup process. Odoo allows you to select multiple databases for backup, ensuring that critical data is protected.

What if my Odoo database is too large to back up manually? 

Odoo provides an option to perform online backups, allowing you to back up large databases without causing any downtime. This ensures the backup process is smooth and efficient.

How can I secure backup files from unauthorized access? 

To secure backup files, you can set appropriate permissions on the backup folder and files. Additionally, consider using encryption, password protection, or secure cloud storage options to enhance data security.

How can I verify the integrity of the backup files? 

One way to verify the integrity of backup files is by performing trial restorations. By restoring a backup on a separate database, you can ensure that the backup is valid and all data is intact before relying on it for disaster recovery.

Conclusion

You now understand how to create automatic daily backups of your Odoo databases using a cronjob.

If you have any queries, feel free to leave a comment below, and we'll be happy to help.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.