Odoo

All Odoo/PostgreSQL Database backup

A short Python script that dumps every listed PostgreSQL database in one run, written to back up Odoo databases from v6 to v11.

1 min readComment

A cluster of orange firecracker flowers among dark green leaves.

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

sudo su postgres

2. start PSQL prompt

psql

3. get the list of databases using below query.

SELECT datname FROM pg_database;

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.

import os

lines = [line.strip() for line in open('<<txt file path>>')]
for i in lines:
    print os.system("pg_dump %s > <<db out directory>>/%s.sql" % (i,i))

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.

Discussion

No comments yet. Start the conversation.

Comments are moderated. Your email is never shown publicly. See the privacy policy.

Keep reading

View all