Backup all Odoo/PostgreSQL databases using Python script

I have made this simple python script to dump all PostgreSQL database. I am using this script for my Odoo PostgreSQL databases. & I often use this script when I am re-installing the OS. In my Development environment, I have databases for Odoo v6 to v11 and master. to back up those databases is a time-consuming process if I do it manually.

Here are the steps to run this script

Start the psql prompt in the terminal

1. switch to the postgres user

2. start PSQL prompt

3. get the list of databases using below query.

4. copy the database names and paste them into the text file. (if you wanted to remove any database you can remove them from the file.)

5. copy the script below and replace the file path.

6. run the script using python. it will dump the listed database and save them to <<db outdirectory>>.

hope this will save a lot of your time.




Leave a Reply