Mark Kaharo

Jul 07, 2025 • 3 min read

🎯 Automating Odoo Backups to Google Drive (on Debian 11)

Keeping regular backups of your Odoo database is non-negotiable. In this guide, I’ll walk you through setting up automatic backups of your Odoo database and filestore and syncing them to Google Drive using rclone.


🔧 Step 1: Install rclone

Start by installing rclone, the tool we’ll use to sync with Google Drive:

sudo apt update
sudo apt install rclone -y

Verify it installed correctly:

rclone version

🔐 Step 2: Configure Google Drive as a Remote

Set up rclone to connect with your Google Drive account:

rclone config

Then follow these steps:

  1. Type n to create a new remote.

  2. Name it something like gdrive.

  3. Choose storage type: type 18 (Google Drive).

  4. You can optionally enter your Google API Client ID and Secret or press enter to use the defaults.

  5. For access scope, type 1 (full access).

  6. Leave team drive and root folder ID blank.

  7. If you’re on a headless server, run this on a local machine:

    rclone authorize "drive"

    Paste the resulting token back into your server prompt.

Once done, confirm and quit the config (y, then q).


✅ Step 3: Test the Connection

Check that everything works by listing directories in your Drive:

rclone lsd gdrive: 

You should see your folders listed.


📝 Step 4: Write the Backup Script

Create a backup script that dumps your Odoo DB, zips it with the filestore, and pushes it to Google Drive.

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

Paste this:

#!/bin/bash

set -euo pipefail

# Configuration
ODOO_DB="DATABASE_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"  # Change if needed
GDRIVE_FOLDER="Odoo-Backups/$ODOO_DB/$DATE"

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

# Fix locale warnings
export LANG=en_GB.UTF-8
export LC_ALL=en_GB.UTF-8

echo "📦 Starting backup for database: $ODOO_DB at $DATE"

# Step 1: Backup Odoo database (uncompressed .sql)
DUMP_PATH="$BACKUP_DIR/dump.sql"
if ! sudo -u postgres pg_dump "$ODOO_DB" > "$DUMP_PATH"; then
    echo "❌ Database backup failed!"
    exit 1
fi
echo "✅ Database dump completed: $DUMP_PATH"

# Step 2: Prepare temp structure for zipping
TEMP_DIR=$(mktemp -d)
cp "$DUMP_PATH" "$TEMP_DIR/"
mkdir -p "$TEMP_DIR/filestore"
cp -r "/var/lib/odoo/filestore/$ODOO_DB" "$TEMP_DIR/filestore/"
echo "📁 Files prepared in temp directory: $TEMP_DIR"

# Step 3: Create zip file
cd "$TEMP_DIR"
if ! zip -r "$BACKUP_FILE" dump.sql filestore/ > /dev/null; then
    echo "❌ ZIP creation failed!"
    rm -rf "$TEMP_DIR"
    exit 1
fi
echo "✅ Backup zipped: $BACKUP_FILE"

# Step 4: Cleanup local temp files
rm -rf "$TEMP_DIR"
rm -f "$DUMP_PATH"
echo "🧹 Temp files cleaned up"

# Step 5: Upload to Google Drive via rclone
if ! sudo -u blackpaw rclone copy "$BACKUP_FILE" "$RCLONE_REMOTE:$GDRIVE_FOLDER" --quiet; then
    echo "❌ Upload to Google Drive failed!"
    exit 1
fi
echo "☁️  Backup uploaded to Google Drive: $RCLONE_REMOTE:$GDRIVE_FOLDER"

echo "✅ Backup process completed successfully!"

Save and close (CTRL+X, Y, Enter).


🔓 Step 5: Make the Script Executable

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

🔁 Step 6: Test the Backup

Run the script manually:

sudo /usr/local/bin/odoo_backup.sh

Then verify the file appears in your Google Drive:

rclone ls gdrive:/Odoo-Backups

⏰ Step 7: Automate with Cron

Schedule daily backups at 2 AM:

sudo crontab -e 

Add this line:

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

📋 Step 8: Verify Cron is Working

After a test run (or next scheduled time), check the log:

cat /var/log/odoo_backup.log

Also, confirm cron ran:

grep CRON /var/log/syslog 

✅ Final Checklist

  • rclone is configured with Google Drive

  • The backup script is tested and working

  • Cron job is set for automation

  • Backups appear in Google Drive under /Odoo-Backups


🚀 You're Done!

You now have a fully automated, off-site backup solution for your Odoo instance. Set it and forget it — your data is safe.

Join Mark on Peerlist!

Join amazing folks like Mark and thousands of other builders on Peerlist.

peerlist.io/

It’s available... this username is available! 😃

Claim your username before it's too late!

This username is already taken, you’re a little late.😐

0

16

0