aboutsummaryrefslogtreecommitdiff
path: root/handlers
diff options
context:
space:
mode:
authorMicah Anderson <micah@riseup.net>2005-05-24 19:27:43 +0000
committerMicah Anderson <micah@riseup.net>2005-05-24 19:27:43 +0000
commit1e410a6d9574c56b7d3a3633b82220eacf782d06 (patch)
treefd66e45778a58f6823e86d5ad1e1dfab8e2dad92 /handlers
parent4f36863c09ad4e3c2613531873292e0e5c1250a2 (diff)
downloadbackupninja-1e410a6d9574c56b7d3a3633b82220eacf782d06.tar.gz
backupninja-1e410a6d9574c56b7d3a3633b82220eacf782d06.tar.bz2
Updates to handle vservers
Diffstat (limited to 'handlers')
-rw-r--r--handlers/mysql78
-rw-r--r--handlers/rdiff29
-rw-r--r--handlers/svn47
-rwxr-xr-xhandlers/sys48
4 files changed, 173 insertions, 29 deletions
diff --git a/handlers/mysql b/handlers/mysql
index 6a8c3dd..b552dde 100644
--- a/handlers/mysql
+++ b/handlers/mysql
@@ -11,25 +11,53 @@ getconf dbhost localhost
getconf hotcopy no
getconf sqldump no
getconf user root
+getconf vsname
-# create backup dirs
+# 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
-[ -d $backupdir ] || mkdir -p $backupdir
-[ -d $backupdir ] || fatal "Backup directory '$backupdir'"
+# Check to make sure that the specified vserver exists
+if [ $usevserver ]
+then
+ vroot="$VROOTDIR/$vsname"
+ [ -d $vroot ] || fatal "vserver '$vsname' does not exist at '$vroot'"
+fi
+
+# create backup dirs, the vroot variable will be empty if no vsname was specified
+# and will proceed to operate on the host
+[ -d $vroot$backupdir ] || mkdir -p $vroot$backupdir
+[ -d $vroot$backupdir ] || fatal "Backup directory '$vroot$backupdir'"
hotdir="$backupdir/hotcopy"
dumpdir="$backupdir/sqldump"
-[ "$sqldump" == "no" -o -d $dumpdir ] || mkdir -p $dumpdir
-[ "$hotcopy" == "no" -o -d $hotdir ] || mkdir -p $hotdir
+
+if [ $usevserver ]
+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
# create .my.cnf
- # (we do this because we don't want to have to specify the password on the command line
- # because then anyone would be able to see it with a 'ps aux'. instead, we create a
- # temporary ~/.my.cnf in root's home directory).
+# (we do this because we don't want to have to specify the password on the command line
+# because then anyone would be able to see it with a 'ps aux'. instead, we create a
+# temporary ~/.my.cnf in root's home directory).
if [ "$dbusername" != "" ]; then
- home=`grep '^root:' /etc/passwd | awk -F: '{print $6}'`
+ home=`grep '^root:' $vroot/etc/passwd | awk -F: '{print $6}'`
[ -d $home ] || fatal "Can't find root's home directory ($home)."
- mycnf="$home/.my.cnf"
+ mycnf="$vroot$home/.my.cnf"
if [ -f $mycnf ]; then
# rename temporarily
tmpcnf="$home/my.cnf.disable"
@@ -59,7 +87,12 @@ fi
if [ "$hotcopy" == "yes" ]; then
if [ "$databases" == "all" ]; then
- execstr="$MYSQLHOTCOPY --quiet --allowold --regexp /.\*/./.\*/ $hotdir"
+ if [ $usevserver ]
+ then
+ execstr="$VSERVER $vsname exec $MYSQLHOTCOPY --quiet --allowold --regexp /.\*/./.\*/ $hotdir"
+ else
+ execstr="$MYSQLHOTCOPY --quiet --allowold --regexp /.\*/./.\*/ $hotdir"
+ fi
debug "su $user -c '$execstr'"
if [ ! $test ]; then
output=`su $user -c "$execstr" 2>&1`
@@ -74,7 +107,12 @@ if [ "$hotcopy" == "yes" ]; then
fi
else
for db in $databases; do
- execstr="$MYSQLHOTCOPY --allowold $db $hotdir"
+ if [ $usevserver ]
+ then
+ execstr="$VSERVER $vsname exec $MYSQLHOTCOPY --allowold $db $hotdir"
+ else
+ execstr="$MYSQLHOTCOPY --allowold $db $hotdir"
+ fi
debug "su $user -c '$execstr'"
if [ ! $test ]; then
output=`su $user -c "$execstr" 2>&1`
@@ -95,11 +133,21 @@ fi
if [ "$sqldump" == "yes" ]; then
if [ "$databases" == "all" ]; then
- databases=`echo 'show databases' | su $user -c "$MYSQL" | grep -v Database`
+ if [ $usevserver ]
+ then
+ databases=`echo 'show databases' | $VSERVER $vsname exec su $user -c "$MYSQL" | grep -v Database`
+ else
+ databases=`echo 'show databases' | su $user -c "$MYSQL" | grep -v Database`
+ fi
fi
for db in $databases; do
- execstr="$MYSQLDUMP --lock-tables --complete-insert --add-drop-table --quick --quote-names $db > $dumpdir/${db}.sql"
+ if [ $usevserver ]
+ then
+ execstr="$VSERVER $vsname exec $MYSQLDUMP --lock-tables --complete-insert --add-drop-table --quick --quote-names $db > $vroot$dumpdir/${db}.sql"
+ else
+ execstr="$MYSQLDUMP --lock-tables --complete-insert --add-drop-table --quick --quote-names $db > $dumpdir/${db}.sql"
+ fi
debug "su $user -c '$execstr'"
if [ ! $test ]; then
output=`su $user -c "$execstr" 2>&1`
@@ -115,7 +163,7 @@ if [ "$sqldump" == "yes" ]; then
done
if [ "$compress" == "yes" ]; then
- output=`$GZIP -f $dumpdir/*.sql 2>&1`
+ output=`$GZIP -f $vroot$dumpdir/*.sql 2>&1`
debug $output
fi
fi
diff --git a/handlers/rdiff b/handlers/rdiff
index 61eb7f5..ca97fa4 100644
--- a/handlers/rdiff
+++ b/handlers/rdiff
@@ -12,6 +12,7 @@ getconf type; sourcetype=$type
getconf label
getconf keep 60
getconf include
+getconf vsinclude
getconf exclude
### DESTINATION ###
@@ -24,6 +25,18 @@ getconf type; desttype=$type
getconf user; destuser=$user
getconf host; desthost=$host
+# See if vservers are configured
+if [ "$VSERVERS" = "yes" ]
+then
+ if [ ! -d $VROOTDIR ]
+ then
+ fatal "vservers enabled, but $VROOTDIR does not exist!"
+ else
+ info "vserver method enabled"
+ usevserver=1
+ fi
+fi
+
[ "$destdir" != "" ] || fatal "Destination directory not set"
if [ "$desttype" == "remote" ]; then
@@ -54,7 +67,8 @@ fi
[ "$label" != "" ] || fatal "Source missing label"
[ "$sourcetype" == "local" ] || fatal "Only local source type supported"
-[ "$include" != "" ] || fatal "No source includes specified"
+[ "$include" != "" -o "$vsinclude" != "" ] || fatal "No source includes specified"
+#TODO should I test for vsinclude if usevservers=1?
execstr_clientpart="/"
@@ -101,6 +115,19 @@ for i in $include; do
execstr="${execstr}--include '$str' "
done
+# vsinclude
+if [ $usevserver ]
+then
+ for vserver in `ls $VROOTDIR|grep -v lost+found`
+ do
+ for vi in $vsinclude
+ do
+ str="${vi//__star__/*}"
+ execstr="${execstr}--include '$VROOTDIR/$vserver$str' "
+ done
+ done
+fi
+
# exclude everything else
execstr="${execstr}--exclude '/*' "
diff --git a/handlers/svn b/handlers/svn
index d0e3648..cd3cc2e 100644
--- a/handlers/svn
+++ b/handlers/svn
@@ -6,42 +6,69 @@ getconf src /var/lib/svn
getconf dest /var/backups/svn
getconf tmp /var/backups/svn.tmp
getconf HOTBACKUP /usr/lib/subversion/hot-backup.py
+getconf vsname
error=0
-cd $src
+
+# 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
+
+# Check to make sure that the specified vserver exists
+if [ $usevserver ]
+then
+ vroot="$VROOTDIR/$vsname"
+ [ -d $vroot ] || fatal "vserver '$vsname' does not exist at '$vroot'"
+fi
+
+cd $vroot$src
for repo in `find . -name svnserve.conf`
do
repo=`dirname $repo`
repo=`dirname $repo`
- ret=`mkdir -p $tmp/$repo 2>&1`
+ ret=`mkdir -p $vroot$tmp/$repo 2>&1`
code=$?
if [ "$ret" ]; then
debug "$ret"
fi
if [ $code != 0 ]; then
- error "command failed mkdir -p $tmp/$repo"
+ error "command failed mkdir -p $vroot$tmp/$repo"
fi
- ret=`$HOTBACKUP $src/$repo $tmp/$repo 2>&1`
+ if [ $usevserver ]
+ then
+ ret=`$VSERVER $vsname exec $HOTBACKUP $src/$repo $tmp/$repo 2>&1`
+ else
+ ret=`$HOTBACKUP $src/$repo $tmp/$repo 2>&1`
+ fi
code=$?
if [ "$ret" ]; then
debug "$ret"
fi
if [ $code != 0 ]; then
- error "command failed -- $HOTBACKUP $src/$repo $tmp/$repo"
+ error "command failed -- $HOTBACKUP $vroot$src/$repo $vroot$tmp/$repo"
error=1
fi
done
if [ $error -eq 1 ]; then
- echo "Error: because of earlier errors, we are leaving svn backups in $tmp instead of $dest"
+ echo "Error: because of earlier errors, we are leaving svn backups in $vroot$tmp instead of $vroot$dest"
else
- if [ -d $dest -a -d $tmp ]; then
- rm -rf $dest
+ if [ -d $vroot$dest -a -d $vroot$tmp ]; then
+ rm -rf $vroot$dest
fi
- if [ -d $tmp ]; then
- mv $tmp $dest
+ if [ -d $vroot$tmp ]; then
+ mv $vroot$tmp $vroot$dest
fi
fi
diff --git a/handlers/sys b/handlers/sys
index fe780b5..f111097 100755
--- a/handlers/sys
+++ b/handlers/sys
@@ -26,10 +26,40 @@ getconf partitionsfile /var/backups/partitions.__star__.txt
getconf hardware yes
getconf hardwarefile /var/backups/hardware.txt
+# See if vservers are configured
+if [ "$VSERVERS" = "yes" ]
+then
+ if [ ! -d $VROOTDIR ]
+ then
+ fatal "vservers enabled, but $VROOTDIR does not exist!"
+ else
+ info "vserver method enabled"
+ usevserver=1
+ fi
+fi
+
if [ "$packages" == "yes" ]; then
- if [ ! -x "`which dpkg`" ]; then
- warning "can't find dpkg, skipping installed packages report."
- packages="no"
+ if [ $usevserver ]
+ then
+ for vserver in `ls $VROOTDIR |grep -v lost+found`
+ do
+ running=`vserver-info $vserver RUNNING`
+ if [ $running = 1]; then
+ if [ ! -x "`$VSERVER $vserver exec which dpkg`" ]; then
+ warning "can't find dpkg in vserver $vserver, skipping installed packages report."
+ nodpkg="$nodpkg $vserver"
+ fi
+ else
+ warning "vserver $vserver is not running, skipping installed packages report."
+ nodpkg="$nodpkg $vserver"
+ fi
+
+ done
+ else
+ if [ ! -x "`which dpkg`" ]; then
+ warning "can't find dpkg, skipping installed packages report."
+ packages="no"
+ fi
fi
fi
@@ -57,10 +87,22 @@ fi
# here we grab a list of the packages installed and removed.
#
+if [ $usevserver ]
+then
+ for vserver in `ls $VROOTDIR | grep -v $nodpkg | grep -v lost+found`
+ do
+ debug "$VSERVER $vserver exec dpkg --get-selections > $VROOTDIR/$vserver$packagesfile"
+ $VSERVER $vserver exec dpkg --get-selections > $VROOTDIR/$vserver$packagesfile
+ done
+fi
+
+# We want to perform this on the host as well
if [ "$packages" == "yes" ]; then
+ debug "dpkg --get-selections > $packagesfile"
dpkg --get-selections > $packagesfile
fi
+
## PARTITIONS #############################
# here we use sfdisk to dump a listing of all the partitions.