mysql: Pass -h $dbhost to mysqlhotcopy consistently.
[matthijs/upstream/backupninja.git] / handlers / mysql.in
index defb72aa8aeb98713d807024a5a488bcbca43cdd..39c1fb9c2729819b5d80f86873d910f0f808917c 100644 (file)
@@ -10,6 +10,7 @@ getconf nodata
 getconf dbhost localhost
 getconf hotcopy no
 getconf sqldump no
+getconf sqldumpoptions "--lock-tables --complete-insert --add-drop-table --quick --quote-names"
 getconf compress yes
 getconf vsname
 
@@ -31,10 +32,7 @@ if [ $vservers_are_available = yes ]; then
          fatal "The vserver given in vsname ($vsname) does not exist."
       fi
       # is it running ?
-      $VSERVERINFO -q $vsname RUNNING
-      if [ $? -ne 0 ]; then
-         fatal "The vserver $vsname is not running."
-      fi
+      vservers_running $vsname || fatal "The vserver $vsname is not running."
       # everything ok
       info "Using vserver '$vsname'."
       usevserver=yes
@@ -42,6 +40,8 @@ if [ $vservers_are_available = yes ]; then
    else
       info "No vserver name specified, actions will be performed on the host."
    fi
+else
+   [ -z "$vsname" ] || warning 'vservers support disabled in backupninja.conf, vsname configuration line will be ignored'
 fi
 
 ## Prepare ignore part of the command
@@ -161,7 +161,11 @@ else
        
        debug "User home set to: $userhome"
        [ -f $userhome/.my.cnf ] || fatal "Can't find config file in $userhome/.my.cnf"
-       defaultsfile="--defaults-extra-file=$userhome/.my.cnf"
+        if [ $usevserver = yes ]; then
+            defaultsfile="--defaults-extra-file=$vuserhome/.my.cnf"
+        else
+            defaultsfile="--defaults-extra-file=$userhome/.my.cnf"
+        fi
        debug "using $defaultsfile"
 fi
 
@@ -178,7 +182,7 @@ then
                info "dbhost: $dbhost"
                execstr="$VSERVER $vsname exec $MYSQLHOTCOPY -h $dbhost --quiet --allowold --regexp /.\*/./.\*/ $hotdir"
        else
-               execstr="$MYSQLHOTCOPY --quiet --allowold --regexp /.\*/./.\*/ $hotdir"
+               execstr="$MYSQLHOTCOPY -h $dbhost --quiet --allowold --regexp /.\*/./.\*/ $hotdir"
        fi
        debug "su $user -c \"$execstr\""
        if [ ! $test ]
@@ -199,9 +203,9 @@ then
        do
                if [ $usevserver = yes ]
                then
-                       execstr="$VSERVER $vsname exec $MYSQLHOTCOPY --allowold $db $hotdir"
+                       execstr="$VSERVER $vsname exec $MYSQLHOTCOPY -h $dbhost --allowold $db $hotdir"
                else
-                       execstr="$MYSQLHOTCOPY --allowold $db $hotdir"
+                       execstr="$MYSQLHOTCOPY -h $dbhost --allowold $db $hotdir"
                fi
                debug 'su $user -c \"$execstr\"'
                if [ ! $test ]
@@ -248,7 +252,7 @@ then
 
        for db in $databases
        do
-           DUMP_BASE="$MYSQLDUMP $defaultsfile --lock-tables --complete-insert --add-drop-table --quick --quote-names"
+           DUMP_BASE="$MYSQLDUMP $defaultsfile $sqldumpoptions"
 
            # Dumping structure and data
            DUMP="$DUMP_BASE $ignore $db"