Skip to content
Snippets Groups Projects
Commit 3e43d6a2 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

Merge branch '5198-detect-empty-mysql-db' into 'master'

On empty dumps: detect if source db is empty too

See merge request !59
parents aebbbf38 aac557be
Branches
No related tags found
1 merge request!59On empty dumps: detect if source db is empty too
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
# 2022-02-18 ah v2.1 WIP: added counters # 2022-02-18 ah v2.1 WIP: added counters
# 2022-03-17 v2.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" # 2022-03-21 v2.3 Check if the created dump contains "insert"
# 2022-03-24 v2.4 On empty dumps: detect if source db is empty too
# ================================================================================ # ================================================================================
if [ -z "$LOCALDUMP_LOADED" ]; then if [ -z "$LOCALDUMP_LOADED" ]; then
...@@ -94,9 +95,19 @@ function mysql.db.dump(){ ...@@ -94,9 +95,19 @@ function mysql.db.dump(){
fetchrc >/dev/null fetchrc >/dev/null
if [ $myrc -eq 0 ]; then if [ $myrc -eq 0 ]; then
zgrep -iE "(CREATE|INSERT)" "$_dumpfile" >/dev/null if ! zgrep -iE "(CREATE|INSERT)" "$_dumpfile" >/dev/null
fetchrc >/dev/null then
test $myrc -ne 0 && echo "ERROR: no data - the dump doesn't contain any CREATE or INSERT statement." typeset -i local _iTables
_iTables=$( mysql --skip-column-names --batch -e "use $_dbname; show tables ;" | wc -l )
if [ $_iTables -eq 0 ];
then
echo -n "NO DATA in database"
else
echo "ERROR: no data - the dump doesn't contain any CREATE or INSERT statement."
# force an error
false; fetchrc >/dev/null
fi
fi
fi fi
test $myrc -eq 0 && mysql_COUNT_DUMPS+=1 test $myrc -eq 0 && mysql_COUNT_DUMPS+=1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment