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
.sql
or.dump
backup 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 cp
command.bashdocker cp /path/to/your/backup.sql odoo-docker_db_1:/backup.sql
This 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 bash
3. Restore the Database
Once inside the container, restore the database using either
psql
orpg_restore
depending on the format of your backup.- For a plain
.sql
file:
bashpsql -U postgres -d your_database < /backup.sql
Replace
your_database
with 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
.dump
file:
bashpg_restore -U postgres -d your_database /backup.dump
4. 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_database
5. 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_1
Recap 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
.sql
file:
bashpsql -U postgres -d your_database < /backup.sql
- For
.dump
file:
bashpg_restore -U postgres -d your_database /backup.dump
- Restart the Odoo container (if necessary):
bashdocker restart odoo-docker_web_1
- For a plain