]> git.parisson.com Git - telemeta.git/commitdiff
add MySQL import script
authorGuillaume Pellerin <yomguy@parisson.com>
Mon, 30 Mar 2015 14:42:24 +0000 (16:42 +0200)
committerGuillaume Pellerin <yomguy@parisson.com>
Mon, 30 Mar 2015 14:42:24 +0000 (16:42 +0200)
telemeta/util/import_sql.sh [new file with mode: 0755]

diff --git a/telemeta/util/import_sql.sh b/telemeta/util/import_sql.sh
new file mode 100755 (executable)
index 0000000..10c0ca4
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+if [[ $# -ne 4 ]]; then
+       echo "Usage: $0 <username> <password> <database> </path/to/sql_file.sql.gz>"
+       exit 1
+fi
+
+echo "=> Starting MySQL Server"
+/usr/bin/mysqld_safe > /dev/null 2>&1 &
+PID=$!
+
+RET=1
+while [[ RET -ne 0 ]]; do
+    echo "=> Waiting for confirmation of MySQL service startup"
+    sleep 5
+    mysql -u"$1" -p"$2" -e "status" > /dev/null 2>&1
+RET=$?
+done
+
+echo "   Started with PID ${PID}"
+
+echo "=> Importing SQL file"
+gunzip -c "$4" | mysql -u"$1" -p"$2" "$3"
+
+echo "=> Stopping MySQL Server"
+mysqladmin -u"$1" -p"$2" shutdown
+
+echo "=> Done!"