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.

0

Automate Odoo V8 Databases Backup

By
Ayham
on 9/2/15, 2:32 AM 774 views

I know that there is a module for auto backup and it was work well for me but know it makes issues with the Pysftp since Odoo with the new updates not recognize that Pysftp is installed so that I decided to make a script for automating backing up on Ubuntu Server.

This is my script:


# Backup script starts here.

#To stop Odoo service

sudo service odoo stop

#!/bin/bash

# Location of the backup logfile.

logfile="/var/odoo/log/logfile.log"

# Location to place backups.

backup_dir="/var/odoo/backups"

touch $logfile

timeslot=`date +%d-%m-%y-%H-%M-%S`

databases=`psql -U postgres -q -c "\l" | awk '{ print $1}' | grep -vE '^\||^-|^List|^Name|template[0|1]|^\('`

for i in $databases; do

timeinfo=`date '+%T %x'`

echo "Backup and Vacuum started at $timeinfo for time slot $timeslot on database: $i " >> $logfile

/usr/bin/vacuumdb -z -U postegres $i >/dev/null 2>&1

/usr/bin/pg_dump $i --port 5432 -U postgres --format=c --blobs --verbose | gzip > "$backup_dir/odoo-$i-$timeslot-database.gz"

timeinfo=`date '+%T %x'`

echo "Backup and Vacuum complete at $timeinfo for time slot $timeslot on database: $i " >> $logfile

done

#-------------------------------------------------

# delete backups more than 30 days old

find $backup_dir/Odoo* -mtime +30 -exec rm {} \;

#To start Odoo service

sudo service odoo start


#END


This script is making backups for all existing databases, but when try to restore any of them it gives me that restore unsuccessful, and when try to restore them by pg_restore command it gives me that the archive is not correct.

The backup file that generated from the web manager backup tool consist of several files but the backup that generated by pg_dump consist from only one file.

Any one can help! 

I tryed to install the auto_backup modul. I have installed the pysftp but when I'm adding the auto_backup module, it says: Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/werkzeug/serving.py", line 177, in run_wsgi execute(self.server.app) File "/usr/lib/python2.7/dist-packages/werkzeug/serving.py", line 165, in execute application_iter = app(environ, start_response) File "/usr/lib/python2.7/dist-packages/openerp/service/server.py", line 290, in app return self.app(e, s) File "/usr/lib/python2.7/dist-packages/openerp/service/wsgi_server.py", line 216, in application return application_unproxied(environ, start_response) File "/usr/lib/python2.7/dist-packages/openerp/service/wsgi_server.py", line 202, in application_unproxied result = handler(environ, start_response) File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 1289, in __call__ self.load_addons() File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 1310, in load_addons m = __import__('openerp.addons.' + module) File "/usr/lib/python2.7/dist-packages/openerp/modules/module.py", line 80, in load_module mod = imp.load_module('openerp.addons.' + module_part, f, path, descr) File "/opt/custom_addons/auto_backup/__init__.py", line 23, in import backup_scheduler File "/opt/custom_addons/auto_backup/backup_scheduler.py", line 33, in raise ImportError('This module needs pysftp to automaticly write backups to the FTP through SFTP. Please install pysftp on your system. (sudo pip install pysftp)') ImportError: This module needs pysftp to automaticly write backups to the FTP through SFTP. Please install pysftp on your system. (sudo pip install pysftp)

wizardz
on 11/19/15, 3:33 AM
1
Andre de Kock
On 9/2/15, 6:59 AM

If you make backups, the best way to do it, I've found, is:

pg_dump --host=$HOST_A --username=$USER_A --verbose $DB_NAME > /tmp/$DB_NAME.backup

And to restore:

createdb --host=$HOST_B --username=$USER_B $DB_NAME

psql --host=$HOST_B --username=$USER_B $DB_NAME < /tmp/$DB_NAME.backup

@Keng Onn:

I solved this by ensuring that any files uploaded to Odoo (any ir.attachment) is stored in the database. You do this by setting an ir.config_parameter called "ir_attachment.location" to "db". The default value is "file" which means that Odoo will by default store ir.attachment objects in the filestore.

thanks for illustrating how you solve this :), but how do you tackle the filestore issue? as in, how to restore other stuff that is not stored in the DB? As well as meta-info such as the modules installed, etc?

Keng Onn
on 9/27/15, 10:55 AM

@Keng Onn: see updated anwer

Limitless Virtual Enterprise, Andre de Kock
on 9/28/15, 1:08 AM
0
Ayham
On 9/2/15, 4:40 PM

#Andre

Dear, I tested the commands, but when making restore the database not appeared    in the web manager page.


#Ahmed

Yes dear I checked the mentioned link before, all mentioned methods in the scripts have issues

0

Ahmed M.Elmubarak

--Ahmed M.Elmubarak--
2988
| 5 3 5
Sudan
--Ahmed M.Elmubarak--


Ahmed M.Elmubarak
On 9/2/15, 7:16 AM

Dear Ayham,

Kindly check this link , if you didn't already ...

Kind Regards,


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

1 follower(s)

Stats

Asked: 9/2/15, 2:32 AM
Seen: 774 times
Last updated: 11/19/15, 3:33 AM