]> arthur.barton.de Git - MkMySqlDump.git/blobdiff - bin/mkmysqldump
Show output of compression program to stdout, not stderr
[MkMySqlDump.git] / bin / mkmysqldump
index 80c299e64d2faa070a4bbe4d31eaab01b9dd6985..0dc345da357d5ec1b1b79e4804a43161fcedc67f 100755 (executable)
@@ -3,6 +3,12 @@
 # mkmysqldump -- dump MySQL (master) data
 # Copyright (c)2015 Alexander Barton <alex@barton.de>
 #
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+# Please read the file COPYING, README and AUTHORS for more information.
+#
 
 NAME=$(basename "$0")
 
@@ -43,6 +49,12 @@ Usage() {
        exit 2
 }
 
+ErrorNotice() {
+       echo
+       echo "----->  THERE HAVE BEEN ERRORS!  <-----"
+       echo
+}
+
 for cmd in mysql mysqldump; do
        if ! which "$cmd" >/dev/null 2>&1; then
                echo "$NAME: \"$cmd\" command not found!"
@@ -59,7 +71,7 @@ while [ $# -gt 0 ]; do
                ;;
          "--user"|"-u")
                [ $# -ge 2 ] || Usage
-               MYHOST="$2"
+               MYUSER="$2"
                shift 2
                ;;
          "--password"|"-p")
@@ -103,10 +115,12 @@ while [ $# -gt 0 ]; do
 done
 
 echo "Dumping MySQL server on \"$MYHOST\" (user \"$MYUSER\"):"
+echo
 echo "Started: $(date)"
+
 umask 0077
 
-[ -n "$MYPW" ] && PWSWITCH="--password='$MYPW'" || PWSWITCH=""
+[ -n "$MYPW" ] && PWSWITCH="--password=$MYPW" || PWSWITCH=""
 
 echo "Getting list of databases from server ..."
 DATABASES=$(
@@ -118,24 +132,44 @@ DATABASES=$(
 )
 if [ $? -ne 0 ]; then
        echo "Failed to get list of databases! Aborting!"
+       ErrorNotice
        exit 1
 fi
 
+echo "Checking slave status ..."
+Slave_IO_Running=""; Slave_SQL_Running=""
+eval "$(echo 'SHOW SLAVE STATUS\G' | mysql -h "$MYHOST" -u "$MYUSER" $PWSWITCH | sed -n '/Running/p' | sed 's/: /=/g')"
+if [ -n "$Slave_IO_Running" -o -n "$Slave_SQL_Running" ]; then
+       if [ "$Slave_IO_Running" = "Yes" -a "$Slave_SQL_Running" = "Yes" ]; then
+               echo "Server is running as MySQL slave, replication is Ok."
+       else
+               echo "Server is running as MySQL slave, but replication FAILED!"
+               ErrorNotice
+               exit 1
+       fi
+else
+       echo "Server is not running as MySQL slave. Ok."
+fi
+
+echo "Will dump the following databases:"
+for d in $DATABASES; do
+       echo " - $d"
+done
+
 echo "Dumping SQL data to file \"$OUTFILE\" ..."
+echo "Beginning dump: $(date)"
 CMD="mysqldump \
        -h $MYHOST \
        -u $MYUSER \
        $PWSWITCH \
        --master-data=1 \
        --databases $DATABASES"
-
-echo "Start date: $(date)"
-echo $CMD
 $CMD >"$OUTFILE"; r=$?
 if [ -n "$COMPRESS" -a -s "$OUTFILE" -a $r -eq 0 ]; then
        echo "Dump done: $(date)"
        echo "Compressing dump file ($COMPRESS) ..."
-       $COMPRESS "$OUTFILE"
+       $COMPRESS "$OUTFILE" 2>&1
+       [ $? -eq 0 ] || echo "Error compressing dump file!" >&2
 fi
 echo "End: $(date)"
 echo
@@ -150,9 +184,12 @@ if [ -n "$STATS" ]; then
        echo
 fi
 
-[ $r -eq 0 ] \
-       && echo "Dump command exited with code 0, success." \
-       || echo "Dump command FAILED with code $r!" >&2
+if [ $r -eq 0 ]; then
+       echo "Dump command exited with code 0, success."
+       echo
+else
+       echo "Dump command FAILED with code $r!" >&2
+       ErrorNotice
+fi
 
-echo
 exit $r