Skip to Content
Menu
This question has been flagged
3 Replies
3966 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! 

Avatar
Discard

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)

Best Answer

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.

Avatar
Discard

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: see updated anwer

Author Best Answer

#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

Avatar
Discard
Best Answer

Dear Ayham,

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

Kind Regards,


Avatar
Discard
Related Posts Replies Views Activity
16
Sep 20
20286
3
Sep 17
2210
2
Feb 16
2990
1
Mar 19
4144
1
Aug 15
6073