r3566@krups: intrigeri | 2005-11-17 21:59:38 +0100

ninjahelper: moved (and enhanced) vservers-related functions to lib/vservers. dup.helper, pgsql.helper: use these functions
This commit is contained in:
intrigeri 2005-11-29 10:10:53 +00:00
parent 5b392f68ba
commit d56c0f0aee
7 changed files with 223 additions and 128 deletions

View File

@ -3,9 +3,11 @@ version 0.9.2 -- unreleased
rdiff ninjahelper bugfixes:
used to expand '*' in default source directories
the "Cancel" buttons used to have a weird behaviour... at least
code refactor: moved to lib/ some code that has to be shared between
code refactor:
moved to lib/ some code that has to be shared between
backupninja and ninjahelper
added duplicity ninjahelper
a bunch of Vserver-related functions for ninjahelper in lib/vservers.in
version 0.9.1 -- November 05 2005
rearranged source so that it is relocatable with autotools

View File

@ -22,10 +22,9 @@ do_dup_host_includes() {
}
do_dup_vserver() {
# choose the vservers to backup
vservers_chooser "$dup_title"
# choose the vservers to backup (into $selected_vservers)
choose_one_or_more_vservers "$dup_title"
[ $? = 0 ] || return 1
dup_vsnames="$vservers_chooser_vsnames"
set -o noglob
# choose the files to backup
@ -61,7 +60,7 @@ do_dup_excludes() {
}
do_dup_src() {
host_or_vservers_chooser "$dup_title"
choose_host_or_vservers_or_both "$dup_title"
[ $? = 0 ] || return 1
case $host_or_vservers in
'host')
@ -259,7 +258,7 @@ encryptkey = $dup_gpg_encryptkey
# include = /mnt/crypt/home/user/Mail
EOF
if [ "$host_or_vservers" == 'host' -o "$host_or_vservers" == 'both' ]; then
if [ "$host_or_vservers" == host -o "$host_or_vservers" == both ]; then
set -o noglob
for ((i=0; i < ${#dup_includes[@]} ; i++)); do
echo "include = ${dup_includes[$i]}" >> $next_filename
@ -283,9 +282,9 @@ EOF
EOF
if [ "$host_or_vservers" == 'vservers' -o "$host_or_vservers" == 'both' ]; then
if [ "$host_or_vservers" == vservers -o "$host_or_vservers" == both ]; then
set -o noglob
echo "vsnames = \"$dup_vsnames\"\n" >> $next_filename
echo -e "vsnames = \"$selected_vservers\"\n" >> $next_filename
for ((i=0; i < ${#dup_vsincludes[@]} ; i++)); do
echo "vsinclude = ${dup_vsincludes[$i]}" >> $next_filename
done
@ -408,7 +407,6 @@ dup_wizard() {
declare -a dup_includes
declare -a dup_excludes
declare -a dup_vsincludes
dup_vsnames=
dup_incremental=yes
dup_keep=60
dup_bandwidth=

View File

@ -1,8 +1,8 @@
HELPERS="$HELPERS pgsql:postgresql_database_backup"
do_pgsql_vserver() {
inputBox "$pgsql_title" "Specify a vserver name:"
[ $? = 1 ] && return;
choose_one_vserver "$pgsql_title"
[ $? = 0 ] || return 1
pgsql_vsname="vsname = $REPLY"
}
@ -32,9 +32,13 @@ pgsql_wizard() {
# constants
pgsql_title="PostgreSQL action wizard"
# vserver support
booleanBox "$pgsql_title" "Do you want to operate on a vserver? If not, the host will be operated on."
[ $? = 0 ] && do_pgsql_vserver
# 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
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"
@ -47,6 +51,7 @@ pgsql_wizard() {
pgsql_databases="databases = all"
else
do_pgsql_databases
[ $? = 0 ] || return 1
fi
# compress
@ -66,8 +71,12 @@ pgsql_wizard() {
# 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.
$pgsql_vsname
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)
# where to dump the backups
$pgsql_backupdir

View File

@ -1,6 +1,6 @@
EXTRA_DIST = easydialog.in parseini.in tools.in
EXTRA_DIST = easydialog.in parseini.in tools.in vserver.in
GENERATED_FILES = easydialog parseini tools
GENERATED_FILES = easydialog parseini tools vserver
dist_pkglib_DATA = $(GENERATED_FILES)
@ -9,14 +9,18 @@ CLEANFILES = $(GENERATED_FILES)
edit = sed \
-e "s,@BASH\@,$(BASH),g"
easydialog: #easydialog.in
easydialog:
rm -f easydialog
$(edit) easydialog.in > easydialog
parseini: #parseini.in
parseini:
rm -f parseini
$(edit) parseini.in > parseini
tools: #tools.in
tools:
rm -f tools
$(edit) tools.in > tools
vserver:
rm -f vserver
$(edit) vserver.in > vserver

View File

@ -111,8 +111,8 @@ sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
EXTRA_DIST = easydialog.in parseini.in tools.in
GENERATED_FILES = easydialog parseini tools
EXTRA_DIST = easydialog.in parseini.in tools.in vserver.in
GENERATED_FILES = easydialog parseini tools vserver
dist_pkglib_DATA = $(GENERATED_FILES)
CLEANFILES = $(GENERATED_FILES)
edit = sed \
@ -291,17 +291,21 @@ uninstall-am: uninstall-dist_pkglibDATA uninstall-info-am
uninstall-dist_pkglibDATA uninstall-info-am
easydialog: #easydialog.in
easydialog:
rm -f easydialog
$(edit) easydialog.in > easydialog
parseini: #parseini.in
parseini:
rm -f parseini
$(edit) parseini.in > parseini
tools: #tools.in
tools:
rm -f tools
$(edit) tools.in > tools
vserver:
rm -f vserver
$(edit) vserver.in > vserver
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

178
lib/vserver.in Normal file
View File

@ -0,0 +1,178 @@
#####################################################
## 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.
##
init_vservers() {
# 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 [ -f "$VSERVERINFO" ]; then $VSERVERINFO info SYSINFO |grep vserver-Rootdir | awk '{print $2}'; fi`
# 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
[ -n "$VROOTDIR" ] || (msgBox "warning" "VROOTDIR is not set in $conffile and could not be guessed."; return)
[ -d "$VROOTDIR" ] || (msgBox "warning" "VROOTDIR ($VROOTDIR) does not exist."; return)
found_vservers=`ls $VROOTDIR | grep -E -v "lost+found|ARCHIVES" | tr "\n" " "`
[ -n "$found_vservers" ] || return
vservers_are_available=yes
fi
}
##
## If the argument is the name of a vserver selected use 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, exit silently.
## 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() {
[ "$vservers_are_available" == "yes" ] || return
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, exit silently.
## 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() {
[ "$vservers_are_available" == "yes" ] || return
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

@ -58,9 +58,8 @@ require_packages() {
## menu for the wizards
##
donew() {
# reset some variables
unset host_or_vservers
unset vservers_chooser_vsnames
# (re-)initialize vservers support
init_vservers
# menu
listBegin "new action menu" "select an action to create"
listItem return "return to main menu"
@ -166,102 +165,6 @@ doaction() {
done
}
#####################################################
## VSERVERS RELATED FUNCTIONS
##
## If vservers are not enabled, exit silently and set host_or_vservers to 'host'.
## 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
## Sets, respectively, $host_or_vservers to 'host', 'vservers', or 'both'
## $host_or_vservers is unset when a new helper is run.
## Returns 1 if cancelled.
##
host_or_vservers_chooser() {
local title=$1
# exit silently if vservers are not enabled
if [ "$vservers" != "yes" ]; then
host_or_vservers='host'
return
fi
# 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
}
##
## If the argument is the name of a vserver selected for backup (in
## $vservers_chooser_vsnames), 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 $vservers_chooser_vsnames ; 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 among "all vservers" and a not-empty subset of these.
## Sets global $vservers_chooser_vsnames variable to "all" or to a
## space-separated name list.
## Depends on host_or_vservers() to have already run.
## $vservers_chooser_vsnames is unset when a new helper is run.
## Returns 1 if cancelled.
##
vservers_chooser() {
local title=$1
local i=
[ -n "$VROOTDIR" ] || (msgBox "warning" "VROOTDIR is not set in $conffile and could not be guessed."; return 1)
[ -d "$VROOTDIR" ] || (msgBox "warning" "VROOTDIR ($VROOTDIR) does not exist."; return 1)
booleanBox "$title" "Do you want to backup all vservers?" ` [ -z "$vservers_chooser_vsnames" -o "$vservers_chooser_vsnames" == "all" ] || echo no`
if [ $? = 0 ]; then
vservers_chooser_vsnames="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 `ls $VROOTDIR | grep -E -v "lost+found|ARCHIVES"`; do
listItem "$vserver" "Backup $vserver vserver" `vserver_is_selected $vserver`
done
listDisplay checklist
[ $? = 0 ] || return 1
done
# remove quotes around each vserver name
vservers_chooser_vsnames=`echo $REPLY | tr -d '"'`
fi
}
#####################################################
## begin program
@ -308,6 +211,7 @@ fi
# include shared functions
. $libdirectory/easydialog
. $libdirectory/tools
. $libdirectory/vserver
# am I running as root?
if [ "$UID" != "0" ]; then
@ -319,10 +223,6 @@ fi
setfile $conffile
getconf configdirectory @CFGDIR@/backup.d
getconf scriptdirectory @datadir@
getconf vservers no
getconf VSERVERINFO /usr/sbin/vserver-info
getconf VSERVER /usr/sbin/vserver
getconf VROOTDIR `if [ -f "$VSERVERINFO" ]; then $VSERVERINFO info SYSINFO |grep vserver-Rootdir | awk '{print $2}'; fi`
# load all the helpers
HELPERS=""