backup restore database

How to Backup & Restore Odoo Database

Odoo is a popular ERP suite used by enterprises for application building and management. While using Odoo, it is advisable to regularly backup your Odoo database. In this article, we will look at how to backup & restore Odoo database.


How to Backup & Restore Odoo Database

Here are the steps to backup & restore Odoo database.


How to Backup Odoo database

Open terminal and run the following command to easily backup your Odoo database, using curl or wget, depending on your preference. Replace ADMIN_PASSWORD with your Odoo installation’s admin password and DB_NAME with your Odoo database name.

$ 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
OR
$ 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

If you want to take backup of Odoo instance from remote server, you need to replace localhost with the URL or IP address of remote server where Odoo is installed.

Alternatively, you can open browser and visit the URL mentioned below.

http://your_server_ip:8069/web/database/manager

You will see a form where you need to enter your Odoo installation’s master password, and database name, and click Backup.

You can also automate these backup by creating a shell script to take backup and run it periodically as a cronjob. Run the following command to create an empty shell script.

$ sudo vi odoo_backup.sh

Add the following lines to it. Replace BACKUP_DIR, ODOO_DATABASE and ADMIN_PASSWORD variables according to your needs.

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

Save and close the file. Run the following command to make your shell script executable.

$ sudo chmod +x ~/backup_odoo.sh

Open Crontab file to add cronjob.

$ sudo crontab -e

Add the following line.

30 1 * * * /home/<yourusername>/odoo_backup.sh


Restore Odoo Database

Similarly, you can restore Odoo database with the following commands, using curl. Replace superadmin_passwd with your Odoo’s master password. Also update the file path to your backup zip file.

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

In case of successful restore, you will see the following 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.

Alternatively, you may open web browser and go to http://your_server_ip:8069/web/database/manager

You will see the following window. Select the backup file to restore, Enter master password and database name for restoration. Select if the database is a copy or if it was moved. Click Continue to proceed with database restoration.

That’s it. In this article, we have learnt how to backup & restore Odoo database in Ubuntu.

Also read:

How to Configure Odoo 13 with PyCharm
How to Install Odoo with Apache Reverse Proxy
How to Setup PostfixAdmin in Ubuntu
How to Completely Uninstall PostgreSQL in Ubuntu
How to Setup NTP Server & Client in Ubuntu

Leave a Reply

Your email address will not be published. Required fields are marked *