]> arthur.barton.de Git - MkMySqlDump.git/blobdiff - bin/mkmysqldump
mkmysqldump: Make sure "HOME" is set correctly
[MkMySqlDump.git] / bin / mkmysqldump
index 87f9db2b73df5ef854ee09aef0ab792259621ab3..e5b8c64ecba6433df422e52c875d8ba4657c8859 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 #
 # mkmysqldump -- dump MySQL (master) data
-# Copyright (c)2015 Alexander Barton <alex@barton.de>
+# Copyright (c)2015-2017 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
@@ -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!"
@@ -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