From 9341c146cc103ab8a4d24fac699f1b88acd563ad Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Mon, 5 Jan 2009 17:36:03 +0100 Subject: [PATCH] mysql: Support multiple vservers. This adds the vsnames configuration variable, while still supporting the vsname variable (with a warning). --- examples/example.mysql | 8 +++---- handlers/mysql.in | 51 +++++++++++++++++++++++++++--------------- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/examples/example.mysql b/examples/example.mysql index 5fbf009..a16a9d0 100644 --- a/examples/example.mysql +++ b/examples/example.mysql @@ -82,10 +82,10 @@ compress = yes # compress = < yes | no > (default = yes) # if yes, compress the sqldump output. # -# vsname = (no default) -# what vserver to operate on (only used if vserver = yes -# in /etc/backupninja.conf), if you do not specify a vsname the -# host will be operated on +# vsnames = all | (no default) +# what vservers to operate on (only used if vserver = yes +# in /etc/backupninja.conf), if you do not specify vsnames the +# host will be operated on. # # NB: databases = all doesn't seem to work with hotcopy = yes # when vsname is specified, I would like to know how to fix this. diff --git a/handlers/mysql.in b/handlers/mysql.in index 066b874..d3e15ab 100644 --- a/handlers/mysql.in +++ b/handlers/mysql.in @@ -13,6 +13,7 @@ getconf sqldump no getconf sqldumpoptions "--lock-tables --complete-insert --add-drop-table --quick --quote-names" getconf compress yes getconf vsname +getconf vsnames # authentication: getconf user @@ -25,22 +26,28 @@ getconf configfile /etc/mysql/debian.cnf # 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 ? - vservers_running $vsname || fatal "The vserver $vsname is not running." - # everything ok - info "Using vserver '$vsname'." - usevserver=yes + +if [ -n "$vsname" ]; then + if [ -z "$vsnames" ]; then + warning "Using deprecated 'vsname' configuration variable" + vsnames="$vsname" else - info "No vserver name specified, actions will be performed on the host." + warning "Ignoring (deprecated) vsname configuration variable, since vsnames is given" + fi +fi + +if [ $vservers_are_available = yes -a -n "$vsnames" ]; then + if [ "$vsnames" = all ]; then + vsnames="$found_vservers" + else + if ! vservers_exist "$vsnames" ; then + fatal "At least one of the vservers listed in vsnames ($vsnames) does not exist." + fi fi + info "Using vservers '$vsnames'" + usevserver=yes else - [ -z "$vsname" ] || warning 'vservers support disabled in backupninja.conf, vsname configuration line will be ignored' + [ -z "$vsnames" ] || warning 'vservers support disabled in backupninja.conf, vsnames configuration line will be ignored' fi ## Prepare ignore part of the command @@ -53,12 +60,18 @@ done function make_backup() { vsname="$1" - if [ -n "$vsname" ]; then - vroot="$VROOTDIR/$vsname" - vexec="$VSERVER $vsname exec" - else + if [ -z "$vsname" ]; then + info "Running on host" vroot="" vexec="" + else + if ! vservers_running "$vsname"; then + error "vserver $vsname is not running!" + return 1 + fi + info "Running on vserver $vsname" + vroot="$VROOTDIR/$vsname" + vexec="$VSERVER $vsname exec" fi interpolated=`interpolate "$backupdir" "$vsname"` @@ -282,7 +295,9 @@ EOF } if [ $usevserver = yes ]; then - make_backup "$vsname" + for vserver in $vsnames; do + make_backup "$vserver" + done else make_backup "" fi -- 2.30.2