Odoo - OpenERP - How to setup a regular PostgreSQL database backup?

Zarshed Ali
Zarshed Ali
5000
| 2 1 2
Asked on 1/29/15, 1:23 PM
0
vote
4100 Views

1) Create Backup-Script /var/scripts/dump_db.sh

#!/bin/sh    
hostname=`hostname`

##########################################
## OpenERP Backup
## Backup databases: openerpdb1, openerpdb2
##########################################

# Stop OpenERP Server
/etc/init.d/openerp-server stop

# Dump DBs
for db in openerpdb1 openerpdb2
do
  date=`date +"%Y%m%d_%H%M%N"`
  filename="/var/pgdump/${hostname}_${db}_${date}.sql"
  pg_dump -E UTF-8 -p 5432 -F p -b -f $filename $db
  gzip $filename
done

# Start OpenERP Server
/etc/init.d/openerp-server start

exit 0

2) Create Housekeeping script /var/scripts/housekeeping.sh 
(deletes backups which are older than 30 days)

#!/bin/sh
path=/var/pgdump
logfile=/var/log/$0

rm -f $logfile
for file in `find /var/pgdump/ -mtime +30 -type f -name *.sql.gz`
do
  echo "deleting: " $file >> $logfile
  rm $file
done

exit 0

3) Create daily cronjobs in /etc/crontab. 
The backup runs daily at 1am and the housekeeping job runs daily at 5am.

# m h dom mon dow user  command
0 1 * * * postgres /var/scripts/dump_db.sh
0 5 * * * postgres /var/scripts/housekeeping.sh

Zarshed Ali
Zarshed Ali
5000
| 2 1 2
Answered on 1/29/15, 1:24 PM
0
vote

Your answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

Ask a Question

Keep Informed

About This Forum

This forum is for HiTechnologia Employees & just Odoo general knowledge purpose only.

Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 1/29/15, 1:23 PM
Seen: 4100 times
Last updated: 1/30/15, 10:38 AM