#!/bin/sh
#
# mkmysqlslave -- import MySQL master data and start slave
-# Copyright (c)2015 Alexander Barton <alex@barton.de>
+# Copyright (c)2015-2016 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")
esac
done
-if [ -z "$INFILE" -o ! -n "$INFILE" ]; then
+if [ -z "$INFILE" ]; then
Usage
fi
-if [ ! -r "$INFILE" ]; then
+if [ ! -r "$INFILE" -a "$INFILE" != "-" ]; then
echo "$NAME: Can't read \"$INFILE\"!"
exit 1
fi
echo "Initializing MySQL server on \"$MYHOST\" (user \"$MYUSER\") as replication slave:"
-[ -n "$MYPW" ] && PWSWITCH="--password='$MYPW'" || PWSWITCH=""
+[ -n "$MYPW" ] && PWSWITCH="--password=$MYPW" || PWSWITCH=""
echo "Stopping running slave threads ..."
mysql -h "$MYHOST" -u "$MYUSER" $PWSWITCH -e 'stop slave'; r=$?
echo "Warning: FAILED to stop MySQL slave threads, code $r!" >&2
fi
-echo "Importing \"$INFILE\" ..."
echo "Start: $(date)"
-mysql -h "$MYHOST" -u "$MYUSER" $PWSWITCH <"$INFILE"; r=$?
+if [ "$INFILE" != "-" ]; then
+ echo "Importing \"$INFILE\" ..."
+else
+ echo "Importing from standard input ..."
+fi
+( echo "SET SESSION SQL_LOG_BIN=0;"; cat "$INFILE" ) \
+ | mysql -h "$MYHOST" -u "$MYUSER" $PWSWITCH; r=$?
echo "End: $(date)"
if [ $r -ne 0 ]; then
echo "MySQL import FAILED, code $r!" >&2