Either the odoo interface itself or psql commands can be used to restore the database. It will be advisable to use PSQL commands when working with huge databases. To restore a backup, we need a backup of the database. We can easily backup the database from the odoo front end and restore it either from the front end or using the terminal.
Backup Database:
Go to the database manager (<odoo-url>/web/database/manager) and click the backup button.
On clicking the backup button, a popup window will be shown.
Master password: the given password when you create the database.
Backup format: we can backup the database in two different formats,
1. Zip (Include filestore)
2. Pg_dump custom format( without filestore)
On selecting the zip option, it will generate a zip file including the filestore, dump.sql, and manifest.json.
The dump.sql file mainly contains all the (Postgresql backup) data. The filestore contains all the static files stored on disks such as images and attachments. The list of modules, the Odoo version, the database name, the Postgresql version, and more are all included in the manifest.json file.
On clicking the backup button, it will generate a database backup.
Restore Backup:
From the front end, we may restore the database. To restore the database, go to the database manager at odoo-url>/web/database/manager and select "Restore Database."
On clicking the button, a popup window will appear.
Provide the master password, brows the .zip file from your directory, give a name to the database and click the continue button.
If we don't want to restore the filestore (i.e. the images and attachments), we can use the dump.sql file from the terminal to restore the database. Extract the database backup .zip file which contains filestore, manifest.json, and dump.sql.
To restore the database using dump.sql
01. Create a database
02. Execute the command to restore the database from dump.sql.
$sudo su postgres
$createdb -O [Owner] [database_name]
$psql [database_name] < dump.sql
Similarly, we can restore the .dump backup file. Go to database manager, then back up the database in the pg_dump custom format (without filestore), we will get a file .dump format
Run the following commands in the terminal to restore the database.
$sudo su postgres
$createdb -O [Owner] [database_name]
$pgrestore -d [database_name] [dumpfile_name].dump
Visit our blog Odoo 15 Database Management for further information on how to access and manage the database.