2017-03-27 21:16:15 +02:00
|
|
|
#!/bin/bash
|
2017-04-16 11:29:31 +02:00
|
|
|
[ -z "${MYSQL_USER}" ] && { echo "=> MYSQL_USER cannot be empty" && exit 1; }
|
|
|
|
[ -z "${MYSQL_PASS}" ] && { echo "=> MYSQL_PASS cannot be empty" && exit 1; }
|
|
|
|
|
|
|
|
if [ "$#" -ne 1 ]
|
|
|
|
then
|
|
|
|
echo "You must pass the path of the backup file to restore"
|
|
|
|
fi
|
|
|
|
|
2021-05-09 17:57:18 +02:00
|
|
|
set -o pipefail
|
|
|
|
|
2021-05-04 22:59:10 +02:00
|
|
|
SQL=$(gunzip -c "$1")
|
2021-03-07 12:57:19 +01:00
|
|
|
DB_NAME=${MYSQL_DATABASE:-${MYSQL_DB}}
|
2021-05-04 22:59:10 +02:00
|
|
|
if [ -z "${DB_NAME}"]
|
|
|
|
then
|
2021-05-09 17:58:46 +02:00
|
|
|
DB_NAME=$(echo "$SQL" | grep -oE '(Database: (\w*))' | cut -d ' ' -f 2)
|
2021-05-04 22:59:10 +02:00
|
|
|
fi
|
|
|
|
[ -z "${DB_NAME}" ] && { echo "=> database name cannot be found" && exit 1; }
|
|
|
|
|
|
|
|
echo "=> Restore database $DB_NAME from $1"
|
|
|
|
|
2021-05-09 17:58:46 +02:00
|
|
|
if echo "$SQL" | mysql -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" "$DB_NAME"
|
2017-04-16 11:29:31 +02:00
|
|
|
then
|
2017-03-27 21:16:15 +02:00
|
|
|
echo "=> Restore succeeded"
|
|
|
|
else
|
|
|
|
echo "=> Restore failed"
|
|
|
|
fi
|