Skip to content

Commit

Permalink
[REF] auto_backup: Refactor command execution to new style/usage
Browse files Browse the repository at this point in the history
  • Loading branch information
randall-vx authored Mar 20, 2024
1 parent b77bc98 commit 31d626e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions auto_backup/models/db_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import shutil
import json
import tempfile
import subprocess

from odoo import models, fields, api, tools, _
from odoo.exceptions import Warning, AccessDenied
Expand Down Expand Up @@ -295,8 +296,8 @@ def _take_dump(self, db_name, stream, model, backup_format='zip'):
db = odoo.sql_db.db_connect(db_name)
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)
cmd.append('--file=' + os.path.join(dump_dir, 'dump.sql'))
subprocess.run(cmd, 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:
Expand All @@ -305,10 +306,11 @@ def _take_dump(self, db_name, stream, model, backup_format='zip'):
t.seek(0)
return t
else:
cmd.insert(-1, '--format=c')
stdin, stdout = odoo.tools.exec_pg_command_pipe(*cmd)
cmd.append('--format=c')
process = subprocess.Popen(cmd,stdout=subprocess.PIPE)
stdout, _ = process.communicate()
if stream:
shutil.copyfileobj(stdout, stream)
stream.write(stdout)
else:
return stdout

Expand Down

0 comments on commit 31d626e

Please sign in to comment.