Browse Source

bug logger --> _logger call [FIX] Flake8 [RM] useless files

pull/636/head
archetipo 9 years ago
committed by Dave Lasley
parent
commit
247ee1cf2f
  1. 2
      auto_backup/README.rst
  2. 2
      auto_backup/data/backup_data.xml
  3. 157
      auto_backup/i18n/ca.po
  4. 141
      auto_backup/i18n/fr_BE.po
  5. 2
      auto_backup/model/__init__.py
  6. 238
      auto_backup/model/backup_scheduler.py
  7. 52
      auto_backup/view/bkp_conf_view.xml

2
auto_backup/README.rst

@ -71,7 +71,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/{project_repo}/issues>`_. Bugs are tracked on `GitHub Issues <https://github.com/OCA/{project_repo}/issues>`_.
In case of trouble, please check there if your issue has already been reported. In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback If you spotted it first, help us smashing it by providing a detailed and welcomed feedback
`here <https://github.com/OCA/{project_repo}/issues/new?body=module:%20{module_name}%0Aversion:%20{version}%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`here <https://github.com/OCA/server-tools/issues/new?body=module:%20auto_backup%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Credits Credits

2
auto_backup/data/backup_data.xml

@ -7,7 +7,7 @@
<field name="user_id" ref="base.user_root"/> <field name="user_id" ref="base.user_root"/>
<field eval="&quot;&quot;&quot;Backup scheduler&quot;&quot;&quot;" name="name"/> <field eval="&quot;&quot;&quot;Backup scheduler&quot;&quot;&quot;" name="name"/>
<field eval="-1" name="numbercall"/> <field eval="-1" name="numbercall"/>
<field eval="&quot;&quot;&quot;2010-01-07 11:35:28&quot;&quot;&quot;" name="nextcall"/>
<field eval="&quot;&quot;&quot;2015-07-07 11:35:28&quot;&quot;&quot;" name="nextcall"/>
<field eval="5" name="priority"/> <field eval="5" name="priority"/>
<field eval="0" name="doall"/> <field eval="0" name="doall"/>
<field eval="False" name="active"/> <field eval="False" name="active"/>

157
auto_backup/i18n/ca.po

@ -1,157 +0,0 @@
# Catalan translation for openobject-addons
# Copyright (c) 2014 Rosetta Contributors and Canonical Ltd 2014
# This file is distributed under the same license as the openobject-addons package.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2014.
#
msgid ""
msgstr ""
"Project-Id-Version: openobject-addons\n"
"Report-Msgid-Bugs-To: FULL NAME <EMAIL@ADDRESS>\n"
"POT-Creation-Date: 2009-11-24 13:49+0000\n"
"PO-Revision-Date: 2014-10-20 06:41+0000\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: Catalan <ca@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Launchpad-Export-Date: 2014-10-21 06:30+0000\n"
"X-Generator: Launchpad (build 17203)\n"
#. module: auto_backup
#: help:db.backup,name:0
msgid "Database you want to schedule backups for"
msgstr ""
#. module: auto_backup
#: constraint:ir.model:0
msgid ""
"The Object name must start with x_ and not contain any special character !"
msgstr ""
#. module: auto_backup
#: constraint:ir.actions.act_window:0
msgid "Invalid model name in the action definition."
msgstr ""
#. module: auto_backup
#: model:ir.model,name:auto_backup.model_db_backup
msgid "db.backup"
msgstr ""
#. module: auto_backup
#: view:db.backup:0
msgid ""
"1) Go to Administration / Configuration / Scheduler / Scheduled Actions"
msgstr ""
#. module: auto_backup
#: model:ir.actions.act_window,name:auto_backup.action_backup_conf_form
#: model:ir.ui.menu,name:auto_backup.backup_conf_menu
msgid "Configure Backup"
msgstr ""
#. module: auto_backup
#: view:db.backup:0
msgid "Test"
msgstr ""
#. module: auto_backup
#: view:db.backup:0
msgid "IP Configuration"
msgstr ""
#. module: auto_backup
#: help:db.backup,bkp_dir:0
msgid "Absolute path for storing the backups"
msgstr ""
#. module: auto_backup
#: model:ir.module.module,shortdesc:auto_backup.module_meta_information
msgid "Database Auto-Backup"
msgstr ""
#. module: auto_backup
#: view:db.backup:0
msgid "Database Configuration"
msgstr ""
#. module: auto_backup
#: view:db.backup:0
msgid "4) Set other values as per your preference"
msgstr ""
#. module: auto_backup
#: field:db.backup,host:0
msgid "Host"
msgstr ""
#. module: auto_backup
#: view:db.backup:0
msgid ""
"Automatic backup of all the databases under this can be scheduled as "
"follows: "
msgstr ""
#. module: auto_backup
#: constraint:ir.ui.view:0
msgid "Invalid XML for View Architecture!"
msgstr ""
#. module: auto_backup
#: field:db.backup,bkp_dir:0
msgid "Backup Directory"
msgstr ""
#. module: auto_backup
#: field:db.backup,name:0
msgid "Database"
msgstr ""
#. module: auto_backup
#: view:db.backup:0
msgid "2) Schedule new action(create a new record)"
msgstr ""
#. module: auto_backup
#: model:ir.module.module,description:auto_backup.module_meta_information
msgid ""
"The generic Open ERP Database Auto-Backup system enables the user to make "
"configurations for the automatic backup of the database.\n"
"User simply requires to specify host & port under IP Configuration & "
"database(on specified host running at specified port) and backup "
"directory(in which all the backups of the specified database will be stored) "
"under Database Configuration.\n"
"\n"
"Automatic backup for all such configured databases under this can then be "
"scheduled as follows: \n"
" \n"
"1) Go to Administration / Configuration / Scheduler / Scheduled Actions\n"
"2) Schedule new action(create a new record)\n"
"3) Set 'Object' to 'db.backup' and 'Function' to 'schedule_backup' under "
"page 'Technical Data'\n"
"4) Set other values as per your preference"
msgstr ""
#. module: auto_backup
#: view:db.backup:0
msgid ""
"3) Set 'Object' to 'db.backup' and 'Function' to 'schedule_backup' under "
"page 'Technical Data'"
msgstr ""
#. module: auto_backup
#: view:db.backup:0
msgid "Help"
msgstr ""
#. module: auto_backup
#: view:db.backup:0
msgid ""
"This configures the scheduler for automatic backup of the given database "
"running on given host at given port on regular intervals."
msgstr ""
#. module: auto_backup
#: field:db.backup,port:0
msgid "Port"
msgstr ""

141
auto_backup/i18n/fr_BE.po

@ -1,141 +0,0 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * auto_backup
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 5.0.6\n"
"Report-Msgid-Bugs-To: support@openerp.com\n"
"POT-Creation-Date: 2009-11-24 13:49:51+0000\n"
"PO-Revision-Date: 2009-11-24 13:49:51+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: auto_backup
#: help:db.backup,name:0
msgid "Database you want to schedule backups for"
msgstr ""
#. module: auto_backup
#: constraint:ir.model:0
msgid "The Object name must start with x_ and not contain any special character !"
msgstr ""
#. module: auto_backup
#: constraint:ir.actions.act_window:0
msgid "Invalid model name in the action definition."
msgstr ""
#. module: auto_backup
#: model:ir.model,name:auto_backup.model_db_backup
msgid "db.backup"
msgstr ""
#. module: auto_backup
#: view:db.backup:0
msgid "1) Go to Administration / Configuration / Scheduler / Scheduled Actions"
msgstr ""
#. module: auto_backup
#: model:ir.actions.act_window,name:auto_backup.action_backup_conf_form
#: model:ir.ui.menu,name:auto_backup.backup_conf_menu
msgid "Configure Backup"
msgstr ""
#. module: auto_backup
#: view:db.backup:0
msgid "Test"
msgstr ""
#. module: auto_backup
#: view:db.backup:0
msgid "IP Configuration"
msgstr ""
#. module: auto_backup
#: help:db.backup,bkp_dir:0
msgid "Absolute path for storing the backups"
msgstr ""
#. module: auto_backup
#: model:ir.module.module,shortdesc:auto_backup.module_meta_information
msgid "Database Auto-Backup"
msgstr ""
#. module: auto_backup
#: view:db.backup:0
msgid "Database Configuration"
msgstr ""
#. module: auto_backup
#: view:db.backup:0
msgid "4) Set other values as per your preference"
msgstr ""
#. module: auto_backup
#: field:db.backup,host:0
msgid "Host"
msgstr ""
#. module: auto_backup
#: view:db.backup:0
msgid "Automatic backup of all the databases under this can be scheduled as follows: "
msgstr ""
#. module: auto_backup
#: constraint:ir.ui.view:0
msgid "Invalid XML for View Architecture!"
msgstr ""
#. module: auto_backup
#: field:db.backup,bkp_dir:0
msgid "Backup Directory"
msgstr ""
#. module: auto_backup
#: field:db.backup,name:0
msgid "Database"
msgstr ""
#. module: auto_backup
#: view:db.backup:0
msgid "2) Schedule new action(create a new record)"
msgstr ""
#. module: auto_backup
#: model:ir.module.module,description:auto_backup.module_meta_information
msgid "The generic Open ERP Database Auto-Backup system enables the user to make configurations for the automatic backup of the database.\n"
"User simply requires to specify host & port under IP Configuration & database(on specified host running at specified port) and backup directory(in which all the backups of the specified database will be stored) under Database Configuration.\n"
"\n"
"Automatic backup for all such configured databases under this can then be scheduled as follows: \n"
" \n"
"1) Go to Administration / Configuration / Scheduler / Scheduled Actions\n"
"2) Schedule new action(create a new record)\n"
"3) Set 'Object' to 'db.backup' and 'Function' to 'schedule_backup' under page 'Technical Data'\n"
"4) Set other values as per your preference"
msgstr ""
#. module: auto_backup
#: view:db.backup:0
msgid "3) Set 'Object' to 'db.backup' and 'Function' to 'schedule_backup' under page 'Technical Data'"
msgstr ""
#. module: auto_backup
#: view:db.backup:0
msgid "Help"
msgstr ""
#. module: auto_backup
#: view:db.backup:0
msgid "This configures the scheduler for automatic backup of the given database running on given host at given port on regular intervals."
msgstr ""
#. module: auto_backup
#: field:db.backup,port:0
msgid "Port"
msgstr ""

2
auto_backup/model/__init__.py

@ -20,4 +20,4 @@
# #
############################################################################## ##############################################################################
import backup_scheduler
from . import backup_scheduler

238
auto_backup/model/backup_scheduler.py

@ -1,6 +1,5 @@
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-
############################################################################## ##############################################################################
#
# OpenERP, Open Source Management Solution # OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# $Id$ # $Id$
@ -19,7 +18,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################## ##############################################################################
import xmlrpclib import xmlrpclib
import socket import socket
import os import os
@ -30,24 +28,29 @@ import re
try: try:
import pysftp import pysftp
except ImportError: except ImportError:
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)')
from openerp.osv import fields,osv,orm
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)'
)
from openerp.osv import fields, osv
from openerp import tools from openerp import tools
from openerp import netsvc
from openerp import tools, _
from openerp import netsvc, _
import logging import logging
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
def execute(connector, method, *args): def execute(connector, method, *args):
res = False res = False
try: try:
res = getattr(connector, method)(*args) res = getattr(connector, method)(*args)
except socket.error,e:
except socket.error as e:
raise e raise e
return res return res
addons_path = tools.config['addons_path'] + '/auto_backup/DBbackups' addons_path = tools.config['addons_path'] + '/auto_backup/DBbackups'
class db_backup(osv.Model): class db_backup(osv.Model):
_name = 'db.backup' _name = 'db.backup'
@ -60,7 +63,7 @@ class db_backup(osv.Model):
return db_list return db_list
def _get_db_name(self, cr, uid, vals, context=None): def _get_db_name(self, cr, uid, vals, context=None):
attach_pool = self.pool.get("ir.logging")
# attach_pool = self.pool.get("ir.logging")
dbName = cr.dbname dbName = cr.dbname
return dbName return dbName
@ -68,21 +71,93 @@ class db_backup(osv.Model):
# Columns local server # Columns local server
'host': fields.char('Host', size=100, required='True'), 'host': fields.char('Host', size=100, required='True'),
'port': fields.char('Port', size=10, required='True'), 'port': fields.char('Port', size=10, required='True'),
'name' : fields.char('Database', size=100, required='True',help='Database you want to schedule backups for'),
'bkp_dir' : fields.char('Backup Directory', size=100, help='Absolute path for storing the backups', required='True'),
'autoremove': fields.boolean('Auto. Remove Backups', help="If you check this option you can choose to automaticly remove the backup after xx days"),
'daystokeep': fields.integer('Remove after x days',
help="Choose after how many days the backup should be deleted. For example:\nIf you fill in 5 the backups will be removed after 5 days.",required=True),
'name': fields.char(
'Database', size=100, required='True',
help='Database you want to schedule backups for'
),
'bkp_dir': fields.char(
'Backup Directory', size=100,
help='Absolute path for storing the backups',
required='True'
),
'autoremove': fields.boolean(
'Auto. Remove Backups',
help=(
"If you check this option you can choose to "
"automaticly remove the backup after xx days"
)
),
'daystokeep': fields.integer(
'Remove after x days',
help=(
"Choose after how many days the backup should be "
"deleted. For example:\nIf you fill in 5 the backups "
"will be removed after 5 days."
), required=True
),
# Columns for external server (SFTP) # Columns for external server (SFTP)
'sftpwrite': fields.boolean('Write to external server with sftp', help="If you check this option you can specify the details needed to write to a remote server with SFTP."),
'sftppath': fields.char('Path external server', help="The location to the folder where the dumps should be written to. For example /odoo/backups/.\nFiles will then be written to /odoo/backups/ on your remote server."),
'sftpip': fields.char('IP Address SFTP Server', help="The IP address from your remote server. For example 192.168.0.1"),
'sftpport': fields.integer("SFTP Port", help="The port on the FTP server that accepts SSH/SFTP calls."),
'sftpusername': fields.char('Username SFTP Server', help="The username where the SFTP connection should be made with. This is the user on the external server."),
'sftppassword': fields.char('Password User SFTP Server', help="The password from the user where the SFTP connection should be made with. This is the password from the user on the external server."),
'daystokeepsftp': fields.integer('Remove SFTP after x days', help="Choose after how many days the backup should be deleted from the FTP server. For example:\nIf you fill in 5 the backups will be removed after 5 days from the FTP server."),
'sendmailsftpfail': fields.boolean('Auto. E-mail on backup fail', help="If you check this option you can choose to automaticly get e-mailed when the backup to the external server failed."),
'emailtonotify': fields.char('E-mail to notify', help="Fill in the e-mail where you want to be notified that the backup failed on the FTP."),
'sftpwrite': fields.boolean(
'Write to external server with sftp',
help=(
"If you check this option you can specify the details "
"needed to write to a remote server with SFTP."
)
),
'sftppath': fields.char(
'Path external server',
help=(
"The location to the folder where the dumps should be "
"written to. For example /odoo/backups/.\nFiles will then"
" be written to /odoo/backups/ on your remote server."
)
),
'sftpip': fields.char(
'IP Address SFTP Server',
help=(
"The IP address from your remote"
" server. For example 192.168.0.1"
)
),
'sftpport': fields.integer(
"SFTP Port",
help="The port on the FTP server that accepts SSH/SFTP calls."
),
'sftpusername': fields.char(
'Username SFTP Server',
help=(
"The username where the SFTP connection "
"should be made with. This is the user on the external server."
)
),
'sftppassword': fields.char(
'Password User SFTP Server',
help=(
"The password from the user where the SFTP connection "
"should be made with. This is the password from the user"
" on the external server."
)
),
'daystokeepsftp': fields.integer(
'Remove SFTP after x days',
help=(
"Choose after how many days the backup should be deleted "
"from the FTP server. For example:\nIf you fill in 5 the "
"backups will be removed after 5 days from the FTP server."
)
),
'sendmailsftpfail': fields.boolean(
'Auto. E-mail on backup fail', help=(
"If you check this option you can choose to automaticly"
" get e-mailed when the backup to the external server failed."
)
),
'emailtonotify': fields.char(
'E-mail to notify',
help=(
"Fill in the e-mail where you want to be"
" notified that the backup failed on the FTP."
)
),
} }
_defaults = { _defaults = {
@ -106,7 +181,6 @@ class db_backup(osv.Model):
(_check_db_exist, _('Error ! No such database exists!'), []) (_check_db_exist, _('Error ! No such database exists!'), [])
] ]
def test_sftp_connection(self, cr, uid, ids, context=None): def test_sftp_connection(self, cr, uid, ids, context=None):
conf_ids = self.search(cr, uid, []) conf_ids = self.search(cr, uid, [])
confs = self.browse(cr, uid, conf_ids) confs = self.browse(cr, uid, conf_ids)
@ -114,27 +188,33 @@ class db_backup(osv.Model):
messageTitle = "" messageTitle = ""
messageContent = "" messageContent = ""
for rec in confs: for rec in confs:
db_list = self.get_db_list(cr, uid, [], rec.host, rec.port)
# db_list = self.get_db_list(cr, uid, [], rec.host, rec.port)
try: try:
pathToWriteTo = rec.sftppath
# pathToWriteTo = rec.sftppath
ipHost = rec.sftpip ipHost = rec.sftpip
portHost = rec.sftpport portHost = rec.sftpport
usernameLogin = rec.sftpusername usernameLogin = rec.sftpusername
passwordLogin = rec.sftppassword passwordLogin = rec.sftppassword
#Connect with external server over SFTP, so we know sure that everything works.
# Connect with external server over SFTP, so we know sure that
# everything works.
srv = pysftp.Connection(host=ipHost, username=usernameLogin, srv = pysftp.Connection(host=ipHost, username=usernameLogin,
password=passwordLogin, port=portHost) password=passwordLogin, port=portHost)
srv.close() srv.close()
# We have a success. # We have a success.
messageTitle = "Connection Test Succeeded!"
messageContent = "Everything seems properly set up for FTP back-ups!"
except Exception, e:
messageTitle = "Connection Test Failed!"
messageTitle = _("Connection Test Succeeded!")
messageContent = _(
"Everything seems properly set up for FTP back-ups!")
except Exception as e:
messageTitle = _("Connection Test Failed!")
if len(rec.sftpip) < 8: if len(rec.sftpip) < 8:
messageContent += "\nYour IP address seems to be too short.\n"
messageContent += _(
"\nYour IP address seems to be too short.\n")
messageContent += "Here is what we got instead:\n" messageContent += "Here is what we got instead:\n"
if "Failed" in messageTitle: if "Failed" in messageTitle:
raise osv.except_osv(_(messageTitle), _(messageContent + "%s") % tools.ustr(e))
raise osv.except_osv(
_(messageTitle), _(
messageContent + "%s") %
tools.ustr(e))
else: else:
raise osv.except_osv(_(messageTitle), _(messageContent)) raise osv.except_osv(_(messageTitle), _(messageContent))
@ -150,22 +230,41 @@ password=passwordLogin,port=portHost)
except: except:
raise raise
# Create name for dumpfile. # Create name for dumpfile.
bkp_file='%s_%s.dump' % (time.strftime('%d_%m_%Y_%H_%M_%S'),rec.name)
bkp_file = '%s_%s.dump' % (
time.strftime('%d_%m_%Y_%H_%M_%S'),
rec.name)
file_path = os.path.join(rec.bkp_dir, bkp_file) file_path = os.path.join(rec.bkp_dir, bkp_file)
uri = 'http://' + rec.host + ':' + rec.port uri = 'http://' + rec.host + ':' + rec.port
conn = xmlrpclib.ServerProxy(uri + '/xmlrpc/db') conn = xmlrpclib.ServerProxy(uri + '/xmlrpc/db')
bkp = '' bkp = ''
try: try:
bkp = execute(conn, 'dump', tools.config['admin_passwd'], rec.name)
bkp = execute(
conn,
'dump',
tools.config['admin_passwd'],
rec.name)
except: except:
<<<<<<< HEAD
logger.notifyChannel('backup', netsvc.LOG_INFO, "Could'nt backup database %s. Bad database administrator password for server running at http://%s:%s" %(rec.name, rec.host, rec.port)) logger.notifyChannel('backup', netsvc.LOG_INFO, "Could'nt backup database %s. Bad database administrator password for server running at http://%s:%s" %(rec.name, rec.host, rec.port))
=======
_logger.notifyChannel(
'backup', netsvc.LOG_INFO,
_(
"Couldn't backup database %s. "
"Bad database administrator"
"password for server running at http://%s:%s"
) % (rec.name, rec.host, rec.port))
>>>>>>> f331fab... [FIX] bug logger --> _logger call
continue continue
bkp = base64.decodestring(bkp) bkp = base64.decodestring(bkp)
fp = open(file_path, 'wb') fp = open(file_path, 'wb')
fp.write(bkp) fp.write(bkp)
fp.close() fp.close()
else: else:
logger.notifyChannel('backup', netsvc.LOG_INFO, "database %s doesn't exist on http://%s:%s" %(rec.name, rec.host, rec.port))
_logger.notifyChannel(
'backup', netsvc.LOG_INFO,
"database %s doesn't exist on http://%s:%s" %
(rec.name, rec.host, rec.port))
# Check if user wants to write to SFTP or not. # Check if user wants to write to SFTP or not.
if rec.sftpwrite is True: if rec.sftpwrite is True:
@ -178,9 +277,14 @@ password=passwordLogin,port=portHost)
usernameLogin = rec.sftpusername usernameLogin = rec.sftpusername
passwordLogin = rec.sftppassword passwordLogin = rec.sftppassword
# Connect with external server over SFTP # Connect with external server over SFTP
srv = pysftp.Connection(host=ipHost, username=usernameLogin,
password=passwordLogin, port=portHost)
#Move to the correct directory on external server. If the user made a typo in his path with multiple slashes (/odoo//backups/) it will be fixed by this regex.
srv = pysftp.Connection(
host=ipHost,
username=usernameLogin,
password=passwordLogin,
port=portHost)
# Move to the correct directory on external server. If the
# user made a typo in his path with multiple slashes
# (/odoo//backups/) it will be fixed by this regex.
pathToWriteTo = re.sub('([/]{2,5})+', '/', pathToWriteTo) pathToWriteTo = re.sub('([/]{2,5})+', '/', pathToWriteTo)
print(pathToWriteTo) print(pathToWriteTo)
try: try:
@ -193,7 +297,12 @@ password=passwordLogin, port=portHost)
try: try:
srv.chdir(currentDir) srv.chdir(currentDir)
except: except:
print('(Part of the) path didn\'t exist. Creating it now at ' + currentDir)
_logger.info(
_(
'(Part of the) path didn\'t exist. '
'Creating it now at %s'
) % currentDir
)
# Make directory and then navigate into it # Make directory and then navigate into it
srv.mkdir(currentDir, mode=777) srv.mkdir(currentDir, mode=777)
srv.chdir(currentDir) srv.chdir(currentDir)
@ -214,12 +323,15 @@ password=passwordLogin, port=portHost)
for file in srv.listdir(pathToWriteTo): for file in srv.listdir(pathToWriteTo):
# Get the full path # Get the full path
fullpath = os.path.join(pathToWriteTo, file) fullpath = os.path.join(pathToWriteTo, file)
#Get the timestamp from the file on the external server
# Get the timestamp from the file on the external
# server
timestamp = srv.stat(fullpath).st_atime timestamp = srv.stat(fullpath).st_atime
createtime = datetime.datetime.fromtimestamp(timestamp) createtime = datetime.datetime.fromtimestamp(timestamp)
now = datetime.datetime.now() now = datetime.datetime.now()
delta = now - createtime delta = now - createtime
#If the file is older than the daystokeepsftp (the days to keep that the user filled in on the Odoo form it will be removed.
# If the file is older than the daystokeepsftp (the
# days to keep that the user filled in on the Odoo form
# it will be removed.
if delta.days >= rec.daystokeepsftp: if delta.days >= rec.daystokeepsftp:
# Only delete files, no directories! # Only delete files, no directories!
if srv.isfile(fullpath) and ".dump" in file: if srv.isfile(fullpath) and ".dump" in file:
@ -227,15 +339,34 @@ password=passwordLogin, port=portHost)
srv.unlink(file) srv.unlink(file)
# Close the SFTP session. # Close the SFTP session.
srv.close() srv.close()
except Exception, e:
_logger.debug('Exception! We couldn\'t back up to the FTP server..')
#At this point the SFTP backup failed. We will now check if the user wants
except Exception as e:
_logger.debug(
'Exception! We couldn\'t back '
'up to the FTP server..'
)
# At this point the SFTP backup failed.
# We will now check if the user wants
# an e-mail notification about this. # an e-mail notification about this.
if rec.sendmailsftpfail: if rec.sendmailsftpfail:
try: try:
ir_mail_server = self.pool.get('ir.mail_server') ir_mail_server = self.pool.get('ir.mail_server')
message = "Dear,\n\nThe backup for the server " + rec.host + " (IP: " + rec.sftpip + ") failed.Please check the following details:\n\nIP address SFTP server: " + rec.sftpip + "\nUsername: " + rec.sftpusername + "\nPassword: " + rec.sftppassword + "\n\nError details: " + tools.ustr(e) + "\n\nWith kind regards"
msg = ir_mail_server.build_email("auto_backup@" + rec.name + ".com", [rec.emailtonotify], "Backup from " + rec.host + "(" + rec.sftpip + ") failed", message)
message = (
"Dear,\n\nThe backup for the server %s"
" (IP: %s) failed.Please check"
" the following details:\n\n"
"IP address SFTP server: %s \nUsername: %s"
"\nPassword: %s"
"\n\nError details: %s \n\nWith kind regards"
) % (
rec.host, rec.sftpip, rec.sftpip,
rec.sftpusername, rec.sftppassword,
tools.ustr(e)
)
msg = ir_mail_server.build_email(
"auto_backup@" + rec.name + ".com",
[rec.emailtonotify],
"Backup from " + rec.host + "(" + rec.sftpip +
") failed", message)
ir_mail_server.send_email(cr, user, msg) ir_mail_server.send_email(cr, user, msg)
except Exception: except Exception:
pass pass
@ -243,9 +374,14 @@ password=passwordLogin, port=portHost)
"""Remove all old files (on local server) in case this is configured.. """Remove all old files (on local server) in case this is configured..
This is done after the SFTP writing to prevent unusual behaviour: This is done after the SFTP writing to prevent unusual behaviour:
If the user would set local back-ups to be kept 0 days and the SFTP If the user would set local back-ups to be kept 0 days and the SFTP
to keep backups xx days there wouldn't be any new back-ups added to the
SFTP.
If we'd remove the dump files before they're writen to the SFTP there willbe nothing to write. Meaning that if an user doesn't want to keep back-ups locally and only wants them on the SFTP (NAS for example) there wouldn't be any writing to the remote server if this if statement was before the SFTP write method right above this comment.
to keep backups xx days there wouldn't be any new back-ups added
to the SFTP.
If we'd remove the dump files before they're writen to the SFTP
there willbe nothing to write. Meaning that if an user doesn't want
to keep back-ups locally and only wants them on the SFTP
(NAS for example) there wouldn't be any writing to the
remote server if this if statement was before the SFTP write method
right above this comment.
""" """
if rec.autoremove is True: if rec.autoremove is True:
dir = rec.bkp_dir dir = rec.bkp_dir
@ -264,4 +400,8 @@ password=passwordLogin, port=portHost)
db_backup() db_backup()
<<<<<<< HEAD
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
=======
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
>>>>>>> f331fab... [FIX] bug logger --> _logger call

52
auto_backup/view/bkp_conf_view.xml

@ -1,6 +1,7 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<openerp> <openerp>
<data> <data>
<record model="ir.ui.view" id="view_backup_conf_form"> <record model="ir.ui.view" id="view_backup_conf_form">
<field name="name">Configure Backup</field> <field name="name">Configure Backup</field>
<field name="model">db.backup</field> <field name="model">db.backup</field>
@ -17,32 +18,33 @@
<field name="bkp_dir"/> <field name="bkp_dir"/>
<field name="autoremove"/> <field name="autoremove"/>
<field name="daystokeep" attrs="{'invisible': [('autoremove','=',False)]}"/> <field name="daystokeep" attrs="{'invisible': [('autoremove','=',False)]}"/>
</group> </group>
<group col="4" colspan="4"> <group col="4" colspan="4">
<separator col="2" string="SFTP"/> <separator col="2" string="SFTP"/>
</group> </group>
<div style="width:50%;border-radius:10px;margin: 10px 0px;padding:15px 10px 15px 10px;
background-repeat: no-repeat;background-position: 10px center;color: #9F6000;background-color: #FEEFB3;" attrs="{'invisible': [('sftpwrite','=',False)]}"><b>Warning:</b> Use SFTP with caution! This writes files to external servers under the path you specify.</div>
<div
style="width:50%;border-radius:10px;
margin: 10px 0px;
padding:15px 10px 15px 10px;
background-repeat:
no-repeat;background-position: 10px center;
color: #9F6000;background-color: #FEEFB3;"
attrs="{'invisible': [('sftpwrite','=',False)]}">
<b>Warning:</b>
Use SFTP with caution! This writes files to external servers under the path you specify.
</div>
<group> <group>
<field name="sftpwrite"/> <field name="sftpwrite"/>
<field name="sftpip"
attrs="{'invisible':[('sftpwrite', '==', False)],'required':[('sftpwrite', '==', True)]}"/>
<field name="sftpport"
attrs="{'invisible':[('sftpwrite', '==', False)],'required':[('sftpwrite', '==', True)]}"/>
<field name="sftpusername"
attrs="{'invisible':[('sftpwrite', '==', False)],'required':[('sftpwrite', '==', True)]}"/>
<field name="sftppassword"
attrs="{'invisible':[('sftpwrite', '==', False)],'required':[('sftpwrite', '==', True)]}" password="True" />
<field name="sftppath"
attrs="{'invisible':[('sftpwrite', '==', False)],'required':[('sftpwrite', '==', True)]}" placeholder="For example: /odoo/backups/"/>
<field name="daystokeepsftp"
attrs="{'invisible':[('sftpwrite', '==', False)],'required':[('sftpwrite', '==', True)]}"/>
<field name="sftpip" attrs="{'invisible':[('sftpwrite', '==', False)],'required':[('sftpwrite', '==', True)]}"/>
<field name="sftpport" attrs="{'invisible':[('sftpwrite', '==', False)],'required':[('sftpwrite', '==', True)]}"/>
<field name="sftpusername" attrs="{'invisible':[('sftpwrite', '==', False)],'required':[('sftpwrite', '==', True)]}"/>
<field name="sftppassword" attrs="{'invisible':[('sftpwrite', '==', False)],'required':[('sftpwrite', '==', True)]}" password="True"/>
<field name="sftppath" attrs="{'invisible':[('sftpwrite', '==', False)],'required':[('sftpwrite', '==', True)]}" placeholder="For example: /odoo/backups/"/>
<field name="daystokeepsftp" attrs="{'invisible':[('sftpwrite', '==', False)],'required':[('sftpwrite', '==', True)]}"/>
<field name="sendmailsftpfail" attrs="{'invisible': [('sftpwrite','=',False)]}"/> <field name="sendmailsftpfail" attrs="{'invisible': [('sftpwrite','=',False)]}"/>
<field name="emailtonotify" attrs="{'invisible':['|',('sendmailsftpfail', '==', False), <field name="emailtonotify" attrs="{'invisible':['|',('sendmailsftpfail', '==', False),
('sftpwrite', '==', False)],'required':[('sendmailsftpfail', '==', True)]}"/> ('sftpwrite', '==', False)],'required':[('sendmailsftpfail', '==', True)]}"/>
<button name="test_sftp_connection" type="object"
attrs="{'invisible': [('sftpwrite','=',False)]}" string="Test SFTP Connection" icon="gtk-network"/>
<button name="test_sftp_connection" type="object" attrs="{'invisible': [('sftpwrite','=',False)]}" string="Test SFTP Connection" icon="gtk-network"/>
</group> </group>
<separator string="Help" colspan="2"/> <separator string="Help" colspan="2"/>
<div> <div>
@ -50,19 +52,10 @@ background-repeat: no-repeat;background-position: 10px center;color: #9F6000;bac
<br/> <br/>
Automatic backups of the database can be scheduled as follows: Automatic backups of the database can be scheduled as follows:
<ol> <ol>
<li>
Go to Settings / Technical / Automation / Scheduled Actions.
</li>
<li>
Search the action named 'Backup scheduler'.
</li>
<li>
Set the scheduler to active and fill in how often you want backups generated.
</li>
<li>Go to Settings / Technical / Automation / Scheduled Actions.</li>
<li>Search the action named 'Backup scheduler'.</li>
<li>Set the scheduler to active and fill in how often you want backups generated.</li>
</ol> </ol>
<p style="font-size:18px;">
Need more help? <a href="mailto:erp@vanroey.be">Contact us!</a>
</p>
</div> </div>
</form> </form>
</field> </field>
@ -108,5 +101,6 @@ background-repeat: no-repeat;background-position: 10px center;color: #9F6000;bac
<field name='view_id' ref='view_backup_conf_tree'/> <field name='view_id' ref='view_backup_conf_tree'/>
</record> </record>
<menuitem parent="base.menu_config" action="action_backup_conf_form" id="backup_conf_menu"/> <menuitem parent="base.menu_config" action="action_backup_conf_form" id="backup_conf_menu"/>
</data> </data>
</openerp> </openerp>
Loading…
Cancel
Save