Odoo Help

Welcome!

This community 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.

1

Pascal Tremblay

--Pascal Tremblay--
1312
| 5 2 7
Alma, Canada
--Pascal Tremblay--


Pascal Tremblay
On 12/11/14, 9:01 AM

Script name : odoo.db.backup.quotidien.sh

This script is executed two times a day via cron. 

This script dump the actual odoo database, create a new db and import data in this new database.

You can after run Odoo with the database you want.

It's really magic to make test on actual database. Each morning, I have a new fresh copy of my actual database and I can log in it if I want.

For the moment, the script doesn't erase the older created databases. 

For the moment, the script stops Odoo to make the dump. We didn't try without to stop Odoo.

Here is our script :

#!/bin/bash

clear

DATABASE="officielle"
NOW=$(date +"%d-%m-%Y_%H-%M")
NOMDUFICHIER="/home/flooder/Bureau/odoo_quotidien_$DATABASE_$NOW.sql"

NEWDB="odoo_quotidien_$NOW" 

echo "1) Arrêt de Odoo..."
/home/flooder/Programmes/StopOdoo.sh

echo
echo "2) Nettoyage du fichier journal..."
> /home/flooder/Programmes/log/odoo.db.backup.quotidien.log
echo
echo "3) Préparation de la sauvegarde de la base de données Odoo... " 


export PGPASSWORD="lsssls"
echo


echo "4) Exportation (dump) de la base de données..."
echo "   + dans le fichier : $NOMDUFICHIER"
echo "   + de la base de données : $DATABASE"
echo
/usr/bin/pg_dump --host localhost --port 5432 -E UTF-8 --format plain --verbose --username "odoo"  --format plain  --file $NOMDUFICHIER $DATABASE 2>>/home/flooder/Programmes/log/odoo.db.backup.quotidien.log

chown flooder:flooder /home/flooder/Programmes/log/odoo.db.backup.quotidien.log
chmod 755 /home/flooder/Programmes/log/odoo.db.backup.quotidien.log
chown flooder:flooder $NOMDUFICHIER
chmod 755 $NOMDUFICHIER

echo
echo "5) Création d'une nouvelle base de données..."
if [[ `psql -U odoo -d postgres -tAc "SELECT 1 FROM pg_database WHERE datname='$NEWDB' " ` == "1" ]]
then
    echo "   + $NEWDB existe déjà. Nous allons la détruire."
        MESSAGE=$(/usr/bin/dropdb -U "odoo" --echo --port 5432  $NEWDB 2>>/home/flooder/Programmes/log/odoo.db.backup.quotidien.log)
        echo "   + message de la destruction : $MESSAGE" 
else
        echo "   + $NEWDB n'existe pas. Nous allons la créer."

     #2>>/home/flooder/Programmes/log/odoo.db.backup.quotidien.log
     
fi
        echo "   + création de la nouvelle base de données : $NEWDB"
        /usr/bin/createdb --encoding=UTF-8 -U "odoo" $NEWDB 2>>/home/flooder/Programmes/log/odoo.db.backup.quotidien.log
echo 


echo "6) Importation des données dans la nouvelle base de données..."
echo "   + du fichier : $NOMDUFICHIER"
echo "   + dans la base de données : $NEWDB"

/usr/bin/psql -U odoo $NEWDB < $NOMDUFICHIER 2>>/home/flooder/Programmes/log/odoo.db.backup.quotidien.log


echo
#2>>/home/flooder/Programmes/log/odoo.db.backup.quotidien.log
echo

echo "7) Redémarrage Odoo"
/home/flooder/Programmes/RestartOdoo.sh


echo "8) Envoi du courriel de confirmation"


FILESIZE=$( stat -c %s /home/flooder/Programmes/log/odoo.db.backup.quotidien.log)
echo "   + le fichier journal à envoyer à une taille : $FILESIZE octets"
sendEmail -f pt@lapagept.com -t pt@lapagept.com -u "Sync PT - quotidien - Odoo" -m "Synchronisation de Odoo terminee." -s mail.lapagept.com:26 -xu pt@lapagept.com -xp einegeineg25$ -a /home/flooder/Programmes/log/odoo.db.backup.quotidien.log
exit

0

zbik

--zbik--
5941
| 6 4 7
Lodz, Poland
--zbik--


zbik
On 12/11/14, 9:45 AM

My suggestion is to use the standard package in Ubuntu - autopostgresqlbackup.

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!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 12/11/14, 9:00 AM
Seen: 1699 times
Last updated: 3/16/15, 8:10 AM