How to Set Up Automatic Dolibarr Backups to Google Drive: A Complete Step-by-Step Guide for SMEs
   05/13/2025 00:00:00     Dolibarr , Wiki Dolibarr    0 Comments
How to Set Up Automatic Dolibarr Backups to Google Drive: A Complete Step-by-Step Guide for SMEs

When managing your business with Dolibarr ERP & CRM, one of the most essential, yet often overlooked, tasks is setting up a robust backup strategy. Data loss can occur unexpectedly due to hardware failure, human error, or malicious attacks. That’s why implementing automatic backups—and storing them off-site in a reliable, secure location like Google Drive—is a best practice for any small or medium-sized business using Dolibarr.

In this comprehensive guide, we’ll walk through everything you need to know to configure automated backups of your Dolibarr instance to Google Drive. We'll cover the technical requirements, backup types, scripting methods, scheduling using cron, security considerations, and verification best practices. Whether you self-host Dolibarr or use a VPS, this guide will help you protect your data with confidence.

Why Google Drive?

Google Drive offers free and paid cloud storage with high availability, easy accessibility, and built-in versioning. It integrates well with automated tools via API and is a logical off-site destination for storing daily or weekly backups of Dolibarr databases and document directories.

Benefits include:

  • Free 15 GB cloud storage (expandable via Google One)

  • Highly available and redundant infrastructure

  • Secure and encrypted file transfer (HTTPS)

  • Integration via Google Drive API and OAuth2

For non-technical users, Google Drive also provides a simple interface for downloading, restoring, or checking backup history.

What Should You Back Up in Dolibarr?

Dolibarr’s data consists of two major components:

  1. Database: All your business data—customers, invoices, products, users, permissions, etc.—reside in the MySQL or MariaDB database.

  2. Documents Directory: Stored files, such as PDF invoices, user-uploaded contracts, and logos, are stored in Dolibarr’s /documents directory.

To ensure full recovery capability, you need to back up both components regularly.

Step 1: Prepare Your Environment

Before diving into scripting and scheduling, ensure the following:

  • You have SSH access to your Dolibarr server (VPS, dedicated, or local machine).

  • You have mysqldump installed for database backups.

  • rclone is installed to handle Google Drive uploads.

  • A Google account with Drive access is available.

If not already installed, you can install rclone on Debian/Ubuntu with:

sudo apt update
sudo apt install rclone

Step 2: Configure Rclone with Google Drive

Rclone is a command-line tool to manage files on cloud storage. It supports Google Drive natively.

Run the configuration wizard:

rclone config

Steps in the wizard:

  1. Choose n for a new remote.

  2. Name it (e.g., gdrive).

  3. Choose Google Drive as the storage type.

  4. Follow the OAuth flow—rclone will open a URL. Log in with your Google account and paste the code back.

  5. Choose default settings unless advanced needs apply.

  6. Save and exit.

Verify it works:

rclone ls gdrive:

This should list your Drive files.

Step 3: Write the Backup Script

Create a bash script, e.g., dolibarr-backup.sh:

#!/bin/bash
DATE=$(date +%F-%H-%M)
BACKUP_DIR="/var/backups/dolibarr"
DB_NAME="dolibarr"
DB_USER="root"
DB_PASS="your_db_password"
DOC_DIR="/var/www/dolibarr/documents"
BACKUP_TMP="/tmp/dolibarr-backup-$DATE"
REMOTE="gdrive:dolibarr-backups"

mkdir -p $BACKUP_TMP
mkdir -p $BACKUP_DIR

# Dump database
mysqldump -u$DB_USER -p$DB_PASS $DB_NAME > $BACKUP_TMP/db-$DATE.sql

# Archive documents
tar -czf $BACKUP_TMP/documents-$DATE.tar.gz -C $DOC_DIR .

# Create a zip with both
cd $BACKUP_TMP
zip -r $BACKUP_DIR/dolibarr-backup-$DATE.zip *

# Upload to Google Drive
rclone copy $BACKUP_DIR/dolibarr-backup-$DATE.zip $REMOTE

# Cleanup
rm -rf $BACKUP_TMP

Make the script executable:

chmod +x dolibarr-backup.sh

Step 4: Schedule with Cron

Automate the script to run daily, weekly, or at a frequency of your choice.

Edit crontab:

crontab -e

Add an entry, e.g., for daily backups at 2 AM:

0 2 * * * /path/to/dolibarr-backup.sh >> /var/log/dolibarr-backup.log 2>&1

Step 5: Monitor and Verify Backups

Even automated backups must be validated.

  • Check /var/log/dolibarr-backup.log for errors.

  • Log into Google Drive and verify files are uploaded.

  • Test restore periodically:

    • Restore the database using mysql.

    • Extract the documents archive and compare with production.

Optional: Send backup completion alerts via email using mailx or integrate with Slack.

Step 6: Rotate and Prune Old Backups

To avoid filling up your Google Drive:

Add cleanup to your script to keep only the last 7 backups:

rclone lsjson $REMOTE | jq -r '.[].Name' | sort | head -n -7 | while read file; do
  rclone deletefile $REMOTE/$file
done

You can also use rclone filters or move old backups to an “archive” folder.

Security Tips

  • Protect credentials: Store DB password in a root-only readable file, or use .my.cnf.

  • Use service accounts: For shared Google Drive use cases.

  • Encrypt backups: Use gpg or zip -e to encrypt sensitive backups.

  • Use secure storage: Always store on a drive with limited access.

Additional Enhancements

  • Integrate with Nextcloud, Dropbox, or S3 using rclone.

  • Create Telegram bots for daily backup status.

  • Visualize backup history with a Grafana dashboard (via logs).

  • Set up alerts for failed cron jobs with health checks.

Common Issues and Troubleshooting

Issue: Rclone fails to connect

  • Cause: OAuth token expired or invalid.

  • Fix: Run rclone config reconnect gdrive: to refresh credentials.

Issue: Mysqldump permission denied

  • Cause: Wrong DB user or permissions.

  • Fix: Check user access and password.

Issue: Cron job doesn’t run

  • Cause: Wrong path or environment.

  • Fix: Use absolute paths and export needed variables.

Issue: Google Drive quota exceeded

  • Fix: Clean old backups, compress better, or upgrade plan.

Why SMEs Must Take Backup Seriously

Small and medium-sized businesses often lack dedicated IT teams, making automated backup strategies critical. Losing access to customer data, invoices, or project files—even for a day—can cost revenue, damage reputation, or even violate compliance obligations.

A well-implemented backup strategy is your insurance against disaster. By leveraging Dolibarr’s modular architecture, open tools like rclone, and cloud platforms like Google Drive, even non-technical businesses can set up a professional-grade backup process.

Final Thoughts

Configuring automatic backups from Dolibarr to Google Drive is a straightforward but powerful safeguard. Once set up, it runs silently in the background, giving you peace of mind. And because it’s built with open standards, you can adapt it as your infrastructure grows.

Whether you run a freelance operation, a logistics business, or a 50-person service agency, don’t wait until disaster strikes. Back up your Dolibarr—automatically, securely, and regularly. It could save your business.

Comments

Log in or register to post comments