summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbackup-mysql9
1 files changed, 7 insertions, 2 deletions
diff --git a/backup-mysql b/backup-mysql
index a3fcb6a..5a0bcfe 100755
--- a/backup-mysql
+++ b/backup-mysql
@@ -61,9 +61,14 @@ for host in $HOSTS; do
echo "Cannot find my.cnf for host $host: $mysqlcnf" >&2
exit 1
fi
+ if grep '^host=' "$mysqlcnf" > /dev/null; then
+ hostarg=""
+ else
+ hostarg="--host=$host"
+ fi
DBs=$(
- echo 'SHOW DATABASES;' | mysql --defaults-file="$mysqlcnf" --host="$host" | tail -n +2 |
+ echo 'SHOW DATABASES;' | mysql --defaults-file="$mysqlcnf" ${hostarg:+"$hostarg"} | tail -n +2 |
while read db; do
if [ "$db" = "innodb" ] || [ "$db" = "test" ] || [ "$db" = "lost+found" ] ; then
continue;
@@ -74,7 +79,7 @@ for host in $HOSTS; do
for db in $DBs; do
file="$TARGET/$DATE-$prefix$db"
- mysqldump --defaults-file="$mysqlcnf" --host="$host" --opt --lock-tables -- "$db" > "$file"
+ mysqldump --defaults-file="$mysqlcnf" ${hostarg:+"$hostarg"} --opt --lock-tables -- "$db" > "$file"
done
for db in $DBs; do