From 7a6724319d2c1a18410e1dba583d7aeca6348a4f Mon Sep 17 00:00:00 2001
From: "Hahn Axel (hahn)" <axel.hahn@iml.unibe.ch>
Date: Tue, 22 Mar 2022 10:23:51 +0100
Subject: [PATCH] mysql dump: update check for empty data

---
 inc_bash.sh                |  4 ++--
 plugins/localdump/mysql.sh | 10 +++++-----
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/inc_bash.sh b/inc_bash.sh
index d076b05..f299e43 100755
--- a/inc_bash.sh
+++ b/inc_bash.sh
@@ -11,8 +11,8 @@
 typeset -i rc=0
 
 # Fetch returncode of last executed command.
-# It summarizes all exitcodes into rc (= if any job failed it is <> 0)
-# It stores the last exitcode in myrc
+# - It summarizes all exitcodes into rc (= if any job failed it is <> 0)
+# - It stores the last exitcode in myrc
 function fetchrc(){
   myrc=$?
   rc=$rc+$myrc
diff --git a/plugins/localdump/mysql.sh b/plugins/localdump/mysql.sh
index 4f69c25..82616a1 100755
--- a/plugins/localdump/mysql.sh
+++ b/plugins/localdump/mysql.sh
@@ -93,15 +93,15 @@ function mysql.db.dump(){
             "$_dbname" 2>&1
   fetchrc >/dev/null
 
-  zgrep -iE "(CREATE|INSERT)" "$_dumpfile" >/dev/null
-  typeset -i local _rc2=$?
-  test $_rc2 -ne 0 && echo "ERROR: the dump does not contain any CREATE or INSERT statement."
+  if [ $myrc -eq 0 ]; then
+        zgrep -iE "(CREATE|INSERT)" "$_dumpfile" >/dev/null
+        fetchrc >/dev/null
+        test $myrc -ne 0 && echo "ERROR: no data - the dump doesn't contain any CREATE or INSERT statement."
+  fi
 
-  typeset -i local myrc+=$_rc2
   test $myrc -eq 0 && mysql_COUNT_DUMPS+=1
   test $myrc -eq 0 || mysql_COUNT_ERRORS+=1
 
-  test $myrc -eq 0  
 }
 
 # import [file] --> [database] 
-- 
GitLab