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,数据库自动备份",
'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',
@@ -18,14 +18,14 @@
11. Multi-language Support. Multi-Company Support.
12. Support Odoo 18,17,16,15,14,13,12, Enterprise and Community and odoo.sh Edition.
13. Full Open Source.
The Database Auto-Backup module enables the user to make configurations for the automatic backup of the database.
The Database Auto-Backup module enables the user to make configurations for the automatic backup of the database.
Backups can be taken on the local system or on a remote server, through SFTP.
You only have to specify the hostname, port, backup location and databasename (all will be pre-filled by default with correct data.
If you want to write to an external server with SFTP you will need to provide the IP, username and password for the remote backups.
The base of this module is taken from Odoo SA V6.1 (https://www.odoo.com/apps/modules/6.0/auto_backup/) and then upgraded and heavily expanded.
This module is made and provided by Yenthe Van Ginneken (Oocademy).
Automatic backup for all such configured databases can then be scheduled as follows:
Automatic backup for all such configured databases can then be scheduled as follows:
1) Go to Settings / Technical / Automation / Scheduled actions.
2) Search the action 'Backup scheduler'.
3) Set it active and choose how often you wish to take backups.

View File

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