What is the best way to do automatic backups?

I am using openERP v6.1 and I would like to know which one is best suited for automatic database backup (let daily backups be)

The "Backup" parameter in the web interface in "Database Management" allows you to restore and create a database in one step. Of course, this must be done manually. Is there a way to automate this process and get the same type of backups as a result? (I'm not sure which file it exports as * .dump)

I tried pg_dump, but I can’t import this file (I tried raw sql and gziped text) from the web interface, of course, there must be different formats. And I have some problems trying to import pg_dump backup for postgres with psql. I can restore the backup, but then when you accessed the site on the Internet, I saw openERP empty

Any thoughts on best practices for this?

+5
source share
5 answers

Assuming you have access to a server running OpenERP, I recommend using pg_dump (with "custom") using the cron task at the system level.

Justification:

, pg_dump postgres psql. , , , openERP empty ", , . pg_dump/pg_restore OpenERP.

+2

python script, . cron, python script .

apps.openerp.com: http://apps.openerp.com/addon/1759

+1

, OpenERP7, Synology, DSM5.2. OpenERP. SSH NAS Synology. .

#!/bin/sh
# Synology OpenERP database backup utiliy. Specify variable information below.
# Run at /etc/crontab at the desired interval.
DIR=/volume1/OpenERP_Backup/
DATESTAMP=$(date +"%Y-%m-%d")                                           
DB_USER=OPENERP7                                                        
DATABASE=Demo

# create backup dir if it does not exist                        
mkdir -p ${DIR}

# remove all backups except the $KEEP latest                    
KEEP=7                                                          
BACKUPS=`find ${DIR} -name "${DATABASE}_*.dump" | wc -l | sed 's/\ //g'`
while [ $BACKUPS -ge $KEEP ]                                            
 do                                                                      
  ls -tr1 ${DIR}${DATABASE}_*.dump | head -n 1 | xargs rm -f            
  BACKUPS=`expr $BACKUPS - 1`                                         
done

# dump the database in a file                                       
FILENAME=${DIR}${DATABASE}_${DATESTAMP}.dump                        
/usr/syno/pgsql/bin/pg_dump --format=c --no-owner --username=${DB_USER} 
--file=${FILENAME} ${DATABASE}

#Development Notes
#Notes on how OpenERP handles backup & restore: 
#For backup
#pg_dump --format=c --no-owner --username=<> --host=<> --port=<> <dbname>
#For restore:
#pg_restore --no-owner --dbname=<> 

#Notes on how Synology DSM handles crontab jobs:
#Run script by assigning job to the crontab. Crontab on Synology NAS can
be found at:
#/etc/crontab 
#crontab entry would look something like the following:
#10  1  *   *   *   root    sh /volume1/OpenERP_Backup/backup.sh
+1

"", pg_dump postgres psql. , , , openERP empty "

psql postgres openerp.

0

postgresql

  • Directry

    mkdir database_backup
    

2.

   nano pg-backup.sh

#enable this option, if you are creating hourly backup
if [ ! -d "$2/`date +%F-%H`" ]; then
mkdir $2/`date +%F-%H`
pg_dump $1 > $2/`date +%F-%H`/$1.sql
else
echo "Do not run this script manually !"
fi

#enable this option, if you are creating daily backup
if [ ! -d "$2/`date +%F`" ]; then
mkdir $2/`date +%F`
pg_dump $1 > $2/`date +%F`/$1.sql
else
echo "Do not run this script manually !"
fi     
  1. chmod 755 pg_backup.sh
    

    sudo crontab -e

@hourly /home/openerp/database_backup/pg_backup.sh database_name /home/openerp/database_backup/

, .

    sudo crontab -e

.

     @daily /home/openerp/database_backup/pg_backup.sh database_name /home/openerp/database_backup/

root- postgresql , ino openerp

postgres,

psql -username <openerp_database_user> -dbname <New_database_name> -f <path_of_backuped_.sql_file>
0

All Articles