diff --git a/plugins/localdump/mysql.sh b/plugins/localdump/mysql.sh index f0dfebb7fa1a8a64ba09a324d56d9effd253b97b..ae3f65bc39f9b85253489db809c8d5473e47c064 100755 --- a/plugins/localdump/mysql.sh +++ b/plugins/localdump/mysql.sh @@ -12,7 +12,8 @@ # 2022-01-20 ah v1.1 fixes with shellcheck # 2022-02-14 ah v2.0 rewrite with class like functions # 2022-02-18 ah v2.1 WIP: added counters -# 2022-03-17 v1.2 WIP: add lines with prefix __DB__ +# 2022-03-17 v2.2 WIP: add lines with prefix __DB__ +# 2022-03-21 v2.3 Check if the created dump contains "insert" # ================================================================================ if [ -z "$LOCALDUMP_LOADED" ]; then @@ -71,7 +72,7 @@ function mysql.db.create(){ echo "CREATE DATABASE IF NOT EXISTS ${_dbname};" | mysql fetchrc >/dev/null test $myrc -eq 0 && mysql_COUNT_CREATE+=1 - test $rc -eq 0 || mysql_COUNT_ERRORS+=1 + test $myrc -eq 0 || mysql_COUNT_ERRORS+=1 } # dump [database] --> [file] @@ -89,11 +90,17 @@ function mysql.db.dump(){ --single-transaction \ --no-autocommit \ --result-file="$_dumpfile" \ - "$_dbname" + "$_dbname" 2>&1 fetchrc >/dev/null - test $myrc -eq 0 && mysql_COUNT_DUMPS+=1 - test $rc -eq 0 || mysql_COUNT_ERRORS+=1 - test $rc -eq 0 + + zgrep -i "INSERT" "$_dumpfile" >/dev/null + typeset -i local _rc2=$? + test $_rc2 -ne 0 && echo "ERROR: the dump does not contain an insert statement." + + typeset -i local _rctotal=$?+$_rc2 + test $_rctotal -eq 0 && mysql_COUNT_DUMPS+=1 + test $_rctotal -eq 0 || mysql_COUNT_ERRORS+=1 + test $_rctotal -eq 0 } # import [file] --> [database] @@ -106,7 +113,7 @@ function mysql.db.import(){ zcat "$_dumpfile" | mysql "${_dbname}" fetchrc >/dev/null test $myrc -eq 0 && mysql_COUNT_IMPORT+=1 - test $rc -eq 0 || mysql_COUNT_ERRORS+=1 + test $myrc -eq 0 || mysql_COUNT_ERRORS+=1 } # show a list of existing databases @@ -116,7 +123,7 @@ function mysql.db.list(){ fetchrc >/dev/null test $myrc -eq 0 && mysql_COUNT_DB=$( echo "$_result" | grep -c "^Database:" ) test $myrc -eq 0 && echo "$_result" | grep "^Database:" | awk '{ print $2 }' - test $rc -eq 0 || mysql_COUNT_ERRORS+=1 + test $myrc -eq 0 || mysql_COUNT_ERRORS+=1 } # --------------------------------------------------------------------------------