Fix indentation of previously cherry-picked patch
[matthijs/upstream/backupninja.git] / handlers / mysql.in
index 88ffb1a798fa8d9eec8e1d8587aa439fd4b5768c..f3230ad3ede61e1c2278c9a4ad1f63757aa3b3e0 100644 (file)
@@ -90,27 +90,33 @@ if [ "$dbusername" != "" -a "$dbpassword" != "" ]
 then
    if [ $usevserver = yes ]
    then
-      vhome=`$VSERVER $vsname exec getent passwd "root" | @AWK@ -F: '{print $6}'`
-   home="$vroot$vhome"
+      home=`$VSERVER $vsname exec getent passwd "root" | @AWK@ -F: '{print $6}'`
    else
       home=`getent passwd "root" | @AWK@ -F: '{print $6}'`
    fi
 
    [ -d $home ] || fatal "Can't find root's home directory ($home)."
-
+    
    mycnf="$home/.my.cnf"
 
-   if [ -f $mycnf ]
+   if [ $usevserver = yes ]
    then
-   # rename temporarily
-   tmpcnf="$home/my.cnf.disable"
-   debug "mv $mycnf $tmpcnf"
-   mv $mycnf $tmpcnf
+      workcnf="$vroot$mycnf"
+   else
+      workcnf="$mycnf"
    fi
 
+   if [ -f $workcnf ]
+   then
+      # rename temporarily
+      tmpcnf="$workcnf.disable"
+      debug "mv $workcnf $tmpcnf"
+      mv $workcnf $tmpcnf
+   fi
+    
    oldmask=`umask`
    umask 077
-   cat > $mycnf <<EOF
+   cat > $workcnf <<EOF
 # auto generated backupninja mysql conf
 [mysql]
 host=$dbhost
@@ -126,14 +132,14 @@ password="$dbpassword"
 host=$dbhost
 user=$dbusername
 password="$dbpassword"
+
+[mysqladmin]
+host=$dbhost
+user=$dbusername
+password="$dbpassword"
 EOF
    umask $oldmask
-   if [ $usevserver = yes ]
-   then
-      defaultsfile="--defaults-extra-file=$vhome/.my.cnf"
-   else
-      defaultsfile="--defaults-extra-file=$mycnf"
-   fi
+   defaultsfile="--defaults-extra-file=$mycnf"
 fi
 
 # if a user is not set, use $configfile, otherwise use $mycnf
@@ -144,22 +150,23 @@ else
    userset=true;
    if [ $usevserver = yes ]
    then
-      vuserhome=`$VSERVER $vsname exec getent passwd "$user" | @AWK@ -F: '{print $6}'`
+      userhome=`$VSERVER $vsname exec getent passwd "$user" | @AWK@ -F: '{print $6}'`
       if [ $? -eq 2 ]
       then
-         fatal "User $user not found in /etc/passwd"
+        fatal "User $user not found in /etc/passwd"
       fi
-         userhome="$vroot$vuserhome"
+      debug "User home set to: $vroot$userhome"
+      [ -f $vroot$userhome/.my.cnf ] || fatal "Can't find config file in $userhome/.my.cnf"
    else
       userhome=`getent passwd "$user" | @AWK@ -F: '{print $6}'`
       if [ $? -eq 2 ]
       then
-         fatal "User $user not found in /etc/passwd"
+        fatal "User $user not found in /etc/passwd"
       fi
-         fi
-
-   debug "User home set to: $userhome"
-   [ -f $userhome/.my.cnf ] || fatal "Can't find config file in $userhome/.my.cnf"
+      debug "User home set to: $userhome"
+      [ -f $userhome/.my.cnf ] || fatal "Can't find config file in $userhome/.my.cnf"
+   fi
+       
    defaultsfile="--defaults-extra-file=$userhome/.my.cnf"
    debug "using $defaultsfile"
 fi
@@ -272,9 +279,9 @@ then
             fatal "mysqld doesn't appear to be running!"
          fi
          if [ "$compress" == "yes" ]; then
-            execstr="$VSERVER $vsname exec $DUMP | $GZIP > $vroot$dumpdir/${db}.sql.gz"
+            execstr="$VSERVER $vsname exec $DUMP | $GZIP --rsyncable > '$vroot$dumpdir/${db}.sql.gz'"
          else
-            execstr="$VSERVER $vsname exec $DUMP -r $vroot$dumpdir/${db}.sql"
+            execstr="$VSERVER $vsname exec $DUMP -r '$vroot$dumpdir/${db}.sql'"
          fi
       else
          # Test to make sure mysqld is running, if it is not sqldump will not work
@@ -283,9 +290,9 @@ then
             fatal "mysqld doesn't appear to be running!"
          fi
          if [ "$compress" == "yes" ]; then
-            execstr="$DUMP | $GZIP > $dumpdir/${db}.sql.gz"
+            execstr="$DUMP | $GZIP --rsyncable > '$dumpdir/${db}.sql.gz'"
          else
-            execstr="$DUMP -r $dumpdir/${db}.sql"
+            execstr="$DUMP -r '$dumpdir/${db}.sql'"
          fi
       fi
       debug "su $user -c \"$execstr\""
@@ -309,12 +316,12 @@ fi
 if [ "$dbusername" != "" -a "$dbpassword" != "" ]
 then
    ## clean up tmp config file
-   debug "rm $mycnf"
-   rm $mycnf
+   debug "rm $workcnf"
+   rm $workcnf
    if [ -f "$tmpcnf" ]
    then
-      debug "mv $tmpcnf $mycnf"
-      mv $tmpcnf $mycnf
+      debug "mv $tmpcnf $workcnf"
+      mv $tmpcnf $workcnf
    fi
 fi