Table of Contents

  1. Introduction

  2. Why Backups Matter: The Real Risks

  3. Understanding Dolibarr Architecture

  4. What You Need to Backup

  5. Backup Types: Manual vs Automated

  6. Step 1: Backup the Database (MySQL/MariaDB)

  7. Step 2: Backup the Document Directory

  8. Step 3: Backup the Configuration File (conf.php)

  9. Step 4: Scheduling Automated Backups

  10. Step 5: Secure Backup Storage Practices

  11. How to Restore a Dolibarr Instance

  12. Testing Your Backup & Restore Process

  13. Common Mistakes to Avoid

  14. Final Thoughts


1. Introduction

Dolibarr ERP & CRM is a modular, open-source platform used by thousands of small to medium-sized enterprises across the globe. It handles everything from invoicing and CRM to accounting, HR, and inventory. Because Dolibarr often becomes the core system of record for many businesses, ensuring that your instance is properly backed up and recoverable is not optional—it’s essential.

In this article, we’ll walk through a detailed, step-by-step guide on how to securely back up and restore Dolibarr, using best practices that reduce the risk of data loss, corruption, or misconfiguration. Whether you’re managing your ERP in a shared hosting environment, VPS, cloud server, or on-premise setup, this guide applies to all Dolibarr deployments.


2. Why Backups Matter: The Real Risks

While Dolibarr is reliable, many external factors can disrupt your instance:

  • Server crashes or hard disk failure

  • Human error: accidental deletion of records or files

  • Software upgrades gone wrong

  • Security breaches or ransomware attacks

  • Corrupted database from improper shutdowns

  • Hosting provider outages

Without a working backup and a clear restoration plan, these events can lead to total loss of business-critical data, massive downtime, and even legal issues.

Backups aren’t just a precaution—they are an integral part of your business continuity and disaster recovery strategy.


3. Understanding Dolibarr Architecture

To properly back up and restore Dolibarr, you need to understand what makes up a complete Dolibarr installation.

A standard Dolibarr instance consists of:

  • Application files: PHP scripts in /htdocs/ (usually untouched unless customized)

  • Configuration file: conf.php in /htdocs/conf/ (contains DB connection info)

  • Document directory: /documents/ stores uploaded files (PDFs, logos, attachments)

  • Database: MySQL or MariaDB database where all records are stored

Therefore, a complete backup includes:

  • The database

  • The documents directory

  • The configuration file

  • Optionally, any custom modules or templates in /custom/ or /theme/


4. What You Need to Backup

Here’s what you need to save regularly:

Component Location Why It Matters
Database MySQL/MariaDB Contains all business data, users, invoices, stock, etc.
Document Files /dolibarr/documents/ Contains uploaded files, invoice PDFs, images
Configuration File /dolibarr/htdocs/conf/conf.php Needed to reconnect Dolibarr to its database
Custom Modules & Themes /dolibarr/htdocs/custom/ and /theme/ Preserves custom functionality
Logs (optional) /dolibarr/logs/ Helps debug problems during restore

A partial backup (e.g., database only) can be dangerous. Always ensure your backup is complete and consistent.


5. Backup Types: Manual vs Automated

You can back up Dolibarr either:

  • Manually using command-line tools or a hosting control panel

  • Automatically using scripts or tools like cron, rsync, or third-party backup services

For production environments, a hybrid approach is recommended:

  • Daily automated backups stored securely

  • Weekly manual checks to verify integrity

  • Monthly offsite backups (to external storage or cloud)

Now, let’s walk through the backup steps in detail.


6. Step 1: Backup the Database (MySQL/MariaDB)

The database is the heart of your Dolibarr system. It holds all structured data—clients, invoices, users, stock, accounting entries, and more.

6.1 Backup with mysqldump (recommended method)

Run this command via terminal or SSH:

bash

mysqldump -u your_db_user -p your_db_name > dolibarr_backup_$(date +%F).sql

Replace your_db_user and your_db_name accordingly.

You’ll be prompted for the database password. This creates a .sql file that can be used later to restore your data.

6.2 Backup with phpMyAdmin (GUI method)

If you're using a web hosting panel:

  1. Login to phpMyAdmin

  2. Select the Dolibarr database

  3. Click Export > Custom

  4. Select all tables, use SQL format

  5. Click Go to download the backup file

Best Practices:

  • Always include the DROP TABLE IF EXISTS option in exports

  • Use gzip to compress backups: gzip dolibarr_backup.sql

  • Use a timestamped filename to avoid confusion

  • Store the file outside your public web root


7. Step 2: Backup the Document Directory

Dolibarr stores uploaded documents in:

bash

/dolibarr/documents/

This directory contains:

  • Generated invoice PDFs

  • Uploaded logos, contracts, employee documents

  • Signed proposals and scanned documents

Command-line Method:

bash

tar -czvf dolibarr_documents_$(date +%F).tar.gz /path/to/dolibarr/documents

With rsync:

bash

rsync -avz /path/to/dolibarr/documents /backup/location/

Best Practices:

  • Maintain folder structure

  • Sync this folder as often as you back up the database

  • Consider encrypting archive files for sensitive content


8. Step 3: Backup the Configuration File (conf.php)

Dolibarr’s configuration file contains your database credentials and system settings.

Location:

bash

/dolibarr/htdocs/conf/conf.php

Use the following command:

bash

cp /dolibarr/htdocs/conf/conf.php /your/backup/location/conf_$(date +%F).php

Make sure it is:

  • Stored securely (not accessible from the web)

  • Backed up regularly, especially after upgrades or reconfigurations

  • Protected with appropriate permissions (chmod 640)

9. Step 4: Scheduling Automated Backups

Manual backups are useful for testing and emergency snapshots, but automated backups are what protect your data consistently. Here's how to schedule them using cron and simple shell scripts.

9.1 Create a Shell Script for Full Backup

Example: /usr/local/bin/backup_dolibarr.sh

bash

#!/bin/bash DATE=$(date +%F) BACKUP_DIR="/var/backups/dolibarr" DB_USER="dolibarr_user" DB_NAME="dolibarr_db" DB_PASS="your_password" mkdir -p $BACKUP_DIR/$DATE # Database backup mysqldump -u $DB_USER -p$DB_PASS $DB_NAME > $BACKUP_DIR/$DATE/dolibarr_db_$DATE.sql # Compress documents tar -czf $BACKUP_DIR/$DATE/documents_$DATE.tar.gz /var/www/dolibarr/documents/ # Backup conf.php cp /var/www/dolibarr/htdocs/conf/conf.php $BACKUP_DIR/$DATE/conf_$DATE.php # Optional: Compress everything into a single archive tar -czf $BACKUP_DIR/dolibarr_full_$DATE.tar.gz -C $BACKUP_DIR/$DATE . # Cleanup old backups (30 days) find $BACKUP_DIR -type f -mtime +30 -exec rm {} \;

Make the script executable:

bash

chmod +x /usr/local/bin/backup_dolibarr.sh

9.2 Add a Cron Job

Run daily at 2 AM:

bash

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

This ensures your Dolibarr instance is backed up automatically and silently, reducing human error.


10. Step 5: Secure Backup Storage Practices

Backing up is only half the job—storing backups securely is equally important.

10.1 Use Encrypted Storage

  • Encrypt backup files using gpg:

    bash

    gpg -c dolibarr_full_2025-05-15.tar.gz
  • Store passphrases securely using a password manager or secure vault

10.2 Store Backups Offsite

Always follow the 3-2-1 rule:

  • 3 copies of your data

  • On 2 different storage types

  • 1 copy offsite (e.g., cloud)

Use services like:

  • AWS S3 (with lifecycle policies)

  • Backblaze B2

  • Google Drive via rclone

  • External encrypted hard drives

10.3 Set File Permissions and Ownership

Restrict access:

bash

chmod -R 600 /var/backups/dolibarr chown -R root:root /var/backups/dolibarr

Don’t store backups in web-accessible directories.


11. How to Restore a Dolibarr Instance

If your system crashes, you’ll need to fully restore your Dolibarr environment from backup.

11.1 Restore the Database

  1. Create a new MySQL database:

    bash

    mysql -u root -p CREATE DATABASE dolibarr_db;
  2. Import your .sql backup:

    bash

    mysql -u dolibarr_user -p dolibarr_db < dolibarr_db_2025-05-15.sql

Ensure the user has proper privileges:

sql

GRANT ALL ON dolibarr_db.* TO 'dolibarr_user'@'localhost' IDENTIFIED BY 'your_password'; FLUSH PRIVILEGES;

11.2 Restore the Document Directory

Extract your archive:

bash

tar -xzf documents_2025-05-15.tar.gz -C /var/www/dolibarr/documents/

Ensure ownership and permissions:

bash

chown -R www-data:www-data /var/www/dolibarr/documents/ chmod -R 755 /var/www/dolibarr/documents/

11.3 Restore the Configuration File

Copy your backed-up conf.php:

bash

cp /backups/conf_2025-05-15.php /var/www/dolibarr/htdocs/conf/conf.php

Check database credentials and file permissions:

bash

chmod 640 conf.php chown www-data:www-data conf.php

11.4 Restart Services and Test

After restoring:

  • Restart Apache/Nginx and MySQL

  • Log in to Dolibarr

  • Check that invoices, clients, and documents are accessible

  • Verify PDF generation and module functionality


12. Testing Your Backup & Restore Process

Backups are useless if you never test them. Schedule regular test restores in a staging or local environment.

Testing Checklist:

  • Restore database and login

  • Validate recent records and documents

  • Check PDFs and reports

  • Verify cron and API endpoints

  • Confirm version compatibility after restores across versions

Simulate worst-case scenarios (e.g., server crash) to validate your disaster recovery readiness.


13. Common Mistakes to Avoid

Avoid these common pitfalls:

Mistake Impact
Backing up database only Loss of document attachments and config
Storing backups in /htdocs/ Exposes sensitive files to the internet
Skipping encryption Risk of data leaks in the event of theft
Forgetting to test backups You won’t know they’re broken until it’s too late
Not automating backups Increased human error and gaps in protection
Not versioning custom modules Lost changes after upgrade or restore
Overwriting live data during test restores Permanent data loss

Always treat backups as part of your production system, not an afterthought.


14. Final Thoughts

A solid backup and restore strategy is the cornerstone of any Dolibarr deployment—regardless of your company size or industry. Whether you’re running a small accounting firm, an e-commerce business, or a logistics company, your ERP system is too critical to be left vulnerable to data loss.

By following the steps outlined in this article, you’ll achieve:

  • Full control over your data

  • Faster recovery after failures or upgrades

  • Peace of mind knowing your system is safe

  • Regulatory compliance with data retention policies

Remember: it’s not a question of if something will go wrong, but when. With automated, secure, and regularly tested backups in place, your Dolibarr instance will be resilient and dependable—just as your business needs it to be.