mirror of
https://0xacab.org/liberate/backupninja.git
synced 2024-11-13 22:32:29 +01:00
Updates to handle vservers
This commit is contained in:
parent
4f36863c09
commit
1e410a6d95
1
README
1
README
@ -23,6 +23,7 @@ Features:
|
|||||||
- backup actions can be scheduled
|
- backup actions can be scheduled
|
||||||
- you can choose when status report emails are mailed to you
|
- you can choose when status report emails are mailed to you
|
||||||
(always, on warning, on error, never).
|
(always, on warning, on error, never).
|
||||||
|
- works with linux-vservers
|
||||||
|
|
||||||
The following options are available:
|
The following options are available:
|
||||||
-h, --help This usage message
|
-h, --help This usage message
|
||||||
|
@ -426,6 +426,10 @@ getconf MYSQLHOTCOPY /usr/bin/mysqlhotcopy
|
|||||||
getconf MYSQLDUMP /usr/bin/mysqldump
|
getconf MYSQLDUMP /usr/bin/mysqldump
|
||||||
getconf GZIP /bin/gzip
|
getconf GZIP /bin/gzip
|
||||||
getconf RSYNC /usr/bin/rsync
|
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
|
if [ ! -d "$configdirectory" ]; then
|
||||||
echo "Configuration directory '$configdirectory' not found."
|
echo "Configuration directory '$configdirectory' not found."
|
||||||
@ -439,6 +443,11 @@ if [ "$UID" != "0" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
## Process each configuration file
|
||||||
|
|
||||||
# by default, don't make files which are world or group readable.
|
# by default, don't make files which are world or group readable.
|
||||||
|
@ -44,4 +44,7 @@ compress = yes
|
|||||||
# compress = < yes | no >
|
# compress = < yes | no >
|
||||||
# if yes, compress the sqldump output.
|
# 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
|
||||||
|
|
||||||
|
@ -18,3 +18,6 @@
|
|||||||
|
|
||||||
## the hotbackup program to use.
|
## the hotbackup program to use.
|
||||||
# HOTBACKUP = /usr/lib/subversion/hot-backup.py
|
# HOTBACKUP = /usr/lib/subversion/hot-backup.py
|
||||||
|
|
||||||
|
## the name of the vserver containing svn, if using vservers
|
||||||
|
# vsname =
|
@ -43,3 +43,7 @@ usecolors = yes
|
|||||||
|
|
||||||
# default value for 'when'
|
# default value for 'when'
|
||||||
when = everyday at 01:00
|
when = everyday at 01:00
|
||||||
|
|
||||||
|
# if running vservers, set to yes
|
||||||
|
VSERVERS = no
|
||||||
|
|
||||||
|
@ -11,15 +11,43 @@ getconf dbhost localhost
|
|||||||
getconf hotcopy no
|
getconf hotcopy no
|
||||||
getconf sqldump no
|
getconf sqldump no
|
||||||
getconf user root
|
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
|
# Check to make sure that the specified vserver exists
|
||||||
[ -d $backupdir ] || fatal "Backup directory '$backupdir'"
|
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"
|
hotdir="$backupdir/hotcopy"
|
||||||
dumpdir="$backupdir/sqldump"
|
dumpdir="$backupdir/sqldump"
|
||||||
|
|
||||||
|
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
|
[ "$sqldump" == "no" -o -d $dumpdir ] || mkdir -p $dumpdir
|
||||||
[ "$hotcopy" == "no" -o -d $hotdir ] || mkdir -p $hotdir
|
[ "$hotcopy" == "no" -o -d $hotdir ] || mkdir -p $hotdir
|
||||||
|
fi
|
||||||
|
|
||||||
# create .my.cnf
|
# create .my.cnf
|
||||||
# (we do this because we don't want to have to specify the password on the command line
|
# (we do this because we don't want to have to specify the password on the command line
|
||||||
@ -27,9 +55,9 @@ dumpdir="$backupdir/sqldump"
|
|||||||
# temporary ~/.my.cnf in root's home directory).
|
# temporary ~/.my.cnf in root's home directory).
|
||||||
|
|
||||||
if [ "$dbusername" != "" ]; then
|
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)."
|
[ -d $home ] || fatal "Can't find root's home directory ($home)."
|
||||||
mycnf="$home/.my.cnf"
|
mycnf="$vroot$home/.my.cnf"
|
||||||
if [ -f $mycnf ]; then
|
if [ -f $mycnf ]; then
|
||||||
# rename temporarily
|
# rename temporarily
|
||||||
tmpcnf="$home/my.cnf.disable"
|
tmpcnf="$home/my.cnf.disable"
|
||||||
@ -59,7 +87,12 @@ fi
|
|||||||
|
|
||||||
if [ "$hotcopy" == "yes" ]; then
|
if [ "$hotcopy" == "yes" ]; then
|
||||||
if [ "$databases" == "all" ]; then
|
if [ "$databases" == "all" ]; then
|
||||||
|
if [ $usevserver ]
|
||||||
|
then
|
||||||
|
execstr="$VSERVER $vsname exec $MYSQLHOTCOPY --quiet --allowold --regexp /.\*/./.\*/ $hotdir"
|
||||||
|
else
|
||||||
execstr="$MYSQLHOTCOPY --quiet --allowold --regexp /.\*/./.\*/ $hotdir"
|
execstr="$MYSQLHOTCOPY --quiet --allowold --regexp /.\*/./.\*/ $hotdir"
|
||||||
|
fi
|
||||||
debug "su $user -c '$execstr'"
|
debug "su $user -c '$execstr'"
|
||||||
if [ ! $test ]; then
|
if [ ! $test ]; then
|
||||||
output=`su $user -c "$execstr" 2>&1`
|
output=`su $user -c "$execstr" 2>&1`
|
||||||
@ -74,7 +107,12 @@ if [ "$hotcopy" == "yes" ]; then
|
|||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
for db in $databases; do
|
for db in $databases; do
|
||||||
|
if [ $usevserver ]
|
||||||
|
then
|
||||||
|
execstr="$VSERVER $vsname exec $MYSQLHOTCOPY --allowold $db $hotdir"
|
||||||
|
else
|
||||||
execstr="$MYSQLHOTCOPY --allowold $db $hotdir"
|
execstr="$MYSQLHOTCOPY --allowold $db $hotdir"
|
||||||
|
fi
|
||||||
debug "su $user -c '$execstr'"
|
debug "su $user -c '$execstr'"
|
||||||
if [ ! $test ]; then
|
if [ ! $test ]; then
|
||||||
output=`su $user -c "$execstr" 2>&1`
|
output=`su $user -c "$execstr" 2>&1`
|
||||||
@ -95,11 +133,21 @@ fi
|
|||||||
|
|
||||||
if [ "$sqldump" == "yes" ]; then
|
if [ "$sqldump" == "yes" ]; then
|
||||||
if [ "$databases" == "all" ]; then
|
if [ "$databases" == "all" ]; then
|
||||||
|
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`
|
databases=`echo 'show databases' | su $user -c "$MYSQL" | grep -v Database`
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
for db in $databases; do
|
for db in $databases; do
|
||||||
|
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"
|
execstr="$MYSQLDUMP --lock-tables --complete-insert --add-drop-table --quick --quote-names $db > $dumpdir/${db}.sql"
|
||||||
|
fi
|
||||||
debug "su $user -c '$execstr'"
|
debug "su $user -c '$execstr'"
|
||||||
if [ ! $test ]; then
|
if [ ! $test ]; then
|
||||||
output=`su $user -c "$execstr" 2>&1`
|
output=`su $user -c "$execstr" 2>&1`
|
||||||
@ -115,7 +163,7 @@ if [ "$sqldump" == "yes" ]; then
|
|||||||
done
|
done
|
||||||
|
|
||||||
if [ "$compress" == "yes" ]; then
|
if [ "$compress" == "yes" ]; then
|
||||||
output=`$GZIP -f $dumpdir/*.sql 2>&1`
|
output=`$GZIP -f $vroot$dumpdir/*.sql 2>&1`
|
||||||
debug $output
|
debug $output
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -12,6 +12,7 @@ getconf type; sourcetype=$type
|
|||||||
getconf label
|
getconf label
|
||||||
getconf keep 60
|
getconf keep 60
|
||||||
getconf include
|
getconf include
|
||||||
|
getconf vsinclude
|
||||||
getconf exclude
|
getconf exclude
|
||||||
|
|
||||||
### DESTINATION ###
|
### DESTINATION ###
|
||||||
@ -24,6 +25,18 @@ getconf type; desttype=$type
|
|||||||
getconf user; destuser=$user
|
getconf user; destuser=$user
|
||||||
getconf host; desthost=$host
|
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"
|
[ "$destdir" != "" ] || fatal "Destination directory not set"
|
||||||
|
|
||||||
if [ "$desttype" == "remote" ]; then
|
if [ "$desttype" == "remote" ]; then
|
||||||
@ -54,7 +67,8 @@ fi
|
|||||||
|
|
||||||
[ "$label" != "" ] || fatal "Source missing label"
|
[ "$label" != "" ] || fatal "Source missing label"
|
||||||
[ "$sourcetype" == "local" ] || fatal "Only local source type supported"
|
[ "$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="/"
|
execstr_clientpart="/"
|
||||||
|
|
||||||
@ -101,6 +115,19 @@ for i in $include; do
|
|||||||
execstr="${execstr}--include '$str' "
|
execstr="${execstr}--include '$str' "
|
||||||
done
|
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
|
# exclude everything else
|
||||||
execstr="${execstr}--exclude '/*' "
|
execstr="${execstr}--exclude '/*' "
|
||||||
|
|
||||||
|
45
handlers/svn
45
handlers/svn
@ -6,42 +6,69 @@ getconf src /var/lib/svn
|
|||||||
getconf dest /var/backups/svn
|
getconf dest /var/backups/svn
|
||||||
getconf tmp /var/backups/svn.tmp
|
getconf tmp /var/backups/svn.tmp
|
||||||
getconf HOTBACKUP /usr/lib/subversion/hot-backup.py
|
getconf HOTBACKUP /usr/lib/subversion/hot-backup.py
|
||||||
|
getconf vsname
|
||||||
|
|
||||||
error=0
|
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`
|
for repo in `find . -name svnserve.conf`
|
||||||
do
|
do
|
||||||
repo=`dirname $repo`
|
repo=`dirname $repo`
|
||||||
repo=`dirname $repo`
|
repo=`dirname $repo`
|
||||||
|
|
||||||
ret=`mkdir -p $tmp/$repo 2>&1`
|
ret=`mkdir -p $vroot$tmp/$repo 2>&1`
|
||||||
code=$?
|
code=$?
|
||||||
if [ "$ret" ]; then
|
if [ "$ret" ]; then
|
||||||
debug "$ret"
|
debug "$ret"
|
||||||
fi
|
fi
|
||||||
if [ $code != 0 ]; then
|
if [ $code != 0 ]; then
|
||||||
error "command failed mkdir -p $tmp/$repo"
|
error "command failed mkdir -p $vroot$tmp/$repo"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ $usevserver ]
|
||||||
|
then
|
||||||
|
ret=`$VSERVER $vsname exec $HOTBACKUP $src/$repo $tmp/$repo 2>&1`
|
||||||
|
else
|
||||||
ret=`$HOTBACKUP $src/$repo $tmp/$repo 2>&1`
|
ret=`$HOTBACKUP $src/$repo $tmp/$repo 2>&1`
|
||||||
|
fi
|
||||||
code=$?
|
code=$?
|
||||||
if [ "$ret" ]; then
|
if [ "$ret" ]; then
|
||||||
debug "$ret"
|
debug "$ret"
|
||||||
fi
|
fi
|
||||||
if [ $code != 0 ]; then
|
if [ $code != 0 ]; then
|
||||||
error "command failed -- $HOTBACKUP $src/$repo $tmp/$repo"
|
error "command failed -- $HOTBACKUP $vroot$src/$repo $vroot$tmp/$repo"
|
||||||
error=1
|
error=1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ $error -eq 1 ]; then
|
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
|
else
|
||||||
if [ -d $dest -a -d $tmp ]; then
|
if [ -d $vroot$dest -a -d $vroot$tmp ]; then
|
||||||
rm -rf $dest
|
rm -rf $vroot$dest
|
||||||
fi
|
fi
|
||||||
if [ -d $tmp ]; then
|
if [ -d $vroot$tmp ]; then
|
||||||
mv $tmp $dest
|
mv $vroot$tmp $vroot$dest
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
42
handlers/sys
42
handlers/sys
@ -26,12 +26,42 @@ getconf partitionsfile /var/backups/partitions.__star__.txt
|
|||||||
getconf hardware yes
|
getconf hardware yes
|
||||||
getconf hardwarefile /var/backups/hardware.txt
|
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 [ "$packages" == "yes" ]; then
|
||||||
|
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
|
if [ ! -x "`which dpkg`" ]; then
|
||||||
warning "can't find dpkg, skipping installed packages report."
|
warning "can't find dpkg, skipping installed packages report."
|
||||||
packages="no"
|
packages="no"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$partitions" == "yes" ]; then
|
if [ "$partitions" == "yes" ]; then
|
||||||
if [ ! -x "`which sfdisk`" ]; then
|
if [ ! -x "`which sfdisk`" ]; then
|
||||||
@ -57,10 +87,22 @@ fi
|
|||||||
# here we grab a list of the packages installed and removed.
|
# 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
|
if [ "$packages" == "yes" ]; then
|
||||||
|
debug "dpkg --get-selections > $packagesfile"
|
||||||
dpkg --get-selections > $packagesfile
|
dpkg --get-selections > $packagesfile
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
## PARTITIONS #############################
|
## PARTITIONS #############################
|
||||||
|
|
||||||
# here we use sfdisk to dump a listing of all the partitions.
|
# here we use sfdisk to dump a listing of all the partitions.
|
||||||
|
Loading…
Reference in New Issue
Block a user