Overview
Usually, you can back up the database through the Odoo interface. However, if the backup file size is too large (over 20GB), it can become problematic.
I will guide you through a manual method that is a bit more challenging, but it will give you a deeper understanding of how Odoo restore works — and most importantly, it allows you to restore even when the data is very large.
Odoo stores its data in two parts:
- PostgreSQL database
- Filestore
What is the Filestore?
When you create a Binary
field in a model and upload a file, Odoo does not store the file directly in the database.
Instead, it saves the file into a special directory called the filestore, and uses the ir.attachment
model to manage and reference these files.
To perform a manual backup and restore, you need to back up both parts and move them to the target server.
1. Backup Filestore
The filestore usually resides in:
~/.local/share/Odoo/filestore, ex: /odoo/.local/share/Odoo/filestore, /opt/.local/share/Odoo/filestore
Step 1: Zip the filestore
zip -r filestore.zip ~/.local/share/Odoo/filestore
Step 2: Transfer the file to the restore server
Then unzip the file to the restore server:
On the restore server, assuming you already have an Odoo server installed,
you need to identify the path to the filestore — for example: /opt/.local/share/Odoo/filestore
.
Then unzip the backup file to that directory:
unzip filestore.zip -d /opt/.local/share/Odoo/filestore
The Odoo server needs permission to write files to the filestore directory.
Make sure to set the correct permissions:
chmod -R 777 /opt/.local/share/Odoo/
# or
sudo chown -R odoo:odoo /opt/.local/share/Odoo/
2. Backup PostgreSQL Database
Check PostgreSQL version
Check the pg_dump
version to ensure compatibility between the backup and restore Postgres servers:
pg_dump --version
? Backup database with pg_dump
pg_dump -Fc --user=odoo --dbname=my_db > my_db.dump
If using Docker, run:
docker exec postgres_db pg_dump -Fc --user=odoo --dbname=my_db > my_db.dump
Here:
postgres_db is the name of the PostgreSQL container.
odoo is the database owner/user.
my_db is the name of the database.
This command will create a
my_db.dump
file that contains the database dump.
3. Install PostgreSQL 16.3
Install PostgreSQL (if not installed)
If the dump was made using PostgreSQL 16.3, you need to install the same version on the restore server.
The following guide installs PostgreSQL directly on the restore server (no Docker is used).
A. Download source from PostgreSQL
wget https://ftp.postgresql.org/pub/source/v16.3/postgresql-16.3.tar.gz
B. Install build dependencies
sudo apt update
sudo apt install build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt1-dev libssl-dev -y
C. Compile and install PostgreSQL
tar -xzf postgresql-16.3.tar.gz
cd postgresql-16.3
./configure
make -j$(nproc)
sudo make install
By default, binaries are installed in /usr/local/pgsql/bin/
.
?️ 4. Create PostgreSQL User and Init Database
sudo adduser postgres
sudo mkdir /usr/local/pgsql/data_16
sudo chown postgres /usr/local/pgsql/data_16
Switch to postgres user and initialize DB:
sudo su - postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data_16
Ensure correct ownership:
sudo chown -R postgres:postgres /usr/local/pgsql/data_16
? 5. Create systemd service for PostgreSQL 16
Create a new file:
/etc/systemd/system/postgresql-16.service
[Unit]
Description=PostgreSQL 16 database server
Documentation=man:postgres(1)
After=network.target
[Service]
Type=forking
User=postgres
Group=postgres
ExecStart=/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data_16 -l /usr/local/pgsql/data_16/logfile start
ExecStop=/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data_16 stop
ExecReload=/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data_16 reload
PIDFile=/usr/local/pgsql/data_16/postmaster.pid
[Install]
WantedBy=multi-user.target
Reload and enable service:
sudo systemctl daemon-reload
sudo systemctl enable postgresql-16.service
sudo systemctl start postgresql-16.service
sudo systemctl status postgresql-16.service
You should see PostgreSQL running:
postgresql-16.service - PostgreSQL 16 database server
Active: active (running)
? 6. Restore the Database
? Upload my_db.dump
to the restore server
Navigate to the dump file directory on restore server:
cd /dump_files
Restore database:
/usr/local/pgsql/bin/pg_restore -U postgres -p 5433 -C -d postgres my_db.dump
In this example, PostgreSQL is configured to use port 5433 (as defined in the postgresql.conf file). You can use a different port, just make sure it matches your PostgreSQL server configuration.
This command will recreate the database
my_db
and set its owner toodoo
.
? 7. Upload Odoo Addons
Upload all custom Odoo addons to the restore server.
Set appropriate permissions:
sudo chown -R odoo:odoo /path/to/addons or sudo chmod -R 777 /path/to/addons
Install required Python packages if needed.
8. Make the odoo.conf
file the same on both servers and configure the database
odoo.conf
file for both the backup and restore servers is same for configs. Example configuration:
Exsample:
[options]
; This is the password that allows database operations:
admin_passwd = your_admin_odoo
http_port = 8069
logfile = /var/log/odoo/odoo-server.log
addons_path = /odoo/odoo-server/addons,/odoo/custom/addons
proxy_mode = True
db_host = localhost
db_port = 5433
db_user = odoo
db_password = your_db_password
db_name = my_db
log_db_level = warning
limit_memory_hard = 4000000000
limit_memory_soft = 5000000000
limit_time_cpu = 1800
limit_time_real = 3600
server_wide_modules = base,web,queue_job
[queue_job]
channels = root:4
✅ Done!
Your Odoo server has now been successfully restored manually with both database and filestore.
Reply