Skip to Content

Automating Odoo Backups: How We Did It & How You Can Too

Avoid Losing Your Clients' Data by Automating Your Back Ups.

Odoo is a powerful business management tool, but without a solid backup strategy, your data is at risk. Losing critical data due to accidental deletion, system failures, or cyberattacks can set your business back significantly. That's why we developed a seamless Odoo backup and cleanup automation process—ensuring data security while eliminating manual effort. Here’s a step-by-step breakdown of how we did it and how you can implement a similar solution.

This automation has been designed for Odoo Community.

Odoo Community Backup Automation: Why is it Crucial?

Manual backups are time-consuming and prone to human error. By automating the process, you: 

✅ Ensure daily backups without fail. 

✅ Secure data in the cloud (Google Drive, in our case). 

✅ Free up local storage with automated old backup deletion. 

✅ Reduce administrative overhead and focus on core tasks.

We designed a solution that automatically backs up Odoo databases and file storage, uploads them to Google Drive, and removes outdated backups—all running in the background.

Step 1: Setting Up rclone for Cloud Backups

To transfer backups to Google Drive, we use rclone, a command-line tool that syncs files between different storage locations. Here’s how to set it up:

Install rclone on Debian 11

sudo apt update
sudo apt install rclone -y

Verify installation:

rclone version

Configure rclone for Google Drive

Run:

rclone config
  • Create a new remote (n for new remote).
  • Name it gdrive (or any name you prefer).
  • Select Google Drive (option 13).
  • Authenticate by following the on-screen instructions.

Test the connection:

rclone lsd gdrive:

If the setup is successful, you should see your Google Drive directories.

Step 2: Creating the Odoo Backup Script

The core of our solution is a script that: 

✅ Exports the Odoo database. 

✅ Compresses the database and file store into a single archive. 

✅ Uploads the archive to Google Drive. 

✅ Deletes backups older than 7 days.

Create a backup script

sudo nano /usr/local/bin/odoo_backup.sh

Paste the following script (customized for your Odoo instance):

#!/bin/bash

# Configuration
ODOO_DB="your_odoo_db_name"
BACKUP_DIR="/var/backups/odoo"
DATE=$(date +'%Y-%m-%d_%H-%M-%S')
BACKUP_FILE="$BACKUP_DIR/odoo_backup_$DATE.zip"
RCLONE_REMOTE="gdrive"  # Ensure this matches your rclone remote name

# Ensure backup directory exists
mkdir -p $BACKUP_DIR
chown postgres:postgres $BACKUP_DIR
chmod 755 $BACKUP_DIR

# Backup Odoo database
sudo -u postgres bash -c "pg_dump $ODOO_DB | gzip > '$BACKUP_DIR/$ODOO_DB-$DATE.sql.gz'"

# Compress the database and filestore
zip -r "$BACKUP_FILE" /var/lib/odoo $BACKUP_DIR/$ODOO_DB-$DATE.sql.gz

# Upload backup to Google Drive
rclone copy "$BACKUP_FILE" "$RCLONE_REMOTE:/Odoo-Backups"

# Clean up old backups (keep last 7 backups)
find $BACKUP_DIR -type f -mtime +7 -delete

Save and exit (CTRL + X, then Y, then ENTER).

Make it executable:

sudo chmod +x /usr/local/bin/odoo_backup.sh

Test the script:

sudo /usr/local/bin/odoo_backup.sh

Verify the backup is in Google Drive:

rclone ls gdrive:/Odoo-Backups

Step 3: Automating Backups with Cron Jobs

To run the backup script automatically every day at 2 AM, add it to the cron scheduler:

sudo crontab -e

At the bottom, add:

0 2 * * * /usr/local/bin/odoo_backup.sh >> /var/log/odoo_backup.log 2>&1

This ensures logs are recorded for debugging purposes.

To verify execution:

cat /var/log/odoo_backup.log

Step 4: Deleting Old Backups Automatically

Keeping unnecessary backups takes up valuable space. We implemented a cleanup script to remove old backup folders in Google Drive after 1 day.

Automating Backup Cleanup

Using Google Apps Script, we wrote a function that: ✅ Scans the backup directory in Google Drive. ✅ Identifies backup folders older than 1 day. ✅ Moves them to trash.

Here's a snippet of our cleanup script:

function deleteOldBackupFolders() {
  var odooBackupsFolderId = "YOUR_FOLDER_ID_HERE";
  var odooBackupsFolder = DriveApp.getFolderById(odooBackupsFolderId);
  
  var subfolders = odooBackupsFolder.getFolders();
  var now = new Date();
  now.setDate(now.getDate() - 1);
  
  while (subfolders.hasNext()) {
    var subfolder = subfolders.next();
    var folderName = subfolder.getName();
    var match = folderName.match(/^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}$/);
    if (match) {
      var folderDate = new Date(match[1]);
      if (folderDate < now) {
        subfolder.setTrashed(true);
      }
    }
  }
}

This runs on a scheduled trigger in Google Apps Script, keeping storage optimized.

Final Checklist: Ensuring Your Backup System Works

rclone is installed and configured. 

Backup script runs successfully. 

Cron job executes daily at 2 AM. 

Backups upload to Google Drive automatically. 

Old backups are deleted to free up storage.

With this automation, your Odoo instance remains secure without manual intervention.

Need Help Setting This Up?

We’ve designed and tested this backup system extensively. If you need a similar setup—or want custom backup solutions tailored to your needs—reach out to us. Let’s ensure your Odoo data is safe, automated, and hassle-free.

Schedule Free Consultation

 

Automating Odoo Backups: How We Did It & How You Can Too
Blackpaw Innovations April 10, 2025
Share this post
Archive
Combine Your Payroll, eTims, and M-Pesa Accounts into One Powerful System
Odoo Finance Enhances Accounting for Entrepreneurs with Seamless Payroll, eTims, and M-Pesa Integration