How to Restore a PostgreSQL Backup to a Docker Container in Odoo
If you’re running an Odoo instance with PostgreSQL in Docker and need to restore a backup from a VPS, follow these steps.
Prerequisites:
- A
.sqlor.dumpbackup file from your VPS. - The PostgreSQL container (
odoo-docker_db_1) is running. - Ensure the PostgreSQL version in the backup is compatible with PostgreSQL 13 (the version in your container).
Steps to Restore the Backup:
1. Copy the Backup File to the PostgreSQL Container
First, move the backup file from your VPS directory to the PostgreSQL container using the
docker cpcommand.bashdocker cp /path/to/your/backup.sql odoo-docker_db_1:/backup.sqlThis places the backup file (e.g.,
backup.sql) into the root directory of the PostgreSQL container.2. Access the PostgreSQL Container
To perform the restore, access the PostgreSQL container by running:
bashdocker exec -it odoo-docker_db_1 bash3. Restore the Database
Once inside the container, restore the database using either
psqlorpg_restoredepending on the format of your backup.- For a plain
.sqlfile:
bashpsql -U postgres -d your_database < /backup.sqlReplace
your_databasewith the name of the database you want to restore. If the database doesn’t exist, create it first:bashcreatedb -U postgres your_database- For a custom-format
.dumpfile:
bashpg_restore -U postgres -d your_database /backup.dump4. Verify the Restore
Once the restore process is complete, verify the data:
- Check the databases:
bashpsql -U postgres -l- Connect to the restored database to verify the tables:
bashpsql -U postgres -d your_database5. Restart Odoo (if needed)
If Odoo depends on the restored data, restart the Odoo container to ensure everything is loaded properly:
bashdocker restart odoo-docker_web_1Recap of Commands:
- Copy the backup to the PostgreSQL container:
bashdocker cp /path/to/your/backup.sql odoo-docker_db_1:/backup.sql- Access the PostgreSQL container:
bashdocker exec -it odoo-docker_db_1 bash- Restore the backup:
- For
.sqlfile:
bashpsql -U postgres -d your_database < /backup.sql- For
.dumpfile:
bashpg_restore -U postgres -d your_database /backup.dump- Restart the Odoo container (if necessary):
bashdocker restart odoo-docker_web_1 - For a plain





