# 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
for i in $ignores $nodata; do
ignore="$ignore --ignore-table=$i"
done
-
+
+if [ $usevserver = yes ]; then
+ vroot="$VROOTDIR/$vsname"
+ vexec="$VSERVER $vsname exec"
+else
+ vroot=""
+ vexec=""
+fi
+
# create backup dirs, $vroot will be empty if no vsname was specified
# and we will instead proceed to operate on the host
[ -d $vroot$backupdir ] || mkdir -p $vroot$backupdir
hotdir="$backupdir/hotcopy"
dumpdir="$backupdir/sqldump"
-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
-else
- [ "$sqldump" == "no" -o -d $dumpdir ] || mkdir -p $dumpdir
- [ "$hotcopy" == "no" -o -d $hotdir ] || mkdir -p $hotdir
-fi
+[ "$sqldump" == "no" -o -d $vroot$dumpdir ] || $vexec mkdir -p $vroot$dumpdir
+[ "$hotcopy" == "no" -o -d $vroot$hotdir ] || $vexec mkdir -p $vroot$hotdir
#######################################################################
## AUTHENTICATION
if [ "$dbusername" != "" -a "$dbpassword" != "" ]
then
- if [ $usevserver = yes ]
- then
- vhome=`$VSERVER $vsname exec getent passwd "root" | @AWK@ -F: '{print $6}'`
- home="$vroot$vhome"
- else
- home=`getent passwd "root" | @AWK@ -F: '{print $6}'`
- fi
+ vhome=`$vexec getent passwd "root" | @AWK@ -F: '{print $6}'`
+ home=$vroot$vhome
[ -d $home ] || fatal "Can't find root's home directory ($home)."
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=$vhome/.my.cnf"
fi
# if a user is not set, use $configfile, otherwise use $mycnf
userset=true;
if [ $usevserver = yes ]
then
- vuserhome=`$VSERVER $vsname exec getent passwd "$user" | @AWK@ -F: '{print $6}'`
+ vuserhome=`$vexec getent passwd "$user" | @AWK@ -F: '{print $6}'`
if [ $? -eq 2 ]
then
fatal "User $user not found in /etc/passwd"
fi
userhome="$vroot$vuserhome"
- else
- userhome=`getent passwd "$user" | @AWK@ -F: '{print $6}'`
- if [ $? -eq 2 ]
- then
- 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"
- if [ $usevserver = yes ]; then
- defaultsfile="--defaults-extra-file=$vuserhome/.my.cnf"
- else
- defaultsfile="--defaults-extra-file=$userhome/.my.cnf"
- fi
+ defaultsfile="--defaults-extra-file=$vuserhome/.my.cnf"
debug "using $defaultsfile"
fi
info "Initializing hotcopy method"
if [ "$databases" == "all" ]
then
- if [ $usevserver = yes ]
- then
- info "dbhost: $dbhost"
- execstr="$VSERVER $vsname exec $MYSQLHOTCOPY -h $dbhost --quiet --allowold --regexp /.\*/./.\*/ $hotdir"
- else
- execstr="$MYSQLHOTCOPY -h $dbhost --quiet --allowold --regexp /.\*/./.\*/ $hotdir"
- fi
+ info "dbhost: $dbhost"
+ execstr="$vexec $MYSQLHOTCOPY -h $dbhost --quiet --allowold --regexp /.\*/./.\*/ $hotdir"
+
debug "su $user -c \"$execstr\""
if [ ! $test ]
then
else
for db in $databases
do
- if [ $usevserver = yes ]
- then
- execstr="$VSERVER $vsname exec $MYSQLHOTCOPY -h $dbhost --allowold $db $hotdir"
- else
- execstr="$MYSQLHOTCOPY -h $dbhost --allowold $db $hotdir"
- fi
+ execstr="$vexec $MYSQLHOTCOPY -h $dbhost --allowold $db $hotdir"
+
debug 'su $user -c \"$execstr\"'
if [ ! $test ]
then
info "Initializing SQL dump method"
if [ "$databases" == "all" ]
then
- if [ $usevserver = yes ]
- then
- debug "$VSERVER $vsname exec su $user -c \"$MYSQL $defaultsfile -N -B -e 'show databases'\" | sed 's/|//g;/\+----/d'"
- databases=`$VSERVER $vsname exec su $user -c "$MYSQL $defaultsfile -N -B -e 'show databases'" | sed 's/|//g;/\+----/d'`
- if [ $? -ne 0 ]
- then
- fatal "Authentication problem, maybe user/password is wrong or mysqld is not running?"
- fi
- else
- databases=$(su $user -c "$MYSQL $defaultsfile -N -B -e 'show databases'" | sed 's/|//g;/\+----/d')
- if [ $? -ne 0 ]
- then
- fatal "Authentication problem, maybe user/password is wrong or mysqld is not running?"
- fi
- fi
+ debug "$vexec su $user -c \"$MYSQL $defaultsfile -N -B -e 'show databases'\" | sed 's/|//g;/\+----/d'"
+ # -N removes the column title and -B should remove the ASCII table borders, but doesn't always so we use sed to make sure.
+ databases=`$vexec su $user -c "$MYSQL $defaultsfile -N -B -e 'show databases'" | sed 's/|//g;/\+----/d'`
+ if [ $? -ne 0 ]
+ then
+ fatal "Authentication problem, maybe user/password is wrong or mysqld is not running?"
+ fi
fi
for db in $databases
done
DUMP="( $DUMP; $DUMP_STRUCT )"
fi
- if [ $usevserver = yes ]
- then
- # Test to make sure mysqld is running, if it is not sqldump will not work
- $VSERVER $vsname exec su $user -c "$MYSQLADMIN $defaultsfile ping"
- if [ $? -ne 0 ]; then
- fatal "Either you have an authentication problem, or mysqld doesn't appear to be running!"
- fi
- if [ "$compress" == "yes" ]; then
- execstr="$VSERVER $vsname exec $DUMP | $GZIP > $vroot$dumpdir/${db}.sql.gz"
- else
- 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
- su $user -c "$MYSQLADMIN $defaultsfile ping"
- if [ $? -ne 0 ]; then
- fatal "Either you have an authentication problem, or mysqld doesn't appear to be running!"
- fi
- if [ "$compress" == "yes" ]; then
- execstr="$DUMP | $GZIP > $dumpdir/${db}.sql.gz"
- else
- execstr="$DUMP -r $dumpdir/${db}.sql"
- fi
- fi
+ # Test to make sure mysqld is running, if it is not sqldump will not work
+ $vexec su $user -c "$MYSQLADMIN $defaultsfile ping"
+ if [ $? -ne 0 ]; then
+ fatal "Either you have an authentication problem, or mysqld doesn't appear to be running!"
+ fi
+ if [ "$compress" == "yes" ]; then
+ execstr="$vexec $DUMP | $GZIP > $vroot$dumpdir/${db}.sql.gz"
+ else
+ execstr="$vexec $DUMP -r $vroot$dumpdir/${db}.sql"
+ fi
+
debug "su $user -c \"$execstr\""
if [ ! $test ]
then