From 6f04580734ed4babcb3cd9bc096939e72a5c8eb3 Mon Sep 17 00:00:00 2001
From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch>
Date: Mon, 18 Nov 2024 09:23:57 +0100
Subject: [PATCH] Detect mariadb sandbox mode

---
 plugins/localdump/mysql.sh | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/plugins/localdump/mysql.sh b/plugins/localdump/mysql.sh
index e3bc6df..43e200d 100755
--- a/plugins/localdump/mysql.sh
+++ b/plugins/localdump/mysql.sh
@@ -18,6 +18,8 @@
 # 2022-03-24         v2.4  On empty dumps: detect if source db is empty too
 # 2023-10-06         v2.5  mysqldump params can be customized in jobs/env
 # 2023-10-02         v2.6  Detect a connect error before backup; remove unneeded code
+# 2024-10-02         v2.6  Detect a connect error before backup; remove unneeded code
+# 2024-11-18         v2.7  Detect mariadb sandbox mode
 # ================================================================================
 
 if [ -z "$LOCALDUMP_LOADED" ]; then
@@ -95,7 +97,17 @@ function mysql.db.dump(){
 function mysql.db.import(){
   local _dumpfile=$1
   local _dbname=$2
-  zcat "$_dumpfile" | mysql $BACKUP_PARAMS "${_dbname}"
+
+  # https://mariadb.org/mariadb-dump-file-compatibility-change/
+  # if sandbox mode is detected then skip the first line
+  local sSandbox; sSandbox='/*!999999\- enable the sandbox mode */'
+  if zcat "$_dumpfile" | head -1 | grep -Fq "$sSandbox" 
+  then
+    zcat "$_dumpfile" | tail +2 | mysql $BACKUP_PARAMS "${_dbname}"
+  else
+    zcat "$_dumpfile" | mysql $BACKUP_PARAMS "${_dbname}"
+  fi
+
   fetchrc >/dev/null
   test $myrc -eq 0 && mysql_COUNT_IMPORT+=1
   test $myrc -eq 0 || mysql_COUNT_ERRORS+=1
-- 
GitLab