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