diff --git a/auto_backup/__openerp__.py b/auto_backup/__openerp__.py index 751c7d296..f1b3a2842 100644 --- a/auto_backup/__openerp__.py +++ b/auto_backup/__openerp__.py @@ -35,7 +35,6 @@ "data": [ "view/bkp_conf_view.xml", "data/backup_data.xml", - "data/autobackup_mail_template.xml", "security/ir.model.access.csv" ], "active": False, diff --git a/auto_backup/data/autobackup_mail_template.xml b/auto_backup/data/autobackup_mail_template.xml deleted file mode 100644 index f3a2d7858..000000000 --- a/auto_backup/data/autobackup_mail_template.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - Auto Backup Error notification - auto_backup@${object.name} - Backup from ${object.host} - (${object.sftpip}) failed - ${object.emailtonotify} - - - Dear,

- -

The backup for the server ${object.host} (IP: ${object.sftpip}) failed.

-

Please check the following details:

-

IP address SFTP server: ${object.sftpip}

-

Username: ${object.sftpusername}

-

Password: ${object.sftppassword}

-

Error details: ${object.lasterrorlog}

-

With kind regards

- - ]]>
-
- -
-
\ No newline at end of file diff --git a/auto_backup/model/backup_scheduler.py b/auto_backup/model/backup_scheduler.py index a836f559c..f2d5b9c95 100644 --- a/auto_backup/model/backup_scheduler.py +++ b/auto_backup/model/backup_scheduler.py @@ -225,6 +225,7 @@ class db_backup(models.Model): @api.model def schedule_backup(self): + for rec in self.search([]): db_list = self.get_db_list(rec.host, rec.port) if rec.name in db_list: @@ -349,15 +350,31 @@ class db_backup(models.Model): # an e-mail notification about this. if rec.sendmailsftpfail: try: - self.write({'lasterrorlog': tools.ustr(e)}) - abk_template = self.env.ref( - 'auto_backup.' - 'email_template_autobackup_error_noificaiton', - False + ir_mail_server = self.env['ir.mail_server'] + 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@%s.com" % rec.name, + [rec.emailtonotify], + "Backup from %s ( %s ) failed" % ( + rec.host, rec.sftpip), + message) + ir_mail_server.send_email(msg) + + except Exception as e: + _logger.debug( + 'Exception! %s' % tools.ustr(e) ) - abk_template.send_mail(self.id) - except Exception: - pass # Remove all old files (on local server) in case this is configured.. # This is done after the SFTP writing to prevent unusual behaviour: @@ -386,5 +403,3 @@ class db_backup(models.Model): if delta.days >= rec.daystokeep: os.remove(fullpath) return True - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: