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.
rcloneStart by installing rclone, the tool we’ll use to sync with Google Drive:
sudo apt update
sudo apt install rclone -yVerify it installed correctly:
rclone versionSet up rclone to connect with your Google Drive account:
rclone configThen follow these steps:
Type n to create a new remote.
Name it something like gdrive.
Choose storage type: type 18 (Google Drive).
You can optionally enter your Google API Client ID and Secret or press enter to use the defaults.
For access scope, type 1 (full access).
Leave team drive and root folder ID blank.
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).
Check that everything works by listing directories in your Drive:
rclone lsd gdrive: You should see your folders listed.
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).
sudo chmod +x /usr/local/bin/odoo_backup.shRun the script manually:
sudo /usr/local/bin/odoo_backup.shThen verify the file appears in your Google Drive:
rclone ls gdrive:/Odoo-BackupsSchedule 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 After a test run (or next scheduled time), check the log:
cat /var/log/odoo_backup.logAlso, confirm cron ran:
grep CRON /var/log/syslog 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 now have a fully automated, off-site backup solution for your Odoo instance. Set it and forget it — your data is safe.
0
16
0