Odoo Help


How do I automate database backups?

on 3/30/13, 12:15 PM 22,074 views

I would like to set up an automated action to make a backup of the database every 30 minutes. I think that I must define an server action with python code. I need help with python code. thank you in advance.

Do you mean the OpenERP database?

Andreas Brueckl
on 3/30/13, 12:53 PM
Mohamed arif
On 4/10/13, 9:09 AM

Alternatively, you can create a crontab to invoke a python script which does backup. refere following script

import os
import time
import subprocess

dump_dir = '/home/openerp/db_backup'
db_username = 'openerp'
#db_password = ''
db_names = ['DB_NAME']

for db_name in db_names:
        file_path = ''
        dumper = " -U %s --password -Z 9 -f %s -F c %s  "
#        os.putenv('PGPASSWORD', db_password)
        bkp_file = '%s_%s.sql' % (db_name, time.strftime('%Y%m%d_%H_%M_%S'))
#        glob_list = glob.glob(dump_dir + db_name + '*' + '.pgdump')
        file_path = os.path.join(dump_dir, bkp_file)
        command = 'pg_dump' + dumper % (db_username, file_path, db_name)
        subprocess.call(command, shell=True)
        subprocess.call('gzip ' + file_path, shell=True)
        print "Couldn't backup database" % (db_name)

It's a cool stuff!

on 4/10/13, 9:29 AM

Thanks Arif!

on 4/10/13, 3:07 PM

Yes it works for version 7.0.

on 1/30/14, 5:24 AM



| 5 2 7
Lomé, Togo


On 4/5/13, 4:03 PM

Thank you. Francesco I did bash sript and I run with crontab. I still have a little detail to be adjusted. I would like the file generated by crontab has a dynamic name for example: "namedatabase-date-hour-minute-seconde.dump". Is it possible?


  • you have to deposit the script in the directory etc and give the access by doing this command in shell:

sudo mv path_to_the_script /etc/cron.hourly/

sudo chmod +x name_of_the_script.py

  • The crontab execute your script.py file for example every 5min after these commands in shell:

    crontab -e

    /5 * * * * /etc/cron.hourly/script.py

    Press button F2 and Enter

use someting like namedatabase-$(date %H-%M-%S).dump. Look at man date for more options

Lorenzo Cabrini
on 4/10/13, 1:10 AM
On 4/10/13, 12:45 AM


I working around this problem, and I waste a couple of time to find the solution. I use this module with a small problem, but this is works as well, the issue what is coming from the server time zone. (UTC) So if you want to test it under 6.1 (may 7.0 same) please setting the next schedule time according UTC, and it will be works. This time issue, is true not just this module, all of that what is use Openerp server as cron controller. I do not have a karma to share a link. (module name is : "db_backup_ept - Database Auto-Backup & Backup Auto-Transfer to FTP server")

Other case the backup is a bit painful under Linux, with cron. The automation of backup you need to store the database data in .pgpass according by this: www.postgresql.org/message-id/490F6EDE.70502@nrc-cnrc.gc.ca you can find a good scripts at here: blog.ufsoft.org/2011/07/03/postgres-cron-backupsI want to avoid to store the db pass in cron script, because this is security hole.

Otherwise you can find some solution about Pgagent also, but I can't try it, because I didn't have a time for the trials.

Finally please never forget to test the restore. (I have a lot of problem with restore, under 9.1 from zip, now I can restore from plain text by psql command).

How to restore: psql NEW_DB_NAME -f SQL_FILE_NAME

Hi klacus, I used db_backup_ept to auto and manual backup it created successfully. But I can't restore the database. The backup format is db_name.sql, how to restore this. help me...

on 2/13/14, 6:37 AM

I edit my answer. pls. check it.

on 2/13/14, 10:19 PM

Yes it is working Thanks...

on 2/15/14, 1:54 AM
Joseph Andrade
On 6/25/15, 7:15 AM


Does anyone has a python script for a Webpage in order to duplicate the DB and store it wherever instructed? I need to enable this functionality for one of my clients on their website and I don't have much clue of how to get this done.

Any help will be appreciated.

Many thanks.

E.R. Spada II
On 3/13/14, 6:37 PM

You can use the module written by Tiny: auto_backup, works great! "name" : "Database Auto-Backup", "version" : "1.0", "author" : "Tiny", "website" : " "category" : "Generic Modules", "description": """The generic Open ERP Database Auto-Backup system enables the user to make configurations for the automatic backup of the database. User simply requires to specify host & port under IP Configuration & database(on specified host running at specified port) and backup directory(in which all the backups of the specified database will be stored) under Database Configuration.

Automatic backup for all such configured databases under this can then be scheduled as follows:

1) Go to Administration / Configuration / Scheduler / Scheduled Actions 2) Schedule new action(create a new record) 3) Set 'Object' to 'db.backup' and 'Function' to 'schedule_backup' under page 'Technical Data' 4) Set other values as per your preference""",

On 2/2/14, 5:23 PM

su openerp -s /bin/bash -c 'pg_dump $YOUR-DB' > $YOUR-DB.sql

Bart Criel
On 2/14/14, 6:24 AM

I am using the information on the PostgreSQL Wiki ( look for Automated_Backup_on_Linux ) to schedule backups with cron. Works fine; set and forget.



Francesco OpenCode

--Francesco OpenCode--

| 6 8 9
Grottaglie, Italy
--Francesco OpenCode--

Italian Odoo (OpenERP) Modules Developer LINKEDIN: http://www.linkedin.com/in/francescoapruzzese

Francesco OpenCode
On 3/30/13, 12:59 PM

If you're using a GNU/Linux system, the best way is to use cron + script bash to do postgres backup. If you want use python, you will use bash however.

P.S. 30 minutes is a time too short. 2 or 3 times at day are good.

Ram S
On 3/30/13, 4:34 PM

In OpenERP V6.x there was an option to automatically back thorough scheduler with in OpenERP. Which automatically does the backup. I am not sure it still exist in V7. '

Jairo Llopis
On 5/27/14, 6:46 AM

I use this cron script:



rm $DIR/$DB*.tar
sudo -u openerp pg_dump --format t --file "$DIR/$DB $(date --rfc-3339 seconds).tar" $DB

Put it into /etc/cron.daily/ and give it execution permissions.

If you want to have more than one version of the database, you may put you own logic in the line rm $DIR/$DB*.tar.

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

3 follower(s)


Asked: 3/30/13, 12:15 PM
Seen: 22074 times
Last updated: 11/6/15, 10:37 AM