How to backup a local odoo server.

To back up a locally hosted Odoo instance, follow these steps to ensure all critical components (database, filestore, custom code, and configurations) are safely backed up:


1. Backup the Odoo Database

Odoo uses PostgreSQL for its database. Use pg_dump to create a SQL dump of your database.

Command:

pg_dump -U <postgres_username> -F p <database_name> > /path/to/backup/odoo_db_$(date +%Y-%m-%d).sql
  • Replace <postgres_username> and <database_name> with your PostgreSQL credentials.
  • Example: pg_dump -U odoo -F p odoo_production > ~/backups/odoo_db_2023-10-01.sql

2. Backup the Filestore

Odoo stores attachments (e.g., documents, images) in the filestore directory. Locate it in your Odoo config file (odoo.conf):

Command:

# Find the filestore path (default: ~/.local/share/Odoo/filestore)
grep data_dir /etc/odoo/odoo.conf

# Copy the filestore directory
cp -r ~/.local/share/Odoo/filestore/<database_name> /path/to/backup/filestore_$(date +%Y-%m-%d)

3. Backup Custom Modules/Code

If you’ve added custom modules or modified Odoo source code, back up these directories:

  • Custom modules (e.g., ~/odoo-custom-addons)
  • Odoo source code (if modified, e.g., /opt/odoo/odoo).

Command:

tar -czvf /path/to/backup/odoo_custom_code_$(date +%Y-%m-%d).tar.gz \
  ~/odoo-custom-addons \
  /opt/odoo/odoo

4. Backup Configuration Files

Back up your Odoo configuration file and any server configurations (e.g., Nginx/Apache, service files).

Command:

cp /etc/odoo/odoo.conf /path/to/backup/odoo.conf_$(date +%Y-%m-%d)

5. Automate Backups (Optional)

Create a script (/path/to/backup_odoo.sh) to automate daily backups:

Script Example:

#!/bin/bash
BACKUP_DIR="/path/to/backups"
DB_NAME="odoo_production"
DB_USER="odoo"
DATE=$(date +%Y-%m-%d)

# Backup database
pg_dump -U $DB_USER -F p $DB_NAME > $BACKUP_DIR/odoo_db_$DATE.sql

# Backup filestore
rsync -avr ~/.local/share/Odoo/filestore/$DB_NAME $BACKUP_DIR/filestore_$DATE

# Backup custom code
tar -czvf $BACKUP_DIR/odoo_custom_code_$DATE.tar.gz ~/odoo-custom-addons

# Backup config
cp /etc/odoo/odoo.conf $BACKUP_DIR/odoo.conf_$DATE

# Delete backups older than 30 days
find $BACKUP_DIR -type f -mtime +30 -delete

Add to Cron (run daily):

crontab -e
# Add this line to run at 2 AM daily:
0 2 * * * /bin/bash /path/to/backup_odoo.sh

6. Restoring from Backup

To restore Odoo from a backup:

  1. Database:
   createdb -U <postgres_user> <new_db_name>
   psql -U <postgres_user> <new_db_name> < /path/to/backup/odoo_db_2023-10-01.sql
  1. Filestore:
   cp -r /path/to/backup/filestore_2023-10-01 ~/.local/share/Odoo/filestore/<new_db_name>
  1. Custom Code/Configs:
    Extract the .tar.gz file and replace the relevant directories/configs.

Additional Tips

  • Use Odoo’s Built-in Backup:
    Go to Settings > Database > Backup in the Odoo web interface to download a .zip backup (includes database + filestore).
  • Encrypt Backups: Use tools like gpg for sensitive data.
  • Offsite Storage: Store backups in cloud storage (e.g., AWS S3, Google Drive) or a remote server.
  • Test Restores: Periodically verify backups by restoring them to a test environment.

By following these steps, you’ll ensure a complete backup of your Odoo instance, minimizing downtime and data loss risks.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *