Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] use subprocess to restore the database #154

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion click_odoo_contrib/restoredb.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import os
import shutil
import subprocess

import click
import click_odoo
Expand All @@ -29,7 +30,14 @@ def _restore_from_folder(dbname, backup, copy=True, jobs=1, neutralize=False):

odoo.service.db._create_empty_database(dbname)
pg_args = ["--jobs", str(jobs), "--dbname", dbname, "--no-owner", dbdump_file_path]
if odoo.tools.exec_pg_command("pg_restore", *pg_args):
pg_env = odoo.tools.misc.exec_pg_environ()
r = subprocess.run(
["pg_restore", *pg_args],
env=pg_env,
stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT,
)
if r.returncode != 0:
raise click.ClickException("Couldn't restore database")
if copy:
# if it's a copy of a database, force generation of a new dbuuid
Expand Down
Loading