mirror of
https://github.com/guohuadeng/app-odoo.git
synced 2025-02-23 04:11:36 +02:00
#I9QR3B app_auto_backup增加从界面下载删除备份库的功能 V17.0
This commit is contained in:
@@ -73,6 +73,7 @@ class DbBackup(models.Model):
|
||||
email_to_notify = 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.')
|
||||
backup_details_ids = fields.One2many('db.backup.details', 'db_backup_id', 'Backup Details')
|
||||
|
||||
def test_sftp_connection(self, context=None):
|
||||
self.ensure_one()
|
||||
@@ -136,11 +137,17 @@ class DbBackup(models.Model):
|
||||
fp = open(file_path, 'wb')
|
||||
self._take_dump(rec.name, fp, 'db.backup', rec.backup_type)
|
||||
fp.close()
|
||||
rec.backup_details_ids.create({
|
||||
'name': bkp_file,
|
||||
'file_path': file_path,
|
||||
'url': '/download/backupfile/%s' % file_path,
|
||||
'db_backup_id': rec.id,
|
||||
})
|
||||
except Exception as error:
|
||||
_logger.debug(
|
||||
_logger.warning(
|
||||
"Couldn't backup database %s. Bad database administrator password for server running at "
|
||||
"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
|
||||
|
||||
# Check if user wants to write to SFTP or not.
|
||||
@@ -262,7 +269,11 @@ class DbBackup(models.Model):
|
||||
# Only delete files (which are .dump and .zip), no directories.
|
||||
if os.path.isfile(fullpath) and (".dump" in f or '.zip' in f):
|
||||
_logger.info("Delete local out-of-date file: %s", fullpath)
|
||||
os.remove(fullpath)
|
||||
backup_details_id = self.env['db.backup.details'].search([('file_path', '=', fullpath)])
|
||||
if backup_details_id:
|
||||
backup_details_id.unlink()
|
||||
else:
|
||||
os.remove(fullpath)
|
||||
|
||||
# This is more or less the same as the default Odoo function at
|
||||
# https://github.com/odoo/odoo/blob/e649200ab44718b8faefc11c2f8a9d11f2db7753/odoo/service/db.py#L209
|
||||
|
||||
Reference in New Issue
Block a user