中菁- odoo  ERP 实施 杭州

示例图片三
首页 > Odoo资讯

如何定期备份Odoo(OpenERP)数据库

2017-04-17 13:35:26 中菁- odoo ERP 实施 杭州 阅读

I use the following setup:

 

Backup-Script /var/script/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 5433 -F p -b -f $filename $db

  gzip $filename

done

 

# Start OpenERP Server

/etc/init.d/openerp-server start

 

exit 0

 

Housekeeping script /var/script/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

 

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


Powered by MetInfo 5.3.15 ©2008-2018 www.metinfo.cn