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)