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

mysql fixes with shellcheck

parent 77509b75
Branches
No related tags found
1 merge request!26Eliminate scheduler
...@@ -10,10 +10,11 @@ ...@@ -10,10 +10,11 @@
# #
# 2016-11-10 ah,ds v0.8 needs to be testet # 2016-11-10 ah,ds v0.8 needs to be testet
# 2017-03-28 ..... v1.0 added restore # 2017-03-28 ..... v1.0 added restore
# 2022-01-20 v1.1 fixes with shellcheck
# ================================================================================ # ================================================================================
if [ -z $BACKUP_TARGETDIR ]; then if [ -z "$BACKUP_TARGETDIR" ]; then
echo ERROR: you cannot start `basename $0` directly echo "ERROR: you cannot start $(basename $0) directly"
rc=$rc+1 rc=$rc+1
exit 1 exit 1
fi fi
...@@ -33,33 +34,33 @@ function doMysqlBackup(){ ...@@ -33,33 +34,33 @@ function doMysqlBackup(){
create_targetdir create_targetdir
for DATABASE_DIR in `find $SOURCE_DIR/* -type d -prune`; for DATABASE_DIR in $(find $SOURCE_DIR/* -type d -prune);
do do
# DATABASE=`basename $DATABASE_DIR` # DATABASE=`basename $DATABASE_DIR`
DATABASE=`basename $DATABASE_DIR | sed "s#\@002d#-#g" ` DATABASE=$(basename "$DATABASE_DIR" | sed "s#\@002d#-#g" )
TABLECOUNT=`find $DATABASE_DIR/. -type f -name *frm | wc -l` TABLECOUNT=$(find "$DATABASE_DIR"/. -type f -name "*frm" | wc -l)
echo --- database $DATABASE - $TABLECOUNT tables echo "--- database $DATABASE - $TABLECOUNT tables"
if [ $TABLECOUNT -gt 0 ]; then if [ $TABLECOUNT -gt 0 ]; then
echo -n "backup ... " echo -n "backup ... "
OUTFILE=${BACKUP_TARGETDIR}/`get_outfile ${DATABASE}`.sql OUTFILE="${BACKUP_TARGETDIR}/$(get_outfile ${DATABASE}).sql"
# task 1251 - "--master-data=2" was removed # task 1251 - "--master-data=2" was removed
$MYSQLDUMP --opt \ $MYSQLDUMP --opt \
--default-character-set=utf8 \ --default-character-set=utf8 \
--flush-logs \ --flush-logs \
--single-transaction \ --single-transaction \
--no-autocommit \ --no-autocommit \
--result-file=$OUTFILE \ --result-file="$OUTFILE" \
$DATABASE "$DATABASE"
fetchrc fetchrc
# $myrc is last returncode - set in fetchrc # $myrc is last returncode - set in fetchrc
if [ $myrc -eq 0 ]; then if [ $myrc -eq 0 ]; then
echo -n "gzip ... " echo -n "gzip ... "
compress_file $OUTFILE compress_file "$OUTFILE"
else else
echo "ERROR occured - no gzip" echo "ERROR occured - no gzip"
fi fi
ls -l $OUTFILE* ls -l "$OUTFILE"*
fi fi
echo echo
done done
...@@ -73,9 +74,9 @@ function restoreByFile(){ ...@@ -73,9 +74,9 @@ function restoreByFile(){
sMyfile=$1 sMyfile=$1
sMyDb=$2 sMyDb=$2
if [ -z $sMyDb ]; then if [ -z "$sMyDb" ]; then
h2 "analyze dump $sMyfile" h2 "analyze dump $sMyfile"
sMyDb=`guessDB $sMyfile` sMyDb=$(guessDB $sMyfile)
echo "detected db schema from file: [${sMyDb}]" echo "detected db schema from file: [${sMyDb}]"
else else
echo "db schema from param 2: [${sMyDb}]" echo "db schema from param 2: [${sMyDb}]"
...@@ -83,7 +84,7 @@ function restoreByFile(){ ...@@ -83,7 +84,7 @@ function restoreByFile(){
echo echo
echo import to $sMyDb... echo import to "$sMyDb"...
h2 ensure that database exists ... h2 ensure that database exists ...
color cmd color cmd
...@@ -91,10 +92,10 @@ function restoreByFile(){ ...@@ -91,10 +92,10 @@ function restoreByFile(){
color reset color reset
h2 import ... h2 import ...
ls -l $sMyfile ls -l "$sMyfile"
echo import to database [${sMyDb}] echo "import to database [${sMyDb}]"
color cmd color cmd
zcat $sMyfile | mysql "${sMyDb}" zcat "$sMyfile" | mysql "${sMyDb}"
fetchrc fetchrc
color reset color reset
...@@ -130,6 +131,6 @@ else ...@@ -130,6 +131,6 @@ else
fi fi
fi fi
echo $0 $* [mysql] final returncode rc=$rc echo "$0 $* [mysql] final returncode rc=$rc"
# -------------------------------------------------------------------------------- # --------------------------------------------------------------------------------
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment