Fixes missing USE statement in SQL dump

This commit adds the additional `--databases` option to the mysqldump command.
This adds a `USE database` statement to the beginning of the SQL dump.
Without this one has to provide the database name at restore.
This commit is contained in:
Markus "Shorty" Uckelmann 2017-09-07 17:10:15 +02:00
parent 44cdee455a
commit ae753e40a1

2
backup.sh Normal file → Executable file
View file

@ -11,7 +11,7 @@ do
then then
echo "Dumping database: $db" echo "Dumping database: $db"
FILENAME=/backup/$DATE.$db.sql FILENAME=/backup/$DATE.$db.sql
if mysqldump -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" "$db" > "$FILENAME" if mysqldump -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" --databases "$db" > "$FILENAME"
then then
gzip -f "$FILENAME" gzip -f "$FILENAME"
else else