opt app_auto_backup V16.0

This commit is contained in:
Chill
2024-05-22 16:37:56 +08:00
parent a6fb463454
commit fdcbc64c5d
3 changed files with 11 additions and 7 deletions

View File

@@ -31,7 +31,8 @@
# any module necessary for this one to work correctly # any module necessary for this one to work correctly
'depends': [ 'depends': [
'base' 'base',
'app_odoo_customize'
], ],
'external_dependencies': { 'external_dependencies': {
'python': ['paramiko'], 'python': ['paramiko'],

View File

@@ -137,17 +137,17 @@ class DbBackup(models.Model):
fp = open(file_path, 'wb') fp = open(file_path, 'wb')
self._take_dump(rec.name, fp, 'db.backup', rec.backup_type) self._take_dump(rec.name, fp, 'db.backup', rec.backup_type)
fp.close() fp.close()
self.backup_details_ids.create({ rec.backup_details_ids.create({
'name': bkp_file, 'name': bkp_file,
'file_path': file_path, 'file_path': file_path,
'url': '/download/backupfile/%s' % file_path, 'url': '/download/backupfile/%s' % file_path,
'db_backup_id': rec.id, 'db_backup_id': rec.id,
}) })
except Exception as error: except Exception as error:
_logger.debug( _logger.warning(
"Couldn't backup database %s. Bad database administrator password for server running at " "Couldn't backup database %s. Bad database administrator password for server running at "
"http://%s:%s" % (rec.name, rec.host, rec.port)) "http://%s:%s" % (rec.name, rec.host, rec.port))
_logger.debug("Exact error from the exception: %s", str(error)) _logger.warning("Exact error from the exception: %s", str(error))
continue continue
# Check if user wants to write to SFTP or not. # Check if user wants to write to SFTP or not.
@@ -270,7 +270,9 @@ class DbBackup(models.Model):
if os.path.isfile(fullpath) and (".dump" in f or '.zip' in f): if os.path.isfile(fullpath) and (".dump" in f or '.zip' in f):
_logger.info("Delete local out-of-date file: %s", fullpath) _logger.info("Delete local out-of-date file: %s", fullpath)
backup_details_id = self.env['db.backup.details'].search([('file_path', '=', fullpath)]) backup_details_id = self.env['db.backup.details'].search([('file_path', '=', fullpath)])
if backup_details_id:
backup_details_id.unlink() backup_details_id.unlink()
else:
os.remove(fullpath) os.remove(fullpath)
# This is more or less the same as the default Odoo function at # This is more or less the same as the default Odoo function at

View File

@@ -2,7 +2,8 @@
import os import os
from odoo import api, fields, models from odoo import api, fields, models, _
from odoo.exceptions import AccessError, UserError
class DbBackupDetails(models.Model): class DbBackupDetails(models.Model):