Remove vserver support (fixes #11289)

This is probably completely unused by now, as vservers have been
superseeded by alternative technology for many years already.
This commit is contained in:
Jerome Charaoui 2018-06-29 16:50:41 -04:00
parent 076ef20ead
commit eabda5615c
29 changed files with 89 additions and 1026 deletions

1
.gitignore vendored
View File

@ -47,7 +47,6 @@ lib/Makefile
lib/easydialog lib/easydialog
lib/parseini lib/parseini
lib/tools lib/tools
lib/vserver
man/Makefile man/Makefile
src/Makefile src/Makefile
src/backupninja src/backupninja

View File

@ -24,7 +24,6 @@ The key features of backupninja are:
- console-based wizard (ninjahelper) makes it easy to create - console-based wizard (ninjahelper) makes it easy to create
backup action configuration files backup action configuration files
- passwords are never sent via the command line to helper programs - passwords are never sent via the command line to helper programs
- works with [Linux-Vservers](http://linux-vserver.org/)
The following backup types are supported: The following backup types are supported:
@ -82,8 +81,7 @@ To add an additional 'wizard' to ninjahelper, follow these steps:
} }
3. Look at the existing helpers to see how they are written. Try to re-use 3. Look at the existing helpers to see how they are written. Try to re-use
functions, such as the dialog functions that are defined in `easydialog.sh`, functions, such as the dialog functions that are defined in `easydialog.sh`.
or the vserver functions defined in `lib/vserver`.
4. Test, re-test, and test again. Try to break the helper by going backwards, 4. Test, re-test, and test again. Try to break the helper by going backwards,
try to think like someone who has no idea how to configure your handler try to think like someone who has no idea how to configure your handler
@ -215,25 +213,6 @@ Since it performs incremental backups it minimizes the number of request per
operation therefore reducing the costs. The boto Python interface to Amazon operation therefore reducing the costs. The boto Python interface to Amazon
Web Services is needed to use duplicity with S3 (Debian package: `python-boto`). Web Services is needed to use duplicity with S3 (Debian package: `python-boto`).
Vservers
--------
If you are using [Linux-Vservers](http://linux-vserver.org/) there are some
special capabilities that different handlers have to make vserver
backups easier.
Set the variable `vservers` to be `yes` in `/etc/backupninja.conf` and see the
example configuration files for each handler to configure the vserver specific
variables.
Additional vserver variables that can be configured in `/etc/backupninja.conf`,
but they probably don't need to be changed:
- `VSERVERINFO` (default: `/usr/sbin/vserver-info`)
- `VSERVER` (default: `/usr/sbin/vserver`)
- `VROOTDIR` (default: `$VSERVERINFO info SYSINFO |grep vserver-Rootdir | awk '{print $2}'`)
.sh configuration files .sh configuration files
----------------------- -----------------------

View File

@ -72,9 +72,6 @@ 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
# programs paths # programs paths
# SLAPCAT=/usr/sbin/slapcat # SLAPCAT=/usr/sbin/slapcat
# LDAPSEARCH=/usr/bin/ldapsearch # LDAPSEARCH=/usr/bin/ldapsearch
@ -89,6 +86,3 @@ vservers = no
# GZIP=/bin/gzip # GZIP=/bin/gzip
# GZIP_OPTS='--rsyncable' # GZIP_OPTS='--rsyncable'
# RSYNC=/usr/bin/rsync # RSYNC=/usr/bin/rsync
# VSERVERINFO=/usr/sbin/vserver-info
# VSERVER=/usr/sbin/vserver
# VROOTDIR=/var/lib/vservers

View File

@ -137,21 +137,6 @@ include = /usr/local/sbin
include = /var/lib/dpkg/status include = /var/lib/dpkg/status
include = /var/lib/dpkg/status-old include = /var/lib/dpkg/status-old
## If vservers = yes in /etc/backupninja.conf then the following variables can
## be used:
## vsnames = all | <vserver1> <vserver2> ... (default = all)
## vsinclude = <path>
## vsinclude = <path>
## ...
## Any path specified in vsinclude is added to the include list for each vserver
## listed in vsnames (or all if vsnames = all, which is the default).
##
## For example, vsinclude = /home will backup the /home directory in every
## vserver listed in vsnames. If you have 'vsnames = foo bar baz', this
## vsinclude will add to the include list /vservers/foo/home, /vservers/bar/home
## and /vservers/baz/home.
## Vservers paths are derived from $VROOTDIR.
# files to exclude from the backup # files to exclude from the backup
exclude = /home/*/.gnupg exclude = /home/*/.gnupg
exclude = /var/cache/backupninja/duplicity exclude = /var/cache/backupninja/duplicity

View File

@ -79,11 +79,3 @@ compress = yes
# #
# compress = < yes | no > (default = yes) # compress = < yes | no > (default = yes)
# if yes, compress the sqldump output. # if yes, compress the sqldump output.
#
# vsname = <vserver> (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
#
# NB: databases = all doesn't seem to work with hotcopy = yes
# when vsname is specified, I would like to know how to fix this.

View File

@ -1,10 +1,5 @@
### backupninja PostgreSQL config file ### ### backupninja PostgreSQL config file ###
# vsname = <vserver> (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
# Note: if operating on a vserver, $VROOTDIR will be prepended to backupdir.
# backupdir = <dir> (default: /var/backups/postgres) # backupdir = <dir> (default: /var/backups/postgres)
# where to dump the backups # where to dump the backups

View File

@ -103,7 +103,7 @@ type = local
# keep = 60 # keep = 60
## A few notes about includes and excludes: ## A few notes about includes and excludes:
## 1. include, exclude and vsinclude statements support globbing with '*' ## 1. include and exclude statements support globbing with '*'
## 2. Symlinks are not dereferenced. Moreover, an include line whose path ## 2. Symlinks are not dereferenced. Moreover, an include line whose path
## contains, at any level, a symlink to a directory, will only have the ## contains, at any level, a symlink to a directory, will only have the
## symlink backed-up, not the target directory's content. Yes, you have to ## symlink backed-up, not the target directory's content. Yes, you have to
@ -129,21 +129,6 @@ include = /usr/local/sbin
include = /var/lib/dpkg/status include = /var/lib/dpkg/status
include = /var/lib/dpkg/status-old include = /var/lib/dpkg/status-old
## If vservers = yes in /etc/backupninja.conf then the following variables can
## be used:
## vsnames = all | <vserver1> <vserver2> ... (default = all)
## vsinclude = <path>
## vsinclude = <path>
## ...
## Any path specified in vsinclude is added to the include list for each vserver
## listed in vsnames (or all if vsnames = all, which is the default).
##
## For example, vsinclude = /home will backup the /home directory in every
## vserver listed in vsnames. If you have 'vsnames = foo bar baz', this
## vsinclude will add to the include list /vservers/foo/home, /vservers/bar/home
## and /vservers/baz/home.
## Vservers paths are derived from $VROOTDIR.
## files to exclude from the backup ## files to exclude from the backup
exclude = /home/*/.gnupg exclude = /home/*/.gnupg
exclude = /var/cache/backupninja/duplicity exclude = /var/cache/backupninja/duplicity

View File

@ -4,8 +4,6 @@
# Mandatory options are uncommented with sugested values # Mandatory options are uncommented with sugested values
# Other options are commented out with their default values # Other options are commented out with their default values
# #
# Note: You dont need to manually specify vservers using "include = /vservers".
# They're automatically backuped if vserver is set to "yes" on you backupninja.conf.
[general] [general]
@ -121,11 +119,6 @@ include = /var
exclude = exclude_folder1 exclude = exclude_folder1
exclude = exclude_folder2 exclude = exclude_folder2
# exlude some vserver from backup
# this is used only if vservers = yes on backupninja.conf
exclude_vserver = excluded_vserver1
exclude_vserver = excluded_vserver2
# ssh command line (remote only) # ssh command line (remote only)
#ssh = ssh #ssh = ssh

View File

@ -21,6 +21,3 @@
## in /usr/share/doc/subversion/examples now if you wish to use ## in /usr/share/doc/subversion/examples now if you wish to use
## it instead ## it instead
# 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 =

View File

@ -79,7 +79,3 @@
# note: to backup your BIOS, you need the program 'flashrom' installed, and your # note: to backup your BIOS, you need the program 'flashrom' installed, and your
# mainboard needs to be supported, see http://flashrom.org/Supported_hardware#Supported_mainboards # mainboard needs to be supported, see http://flashrom.org/Supported_hardware#Supported_mainboards
# bios = no # bios = no
# If vservers = yes in /etc/backupninja.conf then the following variables can
# be used:
# vsnames = all | <vserver1> <vserver2> ... (default = all)

View File

@ -30,35 +30,6 @@ do_dup_host_includes() {
set +o noglob set +o noglob
} }
do_dup_vserver() {
# choose the vservers to backup (into $selected_vservers)
choose_one_or_more_vservers "$dup_title"
[ $? = 0 ] || return 1
set -o noglob
# choose the files to backup
REPLY=
while [ -z "$REPLY" ]; do
formBegin "$dup_title - vservers: vsincludes (backup these directories from every selected vserver)"
[ -z "$dup_vsincludes" ] && dup_vsincludes="$dup_default_includes"
for i in $dup_vsincludes; do
formItem include "$i"
done
formItem include ""
formItem include ""
formItem include ""
formItem include ""
formItem include ""
formItem include ""
formItem include ""
formItem include ""
formDisplay
[ $? = 0 ] || return 1
dup_vsincludes="$REPLY"
done
set +o noglob
}
do_dup_excludes() { do_dup_excludes() {
set -o noglob set -o noglob
formBegin "$dup_title: excludes" formBegin "$dup_title: excludes"
@ -80,35 +51,6 @@ do_dup_excludes() {
set +o noglob set +o noglob
} }
do_dup_src() {
choose_host_or_vservers_or_both "$dup_title"
[ $? = 0 ] || return 1
case $host_or_vservers in
'host')
do_dup_host_includes
[ $? = 0 ] || return 1
;;
'vservers')
do_dup_vserver
[ $? = 0 ] || return 1
;;
'both')
do_dup_host_includes
[ $? = 0 ] || return 1
do_dup_vserver
[ $? = 0 ] || return 1
;;
*)
return 1
;;
esac
do_dup_excludes
[ $? = 0 ] || return 1
_src_done="(DONE)"
setDefault dest
}
do_dup_dest() { do_dup_dest() {
local replyconverted local replyconverted
@ -366,7 +308,7 @@ signpassword = $dup_gpg_signpassword
[source] [source]
# A few notes about includes and excludes: # A few notes about includes and excludes:
# 1. include, exclude and vsinclude statements support globbing with '*' # 1. include and exclude statements support globbing with '*'
# 2. Symlinks are not dereferenced. Moreover, an include line whose path # 2. Symlinks are not dereferenced. Moreover, an include line whose path
# contains, at any level, a symlink to a directory, will only have the # contains, at any level, a symlink to a directory, will only have the
# symlink backed-up, not the target directory's content. Yes, you have to # symlink backed-up, not the target directory's content. Yes, you have to
@ -384,45 +326,14 @@ signpassword = $dup_gpg_signpassword
# files to include in the backup # files to include in the backup
EOF EOF
if [ "$host_or_vservers" == host -o "$host_or_vservers" == both ]; then set -o noglob
set -o noglob for i in $dup_includes; do
for i in $dup_includes; do echo "include = $i" >> $next_filename
echo "include = $i" >> $next_filename done
done set +o noglob
set +o noglob
fi
cat >> $next_filename <<EOF cat >> $next_filename <<EOF
# If vservers = yes in /etc/backupninja.conf then the following variables can
# be used:
# vsnames = all | <vserver1> <vserver2> ... (default = all)
# vsinclude = <path>
# vsinclude = <path>
# ...
# Any path specified in vsinclude is added to the include list for each vserver
# listed in vsnames (or all if vsnames = all, which is the default).
#
# For example, vsinclude = /home will backup the /home directory in every
# vserver listed in vsnames. If you have 'vsnames = foo bar baz', this
# vsinclude will add to the include list /vservers/foo/home, /vservers/bar/home
# and /vservers/baz/home.
# Vservers paths are derived from $VROOTDIR.
EOF
if [ "$host_or_vservers" == vservers -o "$host_or_vservers" == both ]; then
set -o noglob
echo -e "vsnames = $selected_vservers\n" >> $next_filename
for i in $dup_vsincludes; do
echo "vsinclude = $i" >> $next_filename
done
set +o noglob
fi
# excludes
cat >> $next_filename <<EOF
# files to exclude from the backup # files to exclude from the backup
EOF EOF
set -o noglob set -o noglob
@ -605,7 +516,6 @@ dup_wizard() {
_adv_done= _adv_done=
dup_includes= dup_includes=
dup_excludes= dup_excludes=
dup_vsincludes=
dup_incremental=yes dup_incremental=yes
dup_increments=30 dup_increments=30
dup_keep=60 dup_keep=60

View File

@ -20,8 +20,6 @@ getconf signkey
setsection source setsection source
getconf include getconf include
getconf vsnames all
getconf vsinclude
getconf exclude getconf exclude
setsection dest setsection dest
@ -49,7 +47,7 @@ destdir=${destdir%/}
### SANITY CHECKS ############################################################## ### SANITY CHECKS ##############################################################
[ -n "$desturl" -o -n "$destdir" ] || fatal "The destination directory (destdir) must be set when desturl is not used." [ -n "$desturl" -o -n "$destdir" ] || fatal "The destination directory (destdir) must be set when desturl is not used."
[ -n "$include" -o -n "$vsinclude" ] || fatal "No source includes specified" [ -n "$include" ] || fatal "No source includes specified"
[ -n "$password" ] || fatal "The password option must be set." [ -n "$password" ] || fatal "The password option must be set."
if [ -n "$signkey" -a -n "$encryptkey" -a "$signkey" != "$encryptkey" ]; then if [ -n "$signkey" -a -n "$encryptkey" -a "$signkey" != "$encryptkey" ]; then
[ -n "$signpassword" ] || fatal "The signpassword option must be set because signkey is different from encryptkey." [ -n "$signpassword" ] || fatal "The signpassword option must be set because signkey is different from encryptkey."
@ -92,25 +90,6 @@ if [ -n "$ionicelevel" ]; then
nice="ionice -c2 -n $ionicelevel $nice" nice="ionice -c2 -n $ionicelevel $nice"
fi fi
### VServers
# If vservers are configured, check that the ones listed in $vsnames do exist.
usevserver=no
if [ $vservers_are_available = yes ]; 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
if [ -n "$vsinclude" ]; then
info "Using vservers '$vsnames'"
usevserver=yes
fi
else
[ -z "$vsinclude" ] || warning 'vservers support disabled in backupninja.conf, vsincludes configuration lines will be ignored'
fi
### See if we can login on $desthost ### See if we can login on $desthost
if [ "$testconnect" == "yes" ]; then if [ "$testconnect" == "yes" ]; then
if [ -n "$desturl" ]; then if [ -n "$desturl" ]; then
@ -271,20 +250,6 @@ for i in $include; do
done done
IFS=$SAVEIFS IFS=$SAVEIFS
# vsincludes
if [ $usevserver = yes ]; then
for vserver in $vsnames; do
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for vi in $vsinclude; do
str="${vi//__star__/*}"
str="$VROOTDIR/$vserver$str"
execstr_source="${execstr_source} --include '$str'"
done
IFS=$SAVEIFS
done
fi
set +o noglob set +o noglob
### EXECUTE #################################################################### ### EXECUTE ####################################################################

View File

@ -3,12 +3,6 @@
HELPERS="$HELPERS mysql:mysql_database_backup" HELPERS="$HELPERS mysql:mysql_database_backup"
do_mysql_vserver() {
choose_one_vserver "$mysql_title"
[ $? = 0 ] || return 1
mysql_vsname="vsname = $REPLY"
}
do_mysql_databases() { do_mysql_databases() {
REPLY= REPLY=
while [ -z "$REPLY" ]; do while [ -z "$REPLY" ]; do
@ -121,20 +115,6 @@ $mysql_databases
EOF EOF
if [ $host_or_vservers == vservers ]
then
cat >> $next_filename <<EOF
#
# vsname = <vserver> (no default)
# vsname indicates which vserver to operate on, this is only used if
# vserver is set to yes in /etc/backupninja.conf
# NOTE: if you do not specify a vsname the host will be operated on
# alsoNOTE: if operating on a vserver, $VROOTDIR will be
# prepended to backupdir.
EOF
echo -e "$mysql_vsname\n" >> $next_filename
fi
echo -e $@ >> $next_filename echo -e $@ >> $next_filename
chmod 600 $next_filename chmod 600 $next_filename
@ -145,22 +125,8 @@ mysql_wizard() {
# Global variables # Global variables
mysql_title="MySQL action wizard" mysql_title="MySQL action wizard"
# backup the host system or a Vserver?
choose_host_or_one_vserver "$mysql_title"
[ $? = 0 ] || return 1
if [ $host_or_vservers == vservers ]
then
do_mysql_vserver
[ $? = 0 ] || return 1
fi
# backupdir # backupdir
if [ $host_or_vservers == vservers ] inputBox "$mysql_title" "Directory where to store the backups" "/var/backups/mysql"
then
inputBox "$mysql_title" "Directory where to store the backups:`echo \"\n(Relative to chosen vserver's root directory)\"`" "/var/backups/mysql"
else
inputBox "$mysql_title" "Directory where to store the backups" "/var/backups/mysql"
fi
[ $? = 1 ] && return [ $? = 1 ] && return
mysql_backupdir="backupdir = $REPLY" mysql_backupdir="backupdir = $REPLY"

View File

@ -13,7 +13,6 @@ getconf hotcopy no
getconf sqldump no getconf sqldump no
getconf sqldumpoptions "--lock-tables --complete-insert --add-drop-table --quick --quote-names" getconf sqldumpoptions "--lock-tables --complete-insert --add-drop-table --quick --quote-names"
getconf compress yes getconf compress yes
getconf vsname
# authentication: # authentication:
getconf user getconf user
@ -22,27 +21,6 @@ getconf dbpassword
getconf configfile /etc/mysql/debian.cnf getconf configfile /etc/mysql/debian.cnf
# Decide if the handler should operate on a vserver or on the host.
# In the former case, check that $vsname exists and is running.
usevserver=no
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
vroot="$VROOTDIR/$vsname"
else
info "No vserver name specified, actions will be performed on the host."
fi
fi
## Prepare ignore part of the command ## Prepare ignore part of the command
## This only works for mysqldump at the moment ## This only works for mysqldump at the moment
@ -51,21 +29,15 @@ for i in $ignores $nodata; do
ignore="$ignore --ignore-table=$i" ignore="$ignore --ignore-table=$i"
done done
# create backup dirs, $vroot will be empty if no vsname was specified # create backup dirs
# and we will instead proceed to operate on the host # and we will instead proceed to operate on the host
[ -d $vroot$backupdir ] || mkdir -p $vroot$backupdir [ -d $backupdir ] || mkdir -p $backupdir
[ -d $vroot$backupdir ] || fatal "Backup directory '$vroot$backupdir'" [ -d $backupdir ] || fatal "Backup directory '$backupdir'"
hotdir="$backupdir/hotcopy" hotdir="$backupdir/hotcopy"
dumpdir="$backupdir/sqldump" dumpdir="$backupdir/sqldump"
if [ $usevserver = yes ] [ "$sqldump" == "no" -o -d $dumpdir ] || mkdir -p $dumpdir
then [ "$hotcopy" == "no" -o -d $hotdir ] || mkdir -p $hotdir
[ "$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
####################################################################### #######################################################################
## AUTHENTICATION ## AUTHENTICATION
@ -88,23 +60,13 @@ defaultsfile=""
if [ -n "$dbusername" -a -n "$dbpassword" ] if [ -n "$dbusername" -a -n "$dbpassword" ]
then then
if [ $usevserver = yes ] home=`getent passwd "root" | @AWK@ -F: '{print $6}'`
then
home=`$VSERVER $vsname exec getent passwd "root" | @AWK@ -F: '{print $6}'`
else
home=`getent passwd "root" | @AWK@ -F: '{print $6}'`
fi
[ -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="$home/.my.cnf"
if [ $usevserver = yes ] workcnf="$mycnf"
then
workcnf="$vroot$mycnf"
else
workcnf="$mycnf"
fi
if [ -f $workcnf ] if [ -f $workcnf ]
then then
@ -145,28 +107,18 @@ EOF
elif [ -n "$user" ] elif [ -n "$user" ]
then then
userset=true; userset=true;
if [ $usevserver = yes ]
userhome=`getent passwd "$user" | @AWK@ -F: '{print $6}'`
if [ $? -eq 2 ]
then then
userhome=`$VSERVER $vsname exec getent passwd "$user" | @AWK@ -F: '{print $6}'` fatal "User $user not found in /etc/passwd"
if [ $? -eq 2 ]
then
fatal "User $user not found in /etc/passwd"
fi
debug "User home set to: $vroot$userhome"
[ -f $vroot$userhome/.my.cnf ] || fatal "Can't find config file in $userhome/.my.cnf"
else
userhome=`getent passwd "$user" | @AWK@ -F: '{print $6}'`
if [ $? -eq 2 ]
then
fatal "User $user not found in /etc/passwd"
fi
debug "User home set to: $userhome"
[ -f $userhome/.my.cnf ] || fatal "Can't find config file in $userhome/.my.cnf"
fi fi
debug "User home set to: $userhome"
[ -f $userhome/.my.cnf ] || fatal "Can't find config file in $userhome/.my.cnf"
defaultsfile="--defaults-extra-file=$userhome/.my.cnf" defaultsfile="--defaults-extra-file=$userhome/.my.cnf"
debug "using $defaultsfile" debug "using $defaultsfile"
# otherwise use $configfile # otherwise use $configfile
else else
user=root user=root
defaultsfile="--defaults-extra-file=$configfile" defaultsfile="--defaults-extra-file=$configfile"
@ -180,13 +132,7 @@ then
info "Initializing hotcopy method" info "Initializing hotcopy method"
if [ "$databases" == "all" ] if [ "$databases" == "all" ]
then then
if [ $usevserver = yes ] execstr="$MYSQLHOTCOPY --quiet --allowold --regexp /.\*/./.\*/ $hotdir"
then
info "dbhost: $dbhost"
execstr="$VSERVER $vsname exec $MYSQLHOTCOPY -h $dbhost --quiet --allowold --regexp /.\*/./.\*/ $hotdir"
else
execstr="$MYSQLHOTCOPY --quiet --allowold --regexp /.\*/./.\*/ $hotdir"
fi
debug "su $user -c \"$execstr\"" debug "su $user -c \"$execstr\""
if [ ! $test ] if [ ! $test ]
then then
@ -204,12 +150,7 @@ then
else else
for db in $databases for db in $databases
do do
if [ $usevserver = yes ] execstr="$MYSQLHOTCOPY --allowold $db $hotdir"
then
execstr="$VSERVER $vsname exec $MYSQLHOTCOPY --allowold $db $hotdir"
else
execstr="$MYSQLHOTCOPY --allowold $db $hotdir"
fi
debug 'su $user -c \"$execstr\"' debug 'su $user -c \"$execstr\"'
if [ ! $test ] if [ ! $test ]
then then
@ -236,20 +177,10 @@ then
info "Initializing SQL dump method" info "Initializing SQL dump method"
if [ "$databases" == "all" ] if [ "$databases" == "all" ]
then then
if [ $usevserver = yes ] databases=$(set -o pipefail ; su $user -c "$MYSQL $defaultsfile -N -B -e 'show databases'" | sed 's/|//g;/\+----/d;/^\(information\|performance\)_schema$/d')
if [ $? -ne 0 ]
then then
debug 'set -o pipefail ; echo show databases | $VSERVER $vsname exec su $user -c \"$MYSQL $defaultsfile\" | grep -v Database | grep -v '"'"'^\(information\|performance\)_schema$'"'" fatal "Authentication problem, maybe user/password is wrong or mysqld is not running?"
databases=`set -o pipefail ; echo 'show databases' | $VSERVER $vsname exec su $user -c "$MYSQL $defaultsfile" | grep -v Database | grep -v '^\(information\|performance\)_schema$'`
if [ $? -ne 0 ]
then
fatal "Authentication problem, maybe user/password is wrong or mysqld is not running?"
fi
else
databases=$(set -o pipefail ; su $user -c "$MYSQL $defaultsfile -N -B -e 'show databases'" | sed 's/|//g;/\+----/d;/^\(information\|performance\)_schema$/d')
if [ $? -ne 0 ]
then
fatal "Authentication problem, maybe user/password is wrong or mysqld is not running?"
fi
fi fi
fi fi
@ -275,31 +206,19 @@ then
done done
DUMP="( $DUMP; $DUMP_STRUCT )" DUMP="( $DUMP; $DUMP_STRUCT )"
fi fi
if [ $usevserver = yes ]
then # Test to make sure mysqld is running, if it is not sqldump will not work
# Test to make sure mysqld is running, if it is not sqldump will not work su $user -c "$MYSQLADMIN $defaultsfile ping 2>&1 >/dev/null"
$VSERVER $vsname exec su $user -c "$MYSQLADMIN $defaultsfile ping 2>&1 >/dev/null" if [ $? -ne 0 ]; then
if [ $? -ne 0 ]; then fatal "mysqld doesn't appear to be running!"
fatal "mysqld doesn't appear to be running!" fi
fi if [ "$compress" == "yes" ]; then
if [ "$compress" == "yes" ]; then execstr="$DUMP | $GZIP $GZIP_OPTS > '$dumpdir/${db}.sql.gz'"
execstr="$VSERVER $vsname exec $DUMP | $GZIP $GZIP_OPTS > '$vroot$dumpdir/${db}.sql.gz'"
else
execstr="$VSERVER $vsname exec $DUMP -r '$vroot$dumpdir/${db}.sql'"
fi
else else
# Test to make sure mysqld is running, if it is not sqldump will not work execstr="$DUMP > '$dumpdir/${db}.sql'"
su $user -c "$MYSQLADMIN $defaultsfile ping 2>&1 >/dev/null"
if [ $? -ne 0 ]; then
fatal "mysqld doesn't appear to be running!"
fi
if [ "$compress" == "yes" ]; then
execstr="$DUMP | $GZIP $GZIP_OPTS > '$dumpdir/${db}.sql.gz'"
else
execstr="$DUMP > '$dumpdir/${db}.sql'"
fi
fi fi
debug "su $user -c \"$execstr\"" debug "su $user -c \"$execstr\""
if [ ! $test ] if [ ! $test ]
then then
output=`su $user -s /bin/bash -c "set -o pipefail ; $execstr" 2>&1` output=`su $user -s /bin/bash -c "set -o pipefail ; $execstr" 2>&1`

View File

@ -3,12 +3,6 @@
HELPERS="$HELPERS pgsql:postgresql_database_backup" HELPERS="$HELPERS pgsql:postgresql_database_backup"
do_pgsql_vserver() {
choose_one_vserver "$pgsql_title"
[ $? = 0 ] || return 1
pgsql_vsname="vsname = $REPLY"
}
do_pgsql_databases() { do_pgsql_databases() {
REPLY= REPLY=
while [ -z "$REPLY" ]; do while [ -z "$REPLY" ]; do
@ -37,16 +31,8 @@ pgsql_wizard() {
# constants # constants
pgsql_title="PostgreSQL action wizard" pgsql_title="PostgreSQL action wizard"
# backup the host system or a Vserver?
choose_host_or_one_vserver "$pgsql_title"
[ $? = 0 ] || return 1
if [ $host_or_vservers == vservers ]; then
do_pgsql_vserver
[ $? = 0 ] || return 1
fi
# backupdir # backupdir
inputBox "$pgsql_title" "Directory where to store the backups:`[ -z \"$pgsql_vsname\" ] || echo \"\n(In respect to chosen vserver's root directory)\"`" "/var/backups/postgres" inputBox "$pgsql_title" "Directory where to store the backups:" "/var/backups/postgres"
[ $? = 1 ] && return [ $? = 1 ] && return
pgsql_backupdir="backupdir = $REPLY" pgsql_backupdir="backupdir = $REPLY"
@ -87,16 +73,6 @@ pgsql_wizard() {
cat >> $next_filename <<EOF cat >> $next_filename <<EOF
### backupninja PostgreSQL config file ### ### backupninja PostgreSQL config file ###
# vsname = <vserver> (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
# Note: if operating on a vserver, $VROOTDIR will be prepended to backupdir.
EOF
if [ $host_or_vservers == vservers ]; then
echo -e "$pgsql_vsname\n" >> $next_filename
fi
cat >> $next_filename <<EOF
# backupdir = <dir> (default: /var/backups/postgres) # backupdir = <dir> (default: /var/backups/postgres)
# where to dump the backups # where to dump the backups
$pgsql_backupdir $pgsql_backupdir

View File

@ -7,85 +7,39 @@
getconf backupdir /var/backups/postgres getconf backupdir /var/backups/postgres
getconf databases all getconf databases all
getconf compress yes getconf compress yes
getconf vsname
# format maps to pg_dump --format= option, old/default was plain # format maps to pg_dump --format= option, old/default was plain
getconf format plain getconf format plain
localhost=`hostname` localhost=`hostname`
# Decide if the handler should operate on a vserver or on the host.
# In the former case, check that $vsname exists and is running.
usevserver=no
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
vroot="$VROOTDIR/$vsname"
else
info "No vserver name specified, actions will be performed on the host."
fi
fi
# Make sure that the system to backup has the needed executables # Make sure that the system to backup has the needed executables
if [ $usevserver = yes ]; then if [ "$databases" == "all" ] && [ "$format" = "plain" ]; then
debug "Examining vserver '$vsname'." [ -x "`which $PGSQLDUMPALL`" ] || \
if [ "$databases" == "all" ] && [ "$format" = "plain" ]; then fatal "Can't find $PGSQLDUMPALL."
[ -x "$vroot`$VSERVER $vsname exec which $PGSQLDUMPALL`" ] || \ elif [ "$format" != "plain" ]; then
fatal "Can't find $PGSQLDUMPALL in vserver $vsname." [ -x "`which $PGSQLDUMPALL`" ] || \
elif [ "$format" != "plain" ]; then fatal "Can't find $PGSQLDUMPALL."
[ -x "$vroot`$VSERVER $vsname exec which $PGSQLDUMPALL`" ] || \ [ -x "`which $PGSQLDUMP`" ] || \
fatal "Can't find $PGSQLDUMPALL in vserver $vsname." fatal "Can't find $PGSQLDUMP."
[ -x "$vroot`$VSERVER $vsname exec which $PGSQLDUMP`" ] || \ [ -x "`which $PSQL`" ] || \
fatal "Can't find $PGSQLDUMP in vserver $vsname." fatal "Can't find $PSQL."
[ -x "$vroot`$VSERVER $vsname exec which $PSQL`" ] || \
fatal "Can't find $PSQL in vserver $vsname."
else
[ -x "$vroot`$VSERVER $vsname exec which $PGSQLDUMP`" ] || \
fatal "Can't find $PGSQLDUMP in vserver $vsname."
fi
else else
if [ "$databases" == "all" ] && [ "$format" = "plain" ]; then [ -x "`which $PGSQLDUMP`" ] || \
[ -x "`which $PGSQLDUMPALL`" ] || \ fatal "Can't find $PGSQLDUMP."
fatal "Can't find $PGSQLDUMPALL."
elif [ "$format" != "plain" ]; then
[ -x "`which $PGSQLDUMPALL`" ] || \
fatal "Can't find $PGSQLDUMPALL."
[ -x "`which $PGSQLDUMP`" ] || \
fatal "Can't find $PGSQLDUMP."
[ -x "`which $PSQL`" ] || \
fatal "Can't find $PSQL."
else
[ -x "`which $PGSQLDUMP`" ] || \
fatal "Can't find $PGSQLDUMP."
fi
fi fi
# create backup dir, the vroot variable will be empty if no vsname was specified # create backup dir
# and will proceed to operate on the host [ -d $backupdir ] || (debug "mkdir -p $backupdir"; mkdir -p $backupdir)
[ -d $vroot$backupdir ] || (debug "mkdir -p $vroot$backupdir"; mkdir -p $vroot$backupdir) [ -d $backupdir ] || fatal "Backup directory '$backupdir' does not exist, and could not be created."
[ -d $vroot$backupdir ] || fatal "Backup directory '$vroot$backupdir' does not exist, and could not be created."
# give backup dir the good uid and permissions # give backup dir the good uid and permissions
# (in respect to the vserver, if $usevserver = yes) pguid=`getent passwd $PGSQLUSER | @AWK@ -F: '{print $3}'`
if [ $usevserver = yes ]; then [ -n "$pguid" ] || fatal "No user called $PGSQLUSER."
pguid=`$VSERVER $vsname exec getent passwd $PGSQLUSER | @AWK@ -F: '{print $3}'`
else debug "chown $pguid $backupdir"
pguid=`getent passwd $PGSQLUSER | @AWK@ -F: '{print $3}'` chown $pguid $backupdir
fi debug "chmod 700 $backupdir"
[ -n "$pguid" ] || \ chmod 700 $backupdir
fatal "No user called $PGSQLUSER`[ $usevserver = no ] || echo \" on vserver $vsname\"`."
debug "chown $pguid $vroot$backupdir"
chown $pguid $vroot$backupdir
debug "chmod 700 $vroot$backupdir"
chmod 700 $vroot$backupdir
# If we are using the custom (best) or tar pg_dump format, and # If we are using the custom (best) or tar pg_dump format, and
@ -93,11 +47,7 @@ chmod 700 $vroot$backupdir
# of all non-template databases to avoid the use of pg_dumpall. # of all non-template databases to avoid the use of pg_dumpall.
dumpglobals="no" dumpglobals="no"
if [ "$databases" = "all" ] && [ "$format" != "plain" ]; then if [ "$databases" = "all" ] && [ "$format" != "plain" ]; then
cmdprefix="" execstr="su - $PGSQLUSER -c 'psql -AtU $PGSQLUSER -c \"SELECT datname FROM pg_database WHERE NOT datistemplate\"'"
if [ "$usevserver" = "yes" ]; then
cmdprefix="$VSERVER $vsname exec "
fi
execstr="${cmdprefix} su - $PGSQLUSER -c 'psql -AtU $PGSQLUSER -c \"SELECT datname FROM pg_database WHERE NOT datistemplate\"'"
debug execstr debug execstr
dblist="" dblist=""
for db in $(eval $execstr 2>&1); do for db in $(eval $execstr 2>&1); do
@ -113,18 +63,10 @@ fi
# if $databases = all, use pg_dumpall # if $databases = all, use pg_dumpall
if [ "$databases" == "all" ]; then if [ "$databases" == "all" ]; then
if [ $usevserver = yes ]; then if [ "$compress" == "yes" ]; then
if [ "$compress" == "yes" ]; then execstr="su - $PGSQLUSER -s /bin/bash -c \"set -o pipefail ; $PGSQLDUMPALL | $GZIP $GZIP_OPTS > '$backupdir/${localhost}-all.sql.gz'\""
execstr="$VSERVER $vsname exec su - $PGSQLUSER -s /bin/bash -c \"set -o pipefail ; $PGSQLDUMPALL | $GZIP $GZIP_OPTS > '$backupdir/${vsname}.sql.gz'\""
else
execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMPALL > '$backupdir/${vsname}.sql'\""
fi
else else
if [ "$compress" == "yes" ]; then execstr="su - $PGSQLUSER -c \"$PGSQLDUMPALL > '$backupdir/${localhost}-all.sql'\""
execstr="su - $PGSQLUSER -s /bin/bash -c \"set -o pipefail ; $PGSQLDUMPALL | $GZIP $GZIP_OPTS > '$backupdir/${localhost}-all.sql.gz'\""
else
execstr="su - $PGSQLUSER -c \"$PGSQLDUMPALL > '$backupdir/${localhost}-all.sql'\""
fi
fi fi
debug "$execstr" debug "$execstr"
if [ ! $test ]; then if [ ! $test ]; then
@ -151,11 +93,7 @@ else
else else
globalscmd="$PGSQLDUMPALL -g > '$backupdir/globals.sql'" globalscmd="$PGSQLDUMPALL -g > '$backupdir/globals.sql'"
fi fi
if [ $usevserver = yes ]; then execstr="su - $PGSQLUSER -s /bin/bash -c \"$globalscmd\""
execstr="$VSERVER $vsname exec su - $PGSQLUSER -s /bin/bash -c \"$globalscmd\""
else
execstr="su - $PGSQLUSER -s /bin/bash -c \"$globalscmd\""
fi
debug "$execstr" debug "$execstr"
if [ ! $test ]; then if [ ! $test ]; then
output=`eval $execstr 2>&1` output=`eval $execstr 2>&1`
@ -188,11 +126,7 @@ else
else else
dumpcmd="$PGSQLDUMP --format=$format ${disablecustomcompress} $db > '$backupdir/${db}.${dumpext}'" dumpcmd="$PGSQLDUMP --format=$format ${disablecustomcompress} $db > '$backupdir/${db}.${dumpext}'"
fi fi
if [ $usevserver = yes ]; then execstr="su - $PGSQLUSER -s /bin/bash -c \"$dumpcmd\""
execstr="$VSERVER $vsname exec su - $PGSQLUSER -s /bin/bash -c \"$dumpcmd\""
else
execstr="su - $PGSQLUSER -s /bin/bash -c \"$dumpcmd\""
fi
debug "$execstr" debug "$execstr"
if [ ! $test ]; then if [ ! $test ]; then
output=`eval $execstr 2>&1` output=`eval $execstr 2>&1`

View File

@ -5,8 +5,6 @@ HELPERS="$HELPERS rdiff:incremental_remote_filesystem_backup"
declare -a rdiff_includes declare -a rdiff_includes
declare -a rdiff_excludes declare -a rdiff_excludes
declare -a rdiff_vsincludes
declare -a rdiff_vsexcludes
# FUNCTIONS # FUNCTIONS
@ -35,38 +33,6 @@ do_rdiff_host_includes() {
set +o noglob set +o noglob
} }
do_rdiff_vserver() {
# choose the vservers to backup (into $selected_vservers)
choose_one_or_more_vservers "$rdiff_title"
[ $? = 0 ] || return 1
set -o noglob
# choose the files to backup
REPLY=
while [ -z "$REPLY" ]; do
formBegin "$rdiff_title - vsincludes (backup these directories from every vserver)"
[ -z "$rdiff_vsincludes" ] && rdiff_vsincludes="$rdiff_default_includes"
for i in $rdiff_vsincludes; do
formItem include "$i"
done
formItem include ""
formItem include ""
formItem include ""
formItem include ""
formItem include ""
formItem include ""
formItem include ""
formItem include ""
formDisplay
[ $? = 0 ] || return 1
rdiff_vsincludes=($REPLY)
done
set +o noglob
}
do_rdiff_excludes() { do_rdiff_excludes() {
set -o noglob set -o noglob
formBegin "$rdiff_title: excludes" formBegin "$rdiff_title: excludes"
@ -90,27 +56,8 @@ do_rdiff_excludes() {
} }
do_rdiff_src() { do_rdiff_src() {
choose_host_or_vservers_or_both "$rdiff_title" do_rdiff_host_includes
[ $? = 0 ] || return 1 [ $? = 0 ] || return 1
case $host_or_vservers in
'host')
do_rdiff_host_includes
[ $? = 0 ] || return 1
;;
'vservers')
do_rdiff_vserver
[ $? = 0 ] || return 1
;;
'both')
do_rdiff_host_includes
[ $? = 0 ] || return 1
do_rdiff_vserver
[ $? = 0 ] || return 1
;;
*)
return 1
;;
esac
do_rdiff_excludes do_rdiff_excludes
[ $? = 0 ] || return 1 [ $? = 0 ] || return 1
_src_done="(DONE)" _src_done="(DONE)"
@ -314,7 +261,7 @@ type = local
keep = $rdiff_keep keep = $rdiff_keep
# A few notes about includes and excludes: # A few notes about includes and excludes:
# 1. include, exclude and vsinclude statements support globbing with '*' # 1. include and exclude statements support globbing with '*'
# 2. Symlinks are not dereferenced. Moreover, an include line whose path # 2. Symlinks are not dereferenced. Moreover, an include line whose path
# contains, at any level, a symlink to a directory, will only have the # contains, at any level, a symlink to a directory, will only have the
# symlink backed-up, not the target directory's content. Yes, you have to # symlink backed-up, not the target directory's content. Yes, you have to
@ -332,40 +279,11 @@ keep = $rdiff_keep
# files to include in the backup # files to include in the backup
EOF EOF
## includes ## ## includes ##
if [ "$host_or_vservers" == host -o "$host_or_vservers" == both ]; then set -o noglob
set -o noglob for ((i=0; i < ${#rdiff_includes[@]} ; i++)); do
for ((i=0; i < ${#rdiff_includes[@]} ; i++)); do echo "include = ${rdiff_includes[$i]}" >> $next_filename
echo "include = ${rdiff_includes[$i]}" >> $next_filename done
done set +o noglob
set +o noglob
fi
if [ "$host_or_vservers" == vservers -o "$host_or_vservers" == both ]; then
cat >> $next_filename <<EOF
#
# If vservers = yes in /etc/backupninja.conf then the following variables can
# be used:
# vsnames = all | <vserver1> <vserver2> ... (default = all)
# vsinclude = <path>
# vsinclude = <path>
# ...
# Any path specified in vsinclude is added to the include list for each vserver
# listed in vsnames (or all if vsnames = all, which is the default).
#
# For example, vsinclude = /home will backup the /home directory in every
# vserver listed in vsnames. If you have 'vsnames = foo bar baz', this
# vsinclude will add to the include list /vservers/foo/home, /vservers/bar/home
# and /vservers/baz/home.
# Vservers paths are derived from $VROOTDIR.
EOF
set -o noglob
echo -e "vsnames = $selected_vservers\n" >> $next_filename
for i in $rdiff_vsincludes; do
echo "vsinclude = $i" >> $next_filename
done
set +o noglob
fi
## excludes ## ## excludes ##
set -o noglob set -o noglob
@ -439,7 +357,6 @@ rdiff_wizard() {
set -o noglob set -o noglob
rdiff_includes=(/var/spool/cron/crontabs /var/backups /etc /root /home /usr/local/*bin /var/lib/dpkg/status*) rdiff_includes=(/var/spool/cron/crontabs /var/backups /etc /root /home /usr/local/*bin /var/lib/dpkg/status*)
rdiff_excludes=(/home/*/.gnupg /home/*/.local/share/Trash /home/*/.Trash /home/*/.thumbnails /home/*/.beagle /home/*/.aMule /home/*/gtk-gnutella-downloads /var/cache/backupninja/duplicity) rdiff_excludes=(/home/*/.gnupg /home/*/.local/share/Trash /home/*/.Trash /home/*/.thumbnails /home/*/.beagle /home/*/.aMule /home/*/gtk-gnutella-downloads /var/cache/backupninja/duplicity)
rdiff_vsincludes=
set +o noglob set +o noglob
rdiff_main_menu rdiff_main_menu

View File

@ -116,24 +116,6 @@ fi
### CHECK CONFIG ### ### CHECK CONFIG ###
# If vservers are configured, check that the ones listed in $vsnames do exist.
usevserver=no
if [ $vservers_are_available = yes ]; 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
if [ -n "$vsinclude" ]; then
info "Using vservers '$vsnames'"
usevserver=yes
fi
else
[ -z "$vsinclude" ] || warning 'vservers support disabled in backupninja.conf, vsincludes configuration lines will be ignored'
fi
# Check that the ionicelevel is valid # Check that the ionicelevel is valid
if [ -n "$ionicelevel" ] && echo "$ionicelevel" | grep -vq "^[0-7]$"; then if [ -n "$ionicelevel" ] && echo "$ionicelevel" | grep -vq "^[0-7]$"; then
fatal "The value of ionicelevel is expected to be either empty or an integer from 0 to 7. Got: $ionicelevel" fatal "The value of ionicelevel is expected to be either empty or an integer from 0 to 7. Got: $ionicelevel"
@ -255,24 +237,6 @@ for i in $include; do
done done
IFS=$SAVEIFS IFS=$SAVEIFS
# vsinclude
if [ $usevserver = yes ]; then
for vserver in $vsnames; do
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for vi in $vsinclude; do
str="${vi//__star__/*}"
str="$VROOTDIR/$vserver$str"
if [ -n "$str" ]; then
execstr="${execstr}--include '$str' "
else
warning "vsinclude statement '${vi//__star__/*}' will be ignored for VServer $vserver. $symlinks_warning"
fi
done
IFS=$SAVEIFS
done
fi
set +o noglob set +o noglob
# exclude everything else # exclude everything else

View File

@ -57,7 +57,6 @@
# protocol = ssh or rsync (remote source only) # protocol = ssh or rsync (remote source only)
# rsync = rsync program # rsync = rsync program
# rsync_options = rsync command options # rsync_options = rsync command options
# exclude_vserver = vserver-name (valid only if vservers = yes on backupninja.conf)
# numericids = when set to 1, use numeric ids instead of user/group mappings on rsync # numericids = when set to 1, use numeric ids instead of user/group mappings on rsync
# compress = if set to 1, compress data on rsync (remote source only) # compress = if set to 1, compress data on rsync (remote source only)
# bandwidthlimit = set a bandwidth limit in KB/s (remote source only) # bandwidthlimit = set a bandwidth limit in KB/s (remote source only)
@ -98,9 +97,6 @@
# mv = mv command # mv = mv command
# fsck = fsck command # fsck = fsck command
# #
# You dont need to manually specify vservers using "include = /vservers".
# They are automatically backuped if vserver is set to "yes" on you backupninja.conf.
#
# function definitions # function definitions
@ -175,7 +171,6 @@ function eval_config {
getconf filelistbase getconf filelistbase
getconf include getconf include
getconf exclude getconf exclude
getconf exclude_vserver
getconf numericids 0 getconf numericids 0
getconf compress 0 getconf compress 0
@ -981,8 +976,6 @@ function set_rsync_options {
rsync_options=($rsync_options --rsync-path="$remote_rsync") rsync_options=($rsync_options --rsync-path="$remote_rsync")
fi fi
include_vservers
} }
function stop_services { function stop_services {
@ -1056,33 +1049,6 @@ function run_fsck {
} }
function include_vservers {
# add vservers to included folders
if [ "$vservers_are_available" == "yes" ]; then
# sane permission on backup
mkdir -p $backupdir/$VROOTDIR
chmod 000 $backupdir/$VROOTDIR
for candidate in $found_vservers; do
candidate="`basename $candidate`"
found_excluded_vserver="0"
for excluded_vserver in $exclude_vserver; do
if [ "$excluded_vserver" == "$candidate" ]; then
found_excluded_vserver="1"
break
fi
done
if [ "$found_excluded_vserver" == "0" ]; then
include="$include $VROOTDIR/$candidate"
fi
done
fi
}
function start_mux { function start_mux {
if [ "$multiconnection" == "yes" ]; then if [ "$multiconnection" == "yes" ]; then

View File

@ -12,66 +12,40 @@ getconf vsname
error=0 error=0
# Decide if the handler should operate on a vserver or on the host. cd $src
# In the former case, check that $vsname exists and is running.
usevserver=no
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
vroot="$VROOTDIR/$vsname"
else
info "No vserver name specified, actions will be performed on the host."
fi
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 $vroot$tmp/$repo 2>&1` ret=`mkdir -p $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 $vroot$tmp/$repo" error "command failed mkdir -p $tmp/$repo"
fi fi
if [ $usevserver = yes ] ret=`$HOTBACKUP $src/$repo $tmp/$repo 2>&1`
then
ret=`$VSERVER $vsname exec $HOTBACKUP $src/$repo $tmp/$repo 2>&1`
else
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 $vroot$src/$repo $vroot$tmp/$repo" error "command failed -- $HOTBACKUP $src/$repo $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 $vroot$tmp instead of $vroot$dest" echo "Error: because of earlier errors, we are leaving svn backups in $tmp instead of $dest"
else else
if [ -d $vroot$dest -a -d $vroot$tmp ]; then if [ -d $dest -a -d $tmp ]; then
rm -rf $vroot$dest rm -rf $dest
fi fi
if [ -d $vroot$tmp ]; then if [ -d $tmp ]; then
mv $vroot$tmp $vroot$dest mv $tmp $dest
fi fi
fi fi

View File

@ -50,10 +50,6 @@ $bios
# partitionsfile = /var/backups/partitions.__star__.txt # partitionsfile = /var/backups/partitions.__star__.txt
# hardwarefile = /var/backups/hardware.txt # hardwarefile = /var/backups/hardware.txt
# luksheadersfile = /var/backups/luksheader.__star__.bin # luksheadersfile = /var/backups/luksheader.__star__.bin
# If vservers = yes in /etc/backupninja.conf then the following variables can
# be used:
# vsnames = all | <vserver1> <vserver2> ... (default = all)
EOF EOF
chmod 600 $next_filename chmod 600 $next_filename
} }

View File

@ -126,21 +126,6 @@ getconf mbrfile $parentdir/mbr.__star__.bin
getconf FLASHROM `which flashrom` getconf FLASHROM `which flashrom`
getconf bios no getconf bios no
getconf vsnames all
# If vservers are configured, check that the ones listed in $vsnames are running.
usevserver=no
if [ $vservers_are_available = yes ]; then
if [ "$vsnames" = all ]; then
vsnames="$found_vservers"
fi
if ! vservers_running "$vsnames" ; then
fatal "At least one of the vservers listed in vsnames ($vsnames) is not running."
fi
info "Using vservers '$vsnames'"
usevserver=yes
fi
## SANITY CHECKS ######################### ## SANITY CHECKS #########################
if [ "$luksheaders" == "yes" ]; then if [ "$luksheaders" == "yes" ]; then
@ -186,47 +171,6 @@ fi
# #
if [ "$packages" == "yes" ]; then if [ "$packages" == "yes" ]; then
if [ $usevserver = yes ]; then
info "vserver root directory set to: $VROOTDIR"
for vserver in $vsnames; do
info "examining vserver: $vserver"
# is it running ?
vservers_running $vserver
if [ $? -ne 0 ]; then
warning "The vserver $vserver is not running."
continue
fi
# is $packagemgr available inside $vserver ?
if [ ! -x "${VROOTDIR}/${vserver}${packagemgr}" ]; then
warning "can't find $packagemgr in vserver $vserver, skipping installed packages report."
else
# don't expand * since it can be used in $packagemgroptions
set -o noglob
debug "$VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile"
$VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile || fatal "can not save $packagemgr info to $packagesfile"
set +o noglob
fi
# is $debconfgetselections available inside $vserver ?
found=no
# case #1: it is available on the host, is it available inside $vserver ?
if [ -n "$debconfgetselections" ]; then
[ -x "${VROOTDIR}/${vserver}${debconfgetselections}" ] && found=yes
# case #2: it is not available on the host, is it available inside $vserver ?
else
[ -n "`$VSERVER $vserver exec which debconf-get-selections`" ] && found=yes
fi
if [ "$found" != yes ]; then
warning "can't find debconf-get-selections in vserver $vserver, skipping package selection states. You may want to install the debconf-utils package."
else
debug "$VSERVER $vserver exec $debconfgetselections > $VROOTDIR/$vserver$selectionsfile"
$VSERVER $vserver exec $debconfgetselections > $VROOTDIR/$vserver$selectionsfile || fatal "can not save debconf-get-selections info to $selectionsfile"
fi
unset found
done
fi
# We want to perform this on the host as well
if [ -z "$packagemgr" -o ! -x "$packagemgr" ]; then if [ -z "$packagemgr" -o ! -x "$packagemgr" ]; then
warning "can't find ${packagemgr}, skipping installed packages report." warning "can't find ${packagemgr}, skipping installed packages report."
else else
@ -551,11 +495,6 @@ if [ $os = "redhat" ]; then
catifexec "rpm" "-q -V selinux-policy-strict" catifexec "rpm" "-q -V selinux-policy-strict"
fi fi
if [ $usevserver = yes ]; then
STATUS="Gathering vserver information"
catiffile "/proc/virtual"
fi
if [ "$partitions" == "yes" ]; then if [ "$partitions" == "yes" ]; then
if [ "$dosfdisk" == "yes" ]; then if [ "$dosfdisk" == "yes" ]; then
if [ ! -x "$SFDISK" ]; then if [ ! -x "$SFDISK" ]; then

View File

@ -14,12 +14,6 @@ getconf EXTENSION tar
getconf DATE `which date` getconf DATE `which date`
getconf DATEFORMAT "%Y.%m.%d-%H%M" getconf DATEFORMAT "%Y.%m.%d-%H%M"
# See if vservers are configured
if [ "$vservers" = "yes" ]
then
warning "vservers enabled, but tar does not support it!"
fi
if [ ! -d "$backupdir" ] if [ ! -d "$backupdir" ]
then then
mkdir -p "$backupdir" || fatal "Can not make directory $backupdir" mkdir -p "$backupdir" || fatal "Can not make directory $backupdir"

View File

@ -1,9 +1,9 @@
my_execbindir = $(pkglibdir) my_execbindir = $(pkglibdir)
my_execbin_SCRIPTS = easydialog parseini tools vserver my_execbin_SCRIPTS = easydialog parseini tools
CLEANFILES = $(my_execbin_SCRIPTS) CLEANFILES = $(my_execbin_SCRIPTS)
EXTRA_DIST = easydialog.in parseini.in tools.in vserver.in EXTRA_DIST = easydialog.in parseini.in tools.in
edit = sed \ edit = sed \
-e "s,@CFGDIR\@,$(CFGDIR),g" \ -e "s,@CFGDIR\@,$(CFGDIR),g" \
@ -24,7 +24,3 @@ parseini: $(srcdir)/parseini.in
tools: $(srcdir)/tools.in tools: $(srcdir)/tools.in
rm -f tools rm -f tools
$(edit) tools.in > tools $(edit) tools.in > tools
vserver: $(srcdir)/vserver.in
rm -f vserver
$(edit) vserver.in > vserver

View File

@ -1,251 +0,0 @@
# -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
# vim: set filetype=sh sw=3 sts=3 expandtab autoindent:
#####################################################
## VSERVERS RELATED FUNCTIONS FOR NINJAHELPER
##
## Depends on:
## - easydialog library
## - $conffile
##
## Global variables used and modified here:
## - $vservers_are_available (yes/no)
## - $found_vservers (list)
## - $selected_vservers (list)
## - $host_or_vservers (host/vservers/both)
##
##
## Get vservers-related variables.
## Then, if Vservers are enabled, check that:
## - VROOTDIR is valid;
## - at least one vserver can be found.
## If, and only if, the above conditions are all true:
## - set $vservers_are_available to 'yes';
## - set $found_vservers to the list of all vservers found on the system.
## This function has to be run once before a new helper is run.
## If the argument is "nodialog", use the backupninja's message functions
## instead of easydialog.
##
init_vservers() {
local arg=$1
# get global variables from the conffile
setfile $conffile
getconf vservers no
getconf VSERVERINFO /usr/sbin/vserver-info
getconf VSERVER /usr/sbin/vserver
getconf VROOTDIR `if [ -x "$VSERVERINFO" ]; then $VSERVERINFO info SYSINFO | grep '^ *vserver-Rootdir' | @AWK@ '{print $2}'; fi`
# canonicalize VROOTDIR
[ -z "$VROOTDIR" ] || VROOTDIR=`readlink --canonicalize $VROOTDIR`
# init this library's global variables
vservers_are_available=no
found_vservers=
selected_vservers=
host_or_vservers=host
# check vservers real availability
if [ $vservers = yes ]; then
if [ ! -x "$VSERVERINFO" ]; then
`if [ "$arg" = nodialog ]; then echo fatal; else echo "msgBox warning"; fi` \
"vservers enabled in $conffile, but vserver-info command was not found. Please set the VSERVERINFO configuration variable to its full path."
return
fi
if [ ! -x "$VSERVER" ]; then
`if [ "$arg" = nodialog ]; then echo fatal; else echo "msgBox warning"; fi` \
"vservers enabled in $conffile, but vserver command was not found. Please set the VSERVER configuration variable to its full path."
return
fi
if [ -z "$VROOTDIR" ]; then
`if [ "$arg" = nodialog ]; then echo fatal; else echo "msgBox warning"; fi` \
"vservers enabled in $conffile, but VROOTDIR is not set and could not be guessed."
return
fi
if [ ! -d "$VROOTDIR" ]; then
`if [ "$arg" = nodialog ]; then echo fatal; else echo "msgBox warning"; fi` \
"vservers enabled in $conffile, but VROOTDIR ($VROOTDIR) does not exist.";
return
fi
found_vservers=`ls $VROOTDIR | grep -E -v "lost\+found|ARCHIVES" | tr "\n" " "`
if [ -z "$found_vservers" ]; then
`if [ "$arg" = nodialog ]; then echo warning; else echo "msgBox warning"; fi` \
"vservers enabled in $conffile, but no vserver was found in $VROOTDIR.";
return
fi
vservers_are_available=yes
fi
}
##
## If all the arguments are existing vservers names, returns 0.
## Else, returns 1. Also returns 1 if no argument is given.
##
vservers_exist() {
[ $# -ge 1 ] || return 1
local args="$1"
local vserver i found
for vserver in $args ; do
found=no
for i in $found_vservers ; do
if [ $vserver = $i ]; then
found=yes
break
fi
done
[ $found = yes ] || return 1
done
return 0
}
##
## If all the arguments are running vservers names, returns 0.
## Else, returns 1. Also returns 1 if no argument is given.
##
vservers_running() {
[ $# -ge 1 ] || return 1
local args="$1"
local vserver
for vserver in $args ; do
$VSERVERINFO -q $vserver RUNNING || return 1
done
return 0
}
##
## If the argument is the name of a vserver selected by the current helper,
## echoes 'on' and returns 0.
## Else, echoes 'off' and returns 1.
##
vserver_is_selected() {
local vserver=$1
local vserver_is_selected=1
local i
for i in $selected_vservers ; do
[ "$vserver" == "$i" ] && vserver_is_selected=0
done
if [ $vserver_is_selected = 0 ]; then
echo on
else
echo off
fi
return $vserver_is_selected
}
##
## Have the user choose one Vserver among the existing ones.
## Set $selected_vservers to the chosen one's name.
## Returns 1 if cancelled or if Vservers are not available.
##
choose_one_vserver() {
[ "$vservers_are_available" == "yes" ] || return 1
local title=$1
local i=
local vserver=
REPLY=
while [ -z "$REPLY" ]; do
[ -n "$selected_vservers" ] && setDefault $selected_vservers
listBegin "$title" "Choose at least one Linux-Vserver to backup:"
for vserver in $found_vservers; do
listItem "$vserver" "Backup $vserver vserver"
done
listDisplay menu
[ $? = 0 ] || return 1
done
selected_vservers=$REPLY
}
##
## If Vservers are not enabled, set host_or_vservers='host' and then return
## Else, have the user choose if he/she wants to perform the backup on the host
## system or on one Vserver.
## Set, respectively, $host_or_vservers to 'host' or 'vservers'.
## Returns 1 if cancelled.
##
choose_host_or_one_vserver() {
if [ "$vservers_are_available" != "yes" ]
then
host_or_vservers='host'
return
fi
local title=$1
# if there is one, set the previously chosen item as the default
[ -n "$host_or_vservers" ] && setDefault $host_or_vservers
menuBox "$title - src" "Do you want to operate on the host system and/or on vservers?" \
"host" "Host system" \
"vserver" "One Vserver"
[ $? = 0 ] || return 1
case $REPLY in
"host")
host_or_vservers='host'
;;
"vserver")
host_or_vservers='vservers'
;;
esac
}
##
## If Vservers are not enabled, set host_or_vservers='host' and then return
## Else, have the user choose the target he/she wants to perform the backup on:
## - host system only;
## - some vservers only;
## - both the host system and some vservers.
## Set, respectively, $host_or_vservers to 'host', 'vservers', or 'both'
## Returns 1 if cancelled.
##
choose_host_or_vservers_or_both() {
if [ "$vservers_are_available" != "yes" ]
then
host_or_vservers='host'
return
fi
local title=$1
# if there is one, set the previously chosen item as the default
[ -n "$host_or_vservers" ] && setDefault $host_or_vservers
menuBox "$title - src" "Do you want to operate on the host system and/or on vservers?" \
"host" "Host system only" \
"vservers" "Vservers only" \
"both" "Host system and Vservers"
[ $? = 0 ] || return 1
case $REPLY in
"host")
host_or_vservers='host'
;;
"vservers")
host_or_vservers='vservers'
;;
"both")
host_or_vservers='both'
;;
esac
}
##
## Have the user choose among "all vservers" and a not-empty subset of these.
## Set $selected_vservers to 'all' or to a space-separated name list.
## Returns 1 if cancelled or if Vservers are not available.
##
choose_one_or_more_vservers() {
[ "$vservers_are_available" == "yes" ] || return 1
local title=$1
local i=
# UI
booleanBox "$title" "Do you want to backup all vservers?" ` [ -z "$selected_vservers" -o "$selected_vservers" == "all" ] || echo no`
if [ $? = 0 ]; then
selected_vservers="all"
else
# choose among the existing vservers
local vserver=
local vserver_was_selected=
REPLY=
while [ -z "$REPLY" ]; do
listBegin "$title" "Choose at least one Linux-Vserver to backup:"
# list existing vservers, preselecting the previously selected ones
for vserver in $found_vservers; do
listItem "$vserver" "Backup $vserver vserver" `vserver_is_selected $vserver`
done
listDisplay checklist
[ $? = 0 ] || return 1
done
# remove quotes around each vserver name
selected_vservers=`echo $REPLY | tr -d '"'`
fi
}

View File

@ -97,12 +97,6 @@ These values for 'when' are invalid:
when = tues at 02 when = tues at 02
.TP .TP
.B vservers
If you are using Linux-Vservers (http://linux-vserver.org), there are some
special capabilities that different handlers have to make vserver backups easier.
See the example configuration files for each handler to configure the vserver specific
variables.
.SH DEFAULTS .SH DEFAULTS
loglevel = 4 loglevel = 4
@ -122,8 +116,6 @@ scriptdirectory = /usr/share/backupninja
usecolors = yes usecolors = yes
.br .br
when = everyday at 01:00 when = everyday at 01:00
.br
vservers = no
.SH SEE ALSO .SH SEE ALSO
.BR backupninja (1), .BR backupninja (1),

View File

@ -45,8 +45,7 @@ HELPERS="$HELPERS blue:description_of_this_helper"
} }
.IP (3) .IP (3)
look at the existing helpers to see how they are written. Try to re-use look at the existing helpers to see how they are written. Try to re-use
functions, such as the dialog functions that are defined in easydialog.sh, functions, such as the dialog functions that are defined in easydialog.sh.
or the vserver functions defined in lib/vserver.
.IP (4) .IP (4)
test, re-test, and test again. Try to break the helper by going backwards, test, re-test, and test again. Try to break the helper by going backwards,
try to think like someone who has no idea how to configure your handler try to think like someone who has no idea how to configure your handler

View File

@ -507,7 +507,6 @@ fi
# include shared functions # include shared functions
. $libdirectory/tools . $libdirectory/tools
. $libdirectory/vserver
setfile $conffile setfile $conffile
@ -546,10 +545,6 @@ getconf DSYNC /usr/bin/dsync
getconf DOVEADM /usr/bin/doveadm getconf DOVEADM /usr/bin/doveadm
getconf admingroup root getconf admingroup root
# initialize vservers support
# (get config variables and check real vservers availability)
init_vservers nodialog
if [ ! -d "$configdirectory" ]; then if [ ! -d "$configdirectory" ]; then
echo "Configuration directory '$configdirectory' not found." echo "Configuration directory '$configdirectory' not found."
fatal "Configuration directory '$configdirectory' not found." fatal "Configuration directory '$configdirectory' not found."

View File

@ -43,8 +43,6 @@ require_packages() {
## menu for the wizards ## menu for the wizards
## ##
donew() { donew() {
# (re-)initialize vservers support
init_vservers
# menu # menu
listBegin "new action menu" "select an action to create" listBegin "new action menu" "select an action to create"
listItem return "return to main menu" listItem return "return to main menu"
@ -202,7 +200,6 @@ fi
# include shared functions # include shared functions
. $libdirectory/easydialog . $libdirectory/easydialog
. $libdirectory/tools . $libdirectory/tools
. $libdirectory/vserver
# am I running as root? # am I running as root?
if [ "$UID" != "0" ]; then if [ "$UID" != "0" ]; then