fix #IBF5RZ app_auto_backup在wl实例中无法备份,数据库是独立机器

This commit is contained in:
Chill
2025-01-09 18:29:29 +08:00
parent 8287e730d6
commit fc977ce5c4
2 changed files with 19 additions and 7 deletions

View File

@@ -6,7 +6,7 @@
{ {
'name': "Database auto backup and Download,数据库自动备份", 'name': "Database auto backup and Download,数据库自动备份",
'version': '16.24.10.09', 'version': '16.25.01.09',
'summary': 'Automated and odoo database backups. easy download and manage database file. optimized from auto_backup of oca Yenthe Van Ginneken', 'summary': 'Automated and odoo database backups. easy download and manage database file. optimized from auto_backup of oca Yenthe Van Ginneken',

View File

@@ -4,11 +4,13 @@ import os
import datetime import datetime
import time import time
import shutil import shutil
import subprocess
import json import json
import tempfile import tempfile
from odoo import models, fields, api, tools, _ from odoo import models, fields, api, tools, _
from odoo.exceptions import Warning, AccessDenied from odoo.exceptions import Warning, AccessDenied
from odoo.tools import find_pg_tool, exec_pg_environ
import odoo import odoo
import logging import logging
@@ -293,8 +295,10 @@ class DbBackup(models.Model):
_logger.info('DUMP DB: %s format %s', db_name, backup_format) _logger.info('DUMP DB: %s format %s', db_name, backup_format)
cmd = ['pg_dump', '--no-owner'] # cmd = ['pg_dump', '--no-owner']
cmd.append(db_name) # cmd.append(db_name)
cmd = [find_pg_tool('pg_dump'), '--no-owner', db_name]
env = exec_pg_environ()
if backup_format == 'zip': if backup_format == 'zip':
with tempfile.TemporaryDirectory() as dump_dir: with tempfile.TemporaryDirectory() as dump_dir:
@@ -306,7 +310,7 @@ class DbBackup(models.Model):
with db.cursor() as cr: with db.cursor() as cr:
json.dump(self._dump_db_manifest(cr), fh, indent=4) json.dump(self._dump_db_manifest(cr), fh, indent=4)
cmd.insert(-1, '--file=' + os.path.join(dump_dir, 'dump.sql')) cmd.insert(-1, '--file=' + os.path.join(dump_dir, 'dump.sql'))
odoo.tools.exec_pg_command(*cmd) subprocess.run(cmd, env=env, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT, check=True)
if stream: if stream:
odoo.tools.osutil.zip_dir(dump_dir, stream, include_dir=False, fnct_sort=lambda file_name: file_name != 'dump.sql') odoo.tools.osutil.zip_dir(dump_dir, stream, include_dir=False, fnct_sort=lambda file_name: file_name != 'dump.sql')
else: else:
@@ -314,6 +318,14 @@ class DbBackup(models.Model):
odoo.tools.osutil.zip_dir(dump_dir, t, include_dir=False, fnct_sort=lambda file_name: file_name != 'dump.sql') odoo.tools.osutil.zip_dir(dump_dir, t, include_dir=False, fnct_sort=lambda file_name: file_name != 'dump.sql')
t.seek(0) t.seek(0)
return t return t
# odoo.tools.exec_pg_command(*cmd)
# if stream:
# odoo.tools.osutil.zip_dir(dump_dir, stream, include_dir=False, fnct_sort=lambda file_name: file_name != 'dump.sql')
# else:
# t=tempfile.TemporaryFile()
# odoo.tools.osutil.zip_dir(dump_dir, t, include_dir=False, fnct_sort=lambda file_name: file_name != 'dump.sql')
# t.seek(0)
# return t
else: else:
cmd.insert(-1, '--format=c') cmd.insert(-1, '--format=c')
stdin, stdout = odoo.tools.exec_pg_command_pipe(*cmd) stdin, stdout = odoo.tools.exec_pg_command_pipe(*cmd)