X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=handlers%2Fmysql;h=ae54aae7f2a2c0500b8999e03e043009e6eb7768;hb=c8ebca79ad314975a4955bf42fe7705b0c20e9f3;hp=cb7010435a3dbfd98a7e0eaf834a0b297e5e1207;hpb=603c015425c36977b13a73fec79c9fa9e857e358;p=matthijs%2Fupstream%2Fbackupninja.git diff --git a/handlers/mysql b/handlers/mysql index cb70104..ae54aae 100644 --- a/handlers/mysql +++ b/handlers/mysql @@ -1,3 +1,4 @@ +# -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- # # mysql handler script for backupninja # @@ -18,59 +19,28 @@ getconf dbpassword getconf configfile /etc/mysql/debian.cnf -# If vservers are configured, decide if the handler should -# use them or if it should just operate on the host - -if [ "$vservers" = "yes" ] -then - if [ ! -z $vsname ] - then - info "Using vserver '$vsname'" - usevserver=1 - else - info "No vserver name specified, actions will be performed on the host" - fi -fi - -# If needed, make sure that the specified vserver exists and is running. -if [ $usevserver ] -then - debug "Examining vserver '$vsname'" - # does it exist ? - vroot="$VROOTDIR/$vsname" - [ -d $vroot ] || fatal "vserver '$vsname' does not exist at '$vroot'" - # is it running ? - $VSERVERINFO -q $vsname RUNNING - if [ $? -ne 0 ] - then - fatal "vserver $vsname is not running." - fi -fi - -if [ "$user" == "" ]; then - userset=false; - user=root; -else - userset=true; - if [ $usevserver ] - then - userhome=`$VSERVER $vsname exec getent passwd "$user" | awk -F: '{print $6}'` - if [ $? -eq 2 ] - then - fatal "User $user not found in /etc/passwd" - fi - userhome="$vroot$userhome" - debug "User home set to: $userhome" - [ -f $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" - fi - debug "User home set to: $userhome" - [ -f $userhome/.my.cnf ] || fatal "Can't find config file in $userhome/.my.cnf" - fi +# Decide if the handler should operate on a vserver or on the host. +# In the former case, check that $vsname exists and is running. +local usevserver=no +local vroot +if [ $vservers_are_available = yes ]; then + if [ -n "$vsname" ]; then + # does it exist ? + if ! vservers_exist "$vsname" ; 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 + # everything ok + info "Using vserver '$vsname'." + usevserver=yes + vroot="$VROOTDIR/$vsname" + else + info "No vserver name specified, actions will be performed on the host." + fi fi ## Prepare ignore part of the command @@ -88,7 +58,7 @@ done hotdir="$backupdir/hotcopy" dumpdir="$backupdir/sqldump" -if [ $usevserver ] +if [ $usevserver = yes ] then [ "$sqldump" == "no" -o -d $vroot$dumpdir ] || $VSERVER $vsname exec mkdir -p $dumpdir [ "$hotcopy" == "no" -o -d $vroot$hotdir ] || $VSERVER $vsname exec mkdir -p $hotdir @@ -115,19 +85,21 @@ fi # specify the password on the command line. defaultsfile="" + if [ "$dbusername" != "" -a "$dbpassword" != "" ] then - if [ $usevserver ] + if [ $usevserver = yes ] then - home=`$VSERVER $vsname exec getent passwd "root" | awk -F: '{print $6}'` - home="$vroot$home" - debug "Home set to: $home" + vhome=`$VSERVER $vsname exec getent passwd "root" | awk -F: '{print $6}'` + home="$vroot$vhome" else home=`getent passwd "root" | awk -F: '{print $6}'` - debug "Home set to: $home" fi + [ -d $home ] || fatal "Can't find root's home directory ($home)." + mycnf="$home/.my.cnf" + if [ -f $mycnf ] then # rename temporarily @@ -135,27 +107,61 @@ then debug "mv $mycnf $tmpcnf" mv $mycnf $tmpcnf fi + oldmask=`umask` umask 077 cat > $mycnf <