Merge pull request #26855 from akhilnarang/ignore-mariadb-sandbox-mode

fix: remove mariadb sandbox mode comment before restoring backups
This commit is contained in:
Akhil Narang 2024-06-27 12:08:12 +05:30 committed by GitHub
commit c5ea81d8a6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -50,25 +50,38 @@ class DbManager:
return self.db.sql("SHOW DATABASES", pluck=True)
@staticmethod
def restore_database(verbose, target, source, user, password):
def restore_database(verbose: bool, target: str, source: str, user: str, password: str) -> None:
"""
Function to restore the given SQL file to the target database.
:param target: The database to restore to.
:param source: The SQL dump to restore
:param user: The database username
:param password: The database password
:return: Nothing
"""
import shlex
from shutil import which
from frappe.database import get_command
from frappe.utils import execute_in_shell
# Ensure that the entire process fails if any part of the pipeline fails
command = ["set -o pipefail;"]
# Handle gzipped backups
if source.endswith(".gz"):
if gzip := which("gzip"):
command.extend([gzip, "-cd", source, "|"])
source = []
else:
raise Exception("`gzip` not installed")
else:
source = ["<", source]
command.extend(["cat", source, "|"])
# Newer versions of MariaDB add in a line that'll break on older versions, so remove it
command.extend(["sed", r"'/\/\*!999999\\- enable the sandbox mode \*\//d'", "|"])
# Generate the restore command
bin, args, bin_name = get_command(
socket=frappe.conf.db_socket,
host=frappe.conf.db_host,
@ -84,6 +97,6 @@ class DbManager:
)
command.append(bin)
command.append(shlex.join(args))
command.extend(source)
execute_in_shell(" ".join(command), check_exit_code=True, verbose=verbose)
frappe.cache.delete_keys("") # Delete all keys associated with this site.