Creating regular backups of your Odoo database is a fundamental part of managing an ERP system. Data loss can have serious consequences for how a company operates, so every administrator should know proven backup methods. In this article we present a comprehensive guide to backing up Odoo, compatible with the latest versions of the system.
Why is an Odoo database backup essential?
Odoo stores all of your company's key data - from customer information, orders and invoices to HR and warehouse data. Regularly backing up your Odoo database protects you against:
- Server hardware failures and data loss
- Human errors during configuration or data entry
- Ransomware attacks and other cybersecurity threats
- Data corruption during system updates
- Accidental deletion of critical information by users
- Problems with external integrations causing data corruption
A well-planned backup strategy lets you quickly restore the system after a failure, minimizing business downtime and potential financial losses.
Method 1: Backup via the Odoo web interface
The simplest way to back up an Odoo database is to use the built-in tool available through a web browser. Note: In production environments, access to the database manager should be protected or disabled entirely for security reasons.
Step by step - backup via the web interface
1. Accessing the database manager
Depending on your Odoo version, go to: http://twoja-domena.pl/web/database/selector or http://twoja-domena.pl/web/database/manager. Alternatively, you can click the "Manage Databases" link on the login screen (if available).
2. Authentication
Enter the master password (admin_passwd) that was set in the odoo.conf configuration file. Important: In newer Odoo versions (16+), if the master password is not set, access to the database manager is blocked by default for security. If you do not know this password, see the odoo.conf configuration guide.
3. Choosing the backup option
Select the database you want to back up and click the "Backup" button. You can also set a password to encrypt the backup (optional, but recommended).
4. Downloading the file
The system will generate an archive file (usually .zip or .dump) containing the PostgreSQL database dump and the filestore directory with attachments. The file will be downloaded to your computer automatically. In newer Odoo versions, the backup may be in PostgreSQL custom format with the files attached.
Advantages and disadvantages of the web method
Advantages:
- Does not require SSH access to the server
- Intuitive and quick to perform for non-technical users
- Includes a full backup together with the filestore files
- May include the option to encrypt the backup with a password
Disadvantages:
- Cannot be automated without additional tools
- Requires manual intervention every time
- Can be problematic for large databases (browser or server timeout)
- Is a potential security risk if access is not properly protected
- In production environments, access should be disabled
Method 2: Backup via the command line (PostgreSQL)
For administrators with SSH access to the server, using PostgreSQL tools directly offers greater control, automation options and better performance with large databases.
Creating a PostgreSQL database dump
The basic command for backing up an Odoo database in custom format (recommended):
sudo -u postgres pg_dump -d nazwa_bazy_odoo -F c -b -v -f /ścieżka/backup/odoo_backup_$(date +%Y%m%d_%H%M%S).dump
Where:
-d nazwa_bazy_odoo- the name of the database to back up-F c- custom format (recommended, allows compression and selective restore)-b- includes large objects (important for Odoo)-v- verbose mode (detailed output)-f- path to the output file$(date +%Y%m%d_%H%M%S)- adds a timestamp to the file name
Backup in SQL (text) format
Alternatively, you can create a backup in SQL format, which is human-readable:
sudo -u postgres pg_dump nazwa_bazy_odoo | gzip > /backup/odoo_$(date +%Y%m%d).sql.gz
This method creates a compressed SQL file that can be edited in a text editor, but it takes up more space than the custom format and restoring is slower.
Filestore backup (a key element!)
Remember that backing up the database alone is not enough. You must also secure the filestore directory containing attachments, product images, documents and other files uploaded by users:
sudo tar -czf /backup/odoo_filestore_$(date +%Y%m%d).tar.gz -C /home/odoo/.local/share/Odoo/filestore nazwa_bazy
Note: The filestore location may differ depending on the installation. Typical locations are:
/home/odoo/.local/share/Odoo/filestore//var/lib/odoo/.local/share/Odoo/filestore/~/.local/share/Odoo/filestore/(for the odoo user)
Check the actual location in your odoo.conf file, in the data_dir parameter.
Method 3: Automating backups with cron
The best practice is to automate the backup process. This way you do not have to remember to run backups regularly, and the system works reliably without human intervention.
Creating a backup script
Create a bash script file with extended error handling and logging:
sudo nano /usr/local/bin/odoo-backup.sh
Script contents (updated version with error handling):
#!/bin/bash
# Configuration
DB_NAME="nazwa_bazy_odoo"
BACKUP_DIR="/var/backups/odoo"
FILESTORE_DIR="/home/odoo/.local/share/Odoo/filestore/$DB_NAME"
RETENTION_DAYS=30
DATE=$(date +%Y%m%d_%H%M%S)
LOG_FILE="/var/log/odoo-backup.log"
# Logging function
log_message() {
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1" >> $LOG_FILE
}
# Check whether the backup directory exists
if [ ! -d "$BACKUP_DIR" ]; then
mkdir -p $BACKUP_DIR
if [ $? -ne 0 ]; then
log_message "ERROR: Cannot create backup directory $BACKUP_DIR"
exit 1
fi
fi
log_message "INFO: Starting backup process for database $DB_NAME"
# Database backup
sudo -u postgres pg_dump -d $DB_NAME -F c -b -v -f $BACKUP_DIR/db_${DB_NAME}_${DATE}.dump 2>> $LOG_FILE
if [ $? -eq 0 ]; then
log_message "INFO: Database backup completed successfully"
else
log_message "ERROR: Database backup failed"
exit 1
fi
# Filestore backup
if [ -d "$FILESTORE_DIR" ]; then
tar -czf $BACKUP_DIR/filestore_${DB_NAME}_${DATE}.tar.gz -C $(dirname $FILESTORE_DIR) $(basename $FILESTORE_DIR) 2>> $LOG_FILE
if [ $? -eq 0 ]; then
log_message "INFO: Filestore backup completed successfully"
else
log_message "ERROR: Filestore backup failed"
exit 1
fi
else
log_message "WARNING: Filestore directory does not exist: $FILESTORE_DIR"
fi
# Backup size verification
DB_SIZE=$(du -h $BACKUP_DIR/db_${DB_NAME}_${DATE}.dump | cut -f1)
log_message "INFO: Database backup size: $DB_SIZE"
# Removing old backups
log_message "INFO: Removing backups older than $RETENTION_DAYS days"
find $BACKUP_DIR -name "*.dump" -type f -mtime +$RETENTION_DAYS -delete
find $BACKUP_DIR -name "*.tar.gz" -type f -mtime +$RETENTION_DAYS -delete
log_message "INFO: Backup completed successfully: $DATE"
# Optional: send an email notification
# echo "Odoo backup completed successfully. Date: $DATE, Size: $DB_SIZE" | mail -s "Odoo Backup OK" admin@firma.pl
exit 0
Grant execute permission:
sudo chmod +x /usr/local/bin/odoo-backup.sh
Test the script manually before adding it to cron:
sudo /usr/local/bin/odoo-backup.sh
Configuring the cron job
Add a cron job to run the backup automatically. Depending on your needs, you can run it as root or as the odoo user:
sudo crontab -e
Example cron entries:
# Every day at 2:00 AM (recommended for most companies)
0 2 * * * /usr/local/bin/odoo-backup.sh >> /var/log/odoo-backup.log 2>&1
# Every 6 hours (for heavily used systems)
0 */6 * * * /usr/local/bin/odoo-backup.sh >> /var/log/odoo-backup.log 2>&1
# Every day at 2:00 AM with an email notification on failure
0 2 * * * /usr/local/bin/odoo-backup.sh || echo "Backup failed" | mail -s "ALERT: Odoo Backup Failed" admin@firma.pl
Check whether cron is active:
sudo systemctl status cron
Restoring an Odoo backup
The ability to restore data is just as important as backing it up. Here is how to safely restore an Odoo database.
Restoring via the web interface
Note: Before restoring, make sure you have enough disk space and that the process will not be interrupted.
1. Go to the database manager: /web/database/selector or /web/database/manager
2. Enter the master password
3. Select the "Restore Database" option
4. Upload the backup file (it can be a .zip or .dump file)
5. Enter a name for the restored database (it can differ from the original)
6. If the backup was encrypted, enter the password
7. Click "Restore" and wait for the process to finish
8. When it finishes, you will be redirected to the login screen of the new database
Restoring via the command line (recommended for large databases)
Important: Before restoring the database, stop the Odoo service to avoid conflicts:
sudo systemctl stop odoo
Restoring a PostgreSQL database:
# 1. Create a new database (template0 ensures a clean database)
sudo -u postgres createdb -T template0 nazwa_nowej_bazy
# 2. Restore the data from the dump (custom format)
sudo -u postgres pg_restore -d nazwa_nowej_bazy --no-owner --role=odoo /ścieżka/do/backup.dump
# Alternatively, for an SQL file:
# gunzip -c /backup/odoo_backup.sql.gz | sudo -u postgres psql nazwa_nowej_bazy
# 3. Restore the filestore to the correct location
sudo mkdir -p /home/odoo/.local/share/Odoo/filestore/nazwa_nowej_bazy
sudo tar -xzf /backup/filestore_backup.tar.gz -C /home/odoo/.local/share/Odoo/filestore/
# 4. Set the correct permissions
sudo chown -R odoo:odoo /home/odoo/.local/share/Odoo/filestore/nazwa_nowej_bazy
# 5. Restart the Odoo service
sudo systemctl start odoo
After restoring the database, check the Odoo logs to make sure the system started correctly:
sudo tail -f /var/log/odoo/odoo.log
If you use systemd to manage the Odoo service, see how to properly manage the Odoo service.
Testing the restored database
After restoring, run some basic tests:
- Log in to the system and check that the data is available
- Check that attachments are accessible
- Verify reports and printouts
- Test key business functions
- Check integrations with external systems
Backup best practices
The 3-2-1 strategy
Apply the 3-2-1 rule to critical data - it is a recognized standard in the IT industry:
- 3 copies of your data (the original + 2 backups taken at different points in time)
- 2 different media or technologies (e.g., a local disk and the cloud, or an HDD and an SSD)
- 1 copy off-site (an off-site backup in the cloud or another physical location)
Regularly testing restores
A backup that cannot be restored is useless. Regularly test the restore process in a test environment:
- At least once a quarter, restore a full backup in a test environment
- Measure the time needed to restore (important for planning your RTO - Recovery Time Objective)
- Check data integrity after restoring
- Document the process and any problems encountered
- Train your team in data recovery procedures
Encrypting backups
Protect sensitive business data by encrypting backup files, especially if they are stored off-site:
# Encryption with GPG
gpg --symmetric --cipher-algo AES256 backup_file.dump
# Or use OpenSSL
openssl enc -aes-256-cbc -salt -in backup_file.dump -out backup_file.dump.enc -k HASLO
# Decryption (when restoring)
gpg backup_file.dump.gpg
# or
openssl enc -aes-256-cbc -d -in backup_file.dump.enc -out backup_file.dump -k HASLO
Important: Store the passwords for encrypted backups in a secure password manager, separately from the backups themselves.
Monitoring and alerts
Set up a notification system that reports whether the backup process succeeded or failed. You can do this in several ways:
# Extended example in a backup script with notifications:
if [ $? -eq 0 ]; then
echo "Odoo backup completed successfully on $(date)" | mail -s "✓ Odoo Backup OK" admin@firma.pl
else
echo "WARNING! Odoo backup failed on $(date). Check the logs: /var/log/odoo-backup.log" | mail -s "✗ ALERT: Odoo Backup FAILED" admin@firma.pl
fi
You can also integrate notifications with tools such as Slack, Microsoft Teams or monitoring systems:
# Example of sending to Slack
curl -X POST -H 'Content-type: application/json' --data '{"text":"Odoo backup completed successfully"}' https://hooks.slack.com/services/YOUR/WEBHOOK/URL
Incremental backup (for Odoo Enterprise)
If you use Odoo Enterprise with Odoo.sh or your own infrastructure with advanced tools, consider implementing incremental backups:
- A full backup once a week (e.g., on the weekend)
- Incremental backups every day (only the changes since the last backup)
- This approach significantly saves space and time
- Requires dedicated tools such as Barman for PostgreSQL
Backup before a migration or update
Before any significant change to your Odoo system, such as upgrading to a newer version or moving to another server, always make a full backup of your Odoo database.
Recommended procedure before an update or migration:
- Make a full database backup in PostgreSQL custom format
- Back up the filestore directory with all attachments
- Save a copy of the odoo.conf configuration file (it may be needed for debugging)
- Make a list of installed modules with their versions (you can do this via Settings → Apps)
- Back up the directories with custom modules (custom addons)
- Save screenshots of key settings (optional, but helpful)
- Test restoring the backup in a test environment before starting the migration
- Make sure you have access to the previous Odoo version in case you need to roll back the changes
Example pre-migration backup script:
#!/bin/bash
DB_NAME="odoo_production"
BACKUP_DIR="/var/backups/odoo/pre-migration-$(date +%Y%m%d)"
mkdir -p $BACKUP_DIR
# Database backup
sudo -u postgres pg_dump -d $DB_NAME -F c -f $BACKUP_DIR/database.dump
# Filestore backup
tar -czf $BACKUP_DIR/filestore.tar.gz /home/odoo/.local/share/Odoo/filestore/$DB_NAME
# Configuration backup
cp /etc/odoo/odoo.conf $BACKUP_DIR/
# Custom addons backup
tar -czf $BACKUP_DIR/custom_addons.tar.gz /opt/odoo/custom_addons
# List of installed modules (requires psql to be installed)
sudo -u postgres psql $DB_NAME -c "SELECT name, state, latest_version FROM ir_module_module WHERE state='installed'" > $BACKUP_DIR/installed_modules.txt
echo "Pre-migration backup completed in $BACKUP_DIR"
Remote storage of backups
Storing backups only on the same server as Odoo is risky. In the event of a hardware failure or ransomware, you could lose both your production data and your backups.
Cloud synchronization
Use tools such as rclone to automatically synchronize backups with cloud services (AWS S3, Google Drive, Azure, Dropbox, etc.):
# Installing rclone
curl https://rclone.org/install.sh | sudo bash
# Configuration (interactive wizard)
rclone config
# Example of syncing backups to Google Drive
rclone sync /var/backups/odoo/ gdrive:odoo-backups --progress
# Or to AWS S3
rclone sync /var/backups/odoo/ s3:moj-bucket/odoo-backups --progress
# For extra security: encryption during transfer
rclone sync /var/backups/odoo/ gcrypt:encrypted-backups --progress
Add the synchronization to the backup script, or as a separate cron job that runs after the local backup finishes:
# Run the synchronization 30 minutes after the backup
30 2 * * * /usr/bin/rclone sync /var/backups/odoo/ gdrive:odoo-backups --log-file=/var/log/rclone-backup.log
Backup via rsync to a remote server
If you have access to a second server, rsync is a proven method for synchronizing backups:
# Basic synchronization
rsync -avz -e ssh /var/backups/odoo/ user@zdalny-serwer:/backups/odoo/
# With compression and progress display
rsync -avz --progress -e ssh /var/backups/odoo/ user@zdalny-serwer:/backups/odoo/
# Excluding files older than 30 days on the source
find /var/backups/odoo/ -type f -mtime -30 | rsync -avz --files-from=- / user@zdalny-serwer:/backups/
For security, configure SSH keys so that rsync can run without prompting for a password:
# Generate a key pair (if you do not have one yet)
ssh-keygen -t rsa -b 4096
# Copy the public key to the remote server
ssh-copy-id user@zdalny-serwer
FAQ - Frequently asked questions
How often should Odoo backups be made?
The backup frequency depends on how intensively the system is used and how critical the data is. Recommendations:
- Minimum requirement: One full backup per day (at night) for all production systems
- Moderately loaded systems: Backups every 6-12 hours
- Critical systems: Backups every 1-4 hours or continuous database replication
- E-commerce and online stores: At least every 4 hours due to frequent orders
- Before updates: Always immediately before changes to the system
Also remember a retention strategy - keep backups for an appropriate length of time (e.g., 30 days of daily backups, 12 months of monthly backups).
Does a database backup contain all Odoo data?
A backup of the PostgreSQL database alone contains most of the Odoo data, but not everything. A full Odoo backup should include:
- PostgreSQL database dump - contains transactional data, configuration, user settings, products, invoices, orders, etc.
- Filestore directory - stores attachments, product images, documents, photos, PDFs and files uploaded by users
- The odoo.conf configuration file (optional) - helpful when restoring, contains connection settings, paths and parameters
- Custom modules (if you have your own or purchased ones) - the custom addons directories
- Session files (rarely needed) - if you use file-based sessions instead of database-based ones
A backup via the Odoo web interface automatically includes the database and the filestore in a single archive. With a CLI backup, you must take care of both elements separately.
What should I do when the backup is too large?
For large databases (above a few GB) you can apply several optimization solutions:
- Use the pg_dump custom format with compression - it is much smaller than SQL
- Implement an incremental backup strategy - a full backup once a week, and only the changes the rest of the time (requires tools such as Barman or pgBackRest)
- Archive old data - move historical records to a separate archive database
- Clean up logs and unused attachments - regularly delete old temporary files, audit logs and unused images
- Compress the filestore separately - use tar with the -czf option or 7zip with high compression
- File-system-level deduplication - use ZFS or Btrfs with deduplication
- Keep different retention frequencies - daily backups for 7 days, weekly for a month, monthly for a year
- Consider professional backup tools - Veeam, Bacula and Amanda offer advanced compression and deduplication
Example of a script with compression and cleanup:
#!/bin/bash
# Backup with aggressive compression and cleanup
# Database backup with compression level 9
sudo -u postgres pg_dump -d odoo_db -F c -Z 9 -f backup.dump
# Filestore with 7zip (if installed)
7z a -t7z -m0=lzma2 -mx=9 filestore.7z /path/to/filestore/
# Or tar with xz (best compression)
tar -cJf filestore.tar.xz /path/to/filestore/
How do I check whether a backup succeeded?
Verifying the integrity of a backup is crucial. You can do this in several ways:
- Check the command's exit code - in scripts use
if [ $? -eq 0 ] - Verify the file size - compare it with previous backups; a drastic difference may indicate a problem
- Test restoring - the best test is to actually restore in a test environment
- Use pg_restore --list - displays the contents of the backup without restoring it
- Calculate a checksum - record the MD5/SHA256 of each backup and check it before restoring
# PostgreSQL backup verification
pg_restore --list backup.dump > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Backup is valid"
else
echo "Backup is corrupted"
fi
# Calculating and saving the checksum
sha256sum backup.dump > backup.dump.sha256
Can I run a backup while the system is running?
Yes, you can and you should! PostgreSQL and Odoo support so-called "hot backup" - a backup taken while the system is running. You do not need to stop Odoo or PostgreSQL to make a backup.
PostgreSQL uses the MVCC (Multi-Version Concurrency Control) mechanism, which guarantees data consistency during a backup. The backup will represent the state of the database at the moment pg_dump started.
Notes:
- A backup may slow down the system while it runs (increased I/O load)
- It is therefore recommended to run backups at night or during low load
- For very large databases, consider using a replica for backups
Summary
Regularly backing up your Odoo database is an essential part of managing an ERP system and can save your company from the serious consequences of data loss. The methods presented - from a simple backup via the web interface, through advanced automation scripts with error handling, to remote storage in the cloud - offer a full range of options suited to different business needs and levels of technical expertise.
Key takeaways:
- A backup must include both the PostgreSQL database and the filestore directory
- Automation with cron is a necessity, not an option
- Apply the 3-2-1 strategy and store backups in multiple locations
- Regularly test the restore process - a backup that cannot be restored is useless
- Monitor and verify the correctness of your backups
- Encrypt backups that contain sensitive data
- Adjust the backup frequency to the criticality of your data
Remember that you will only learn the value of a backup when you have to use it - make sure it works properly before the need arises. The time invested in properly configuring your backup system will pay off many times over in the event of a failure.
Need help setting up a secure backup strategy for Odoo? The KK Innovations team specializes in implementing and administering Odoo systems. We offer comprehensive solutions covering backup automation, monitoring, replication and disaster recovery plans. Contact us to discuss the optimal solution for your company and ensure maximum security of your business data in line with industry best practices.