X-Git-Url: https://arthur.barton.de/gitweb/?a=blobdiff_plain;f=bin%2Fmkmysqldump;h=e5b8c64ecba6433df422e52c875d8ba4657c8859;hb=6f7fb5e294c8b2d6ff1414c60c9346bb2546fa58;hp=3a5ba19ee7366bb6b27e9770cce79504a053dbca;hpb=2018dba2234b3285b69dbfcc78a0023187751e06;p=MkMySqlDump.git diff --git a/bin/mkmysqldump b/bin/mkmysqldump index 3a5ba19..e5b8c64 100755 --- a/bin/mkmysqldump +++ b/bin/mkmysqldump @@ -1,7 +1,7 @@ #!/bin/sh # # mkmysqldump -- dump MySQL (master) data -# Copyright (c)2015 Alexander Barton +# Copyright (c)2015-2017 Alexander Barton # # 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 @@ -55,6 +55,11 @@ ErrorNotice() { echo } +# Make sure the environment is "sane", for example, mysql(1) depends on the +# HOME environment variable to be set. +[ -n "$HOME" ] || HOME=$( getent passwd "${LOGNAME:-root}" | cut -d: -f6 ) +export HOME + for cmd in mysql mysqldump; do if ! which "$cmd" >/dev/null 2>&1; then echo "$NAME: \"$cmd\" command not found!" @@ -71,7 +76,7 @@ while [ $# -gt 0 ]; do ;; "--user"|"-u") [ $# -ge 2 ] || Usage - MYHOST="$2" + MYUSER="$2" shift 2 ;; "--password"|"-p") @@ -120,7 +125,7 @@ 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=$( @@ -138,7 +143,7 @@ fi echo "Checking slave status ..." Slave_IO_Running=""; Slave_SQL_Running="" -eval "$(echo 'SHOW SLAVE STATUS\G' | mysql | sed -n '/Running/p' | sed 's/: /=/g')" +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." @@ -168,7 +173,8 @@ $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 @@ -185,10 +191,10 @@ fi 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