From 8fc4fb4eb76010db4dafa564fc0904a4605ca013 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Mon, 19 Jan 2009 14:52:14 +0000 Subject: Support setting host in my.cnf git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@378 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede --- backup-mysql | 9 +++++++-- 1 file 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 -- cgit v1.2.3