mirror of
https://github.com/guohuadeng/app-odoo.git
synced 2025-02-23 04:11:36 +02:00
fix #IBF5RZ app_auto_backup在wl实例中无法备份,数据库是独立机器
This commit is contained in:
@@ -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',
|
||||||
|
|
||||||
@@ -18,14 +18,14 @@
|
|||||||
11. Multi-language Support. Multi-Company Support.
|
11. Multi-language Support. Multi-Company Support.
|
||||||
12. Support Odoo 18,17,16,15,14,13,12, Enterprise and Community and odoo.sh Edition.
|
12. Support Odoo 18,17,16,15,14,13,12, Enterprise and Community and odoo.sh Edition.
|
||||||
13. Full Open Source.
|
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.
|
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.
|
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.
|
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.
|
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).
|
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.
|
1) Go to Settings / Technical / Automation / Scheduled actions.
|
||||||
2) Search the action 'Backup scheduler'.
|
2) Search the action 'Backup scheduler'.
|
||||||
3) Set it active and choose how often you wish to take backups.
|
3) Set it active and choose how often you wish to take backups.
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user