Updates to handle vservers

This commit is contained in:
Micah Anderson 2005-05-24 19:27:43 +00:00
parent 4f36863c09
commit 1e410a6d95
9 changed files with 194 additions and 30 deletions

1
README
View File

@ -23,6 +23,7 @@ Features:
- backup actions can be scheduled
- you can choose when status report emails are mailed to you
(always, on warning, on error, never).
- works with linux-vservers
The following options are available:
-h, --help This usage message

View File

@ -426,6 +426,10 @@ getconf MYSQLHOTCOPY /usr/bin/mysqlhotcopy
getconf MYSQLDUMP /usr/bin/mysqldump
getconf GZIP /bin/gzip
getconf RSYNC /usr/bin/rsync
getconf vservers no
getconf VSERVERINFO /usr/sbin/vserver-info
getconf VSERVER /usr/sbin/vserver
getconf VROOTDIR `$VSERVERINFO info SYSINFO |grep vserver-Rootdir | awk '{print $2}'`
if [ ! -d "$configdirectory" ]; then
echo "Configuration directory '$configdirectory' not found."
@ -439,6 +443,11 @@ if [ "$UID" != "0" ]; then
exit 1
fi
if [ "$VSERVERS" = "yes" -a ! -d $VROOTDIR ]; then
echo "vservers option set in config, but $VROOTDIR is not a directory!"
fatal "vservers option set in config, but $VROOTDIR is not a directory!"
fi
## Process each configuration file
# by default, don't make files which are world or group readable.

View File

@ -5,7 +5,7 @@ databases = all
backupdir = /var/backups/mysql
hotcopy = yes
sqldump = yes
compress = yes
compress = yes
#
# user = <user>
@ -44,4 +44,7 @@ compress = yes
# compress = < yes | no >
# if yes, compress the sqldump output.
#
# vsname = <vserver>
# 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

View File

@ -18,3 +18,6 @@
## the hotbackup program to use.
# HOTBACKUP = /usr/lib/subversion/hot-backup.py
## the name of the vserver containing svn, if using vservers
# vsname =

View File

@ -43,3 +43,7 @@ usecolors = yes
# default value for 'when'
when = everyday at 01:00
# if running vservers, set to yes
VSERVERS = no

View File

@ -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

View File

@ -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 '/*' "

View File

@ -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

View File

@ -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.