???
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project
- MRP
This question has been flagged
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
My suggestion is to use the standard package in Ubuntu - autopostgresqlbackup.
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
2
Mar 15
|
5314 | ||
|
2
Dec 17
|
4953 | ||
|
0
Mar 15
|
4157 | ||
|
2
Dec 24
|
669 | ||
|
1
Nov 23
|
3423 |