Make all indentation consistent.

Previously, there were many indentation styles in use: Real tabs, 2, 3
or 4 spaces, mixing these within the same file, function or even within
a single line.

This commit changes all bash scripts in the handlers, src and lib dirs
to use consistent indentation: three spaces are now used everywhere.
Other files (e.g. Makefiles) are left untouched.

Additionally, this commit removes all trailing whitespace.
This commit is contained in:
Matthijs Kooijman 2009-05-22 14:50:52 +02:00
parent 386c427594
commit 4ecaae9405
28 changed files with 1740 additions and 1745 deletions

View File

@ -13,11 +13,11 @@ do_dup_host_includes() {
[ -z "$dup_includes" ] && dup_includes="$dup_default_includes" [ -z "$dup_includes" ] && dup_includes="$dup_default_includes"
for i in $dup_includes; do for i in $dup_includes; do
formItem include "$i" formItem include "$i"
done done
formItem include "" formItem include ""
formItem include "" formItem include ""
formItem include "" formItem include ""
formDisplay formDisplay
[ $? = 0 ] || return 1 [ $? = 0 ] || return 1
dup_includes="$REPLY" dup_includes="$REPLY"
done done
@ -37,10 +37,10 @@ do_dup_vserver() {
[ -z "$dup_vsincludes" ] && dup_vsincludes="$dup_default_includes" [ -z "$dup_vsincludes" ] && dup_vsincludes="$dup_default_includes"
for i in $dup_vsincludes; do for i in $dup_vsincludes; do
formItem include "$i" formItem include "$i"
done done
formItem include "" formItem include ""
formItem include "" formItem include ""
formItem include "" formItem include ""
formDisplay formDisplay
[ $? = 0 ] || return 1 [ $? = 0 ] || return 1
dup_vsincludes="$REPLY" dup_vsincludes="$REPLY"
@ -69,26 +69,26 @@ do_dup_src() {
[ $? = 0 ] || return 1 [ $? = 0 ] || return 1
case $host_or_vservers in case $host_or_vservers in
'host') 'host')
do_dup_host_includes do_dup_host_includes
[ $? = 0 ] || return 1 [ $? = 0 ] || return 1
;; ;;
'vservers') 'vservers')
do_dup_vserver do_dup_vserver
[ $? = 0 ] || return 1 [ $? = 0 ] || return 1
;; ;;
'both') 'both')
do_dup_host_includes do_dup_host_includes
[ $? = 0 ] || return 1 [ $? = 0 ] || return 1
do_dup_vserver do_dup_vserver
[ $? = 0 ] || return 1 [ $? = 0 ] || return 1
;; ;;
*) *)
return 1 return 1
;; ;;
esac esac
do_dup_excludes do_dup_excludes
[ $? = 0 ] || return 1 [ $? = 0 ] || return 1
_src_done="(DONE)" _src_done="(DONE)"
setDefault dest setDefault dest
} }
@ -102,13 +102,13 @@ do_dup_dest() {
REPLY= REPLY=
while [ -z "$REPLY" -o -z "$dup_destdir" -o -z "$dup_desthost" -o -z "$dup_destuser" ]; do while [ -z "$REPLY" -o -z "$dup_destdir" -o -z "$dup_desthost" -o -z "$dup_destuser" ]; do
formBegin "$dup_title - destination: first three items are compulsory" formBegin "$dup_title - destination: first three items are compulsory"
formItem "desthost" "$dup_desthost" formItem "desthost" "$dup_desthost"
formItem "destuser" "$dup_destuser" formItem "destuser" "$dup_destuser"
formItem "destdir" "$dup_destdir" formItem "destdir" "$dup_destdir"
formItem "keep" "$dup_keep" formItem "keep" "$dup_keep"
formItem "incremental" "$dup_incremental" formItem "incremental" "$dup_incremental"
formItem "bandwidthlimit" "$dup_bandwidth" formItem "bandwidthlimit" "$dup_bandwidth"
formItem "sshoptions" "$dup_sshoptions" formItem "sshoptions" "$dup_sshoptions"
formDisplay formDisplay
[ $? = 0 ] || return 1 [ $? = 0 ] || return 1
@ -117,7 +117,7 @@ do_dup_dest() {
IFS=$':' IFS=$':'
thereply=($replyconverted) thereply=($replyconverted)
IFS=$' \t\n' IFS=$' \t\n'
dup_desthost=${thereply[0]} dup_desthost=${thereply[0]}
dup_destuser=${thereply[1]} dup_destuser=${thereply[1]}
dup_destdir=${thereply[2]} dup_destdir=${thereply[2]}
@ -165,9 +165,9 @@ do_dup_gpg_signkey() {
# signkey ? # signkey ?
REPLY= REPLY=
while [ -z "$REPLY" -o -z "$dup_gpg_signkey" ]; do while [ -z "$REPLY" -o -z "$dup_gpg_signkey" ]; do
inputBox "$dup_title - GnuPG" "Enter the ID of the private GnuPG key to be used to sign the backups:" "$dup_gpg_signkey" inputBox "$dup_title - GnuPG" "Enter the ID of the private GnuPG key to be used to sign the backups:" "$dup_gpg_signkey"
[ $? = 0 ] || return 1 [ $? = 0 ] || return 1
dup_gpg_signkey="$REPLY" dup_gpg_signkey="$REPLY"
done done
fi fi
} }
@ -183,7 +183,7 @@ do_dup_gpg_passphrase() {
} }
do_dup_gpg() { do_dup_gpg() {
# symmetric or public key encryption ? # symmetric or public key encryption ?
booleanBox "$dup_title - GnuPG" "Use public key encryption? Otherwise, symmetric encryption will be used, and data signing will be impossible." "$dup_gpg_asymmetric_encryption" booleanBox "$dup_title - GnuPG" "Use public key encryption? Otherwise, symmetric encryption will be used, and data signing will be impossible." "$dup_gpg_asymmetric_encryption"
if [ $? = 0 ]; then if [ $? = 0 ]; then
@ -197,7 +197,7 @@ do_dup_gpg() {
do_dup_gpg_encryptkey ; [ $? = 0 ] || return 1 do_dup_gpg_encryptkey ; [ $? = 0 ] || return 1
do_dup_gpg_sign ; [ $? = 0 ] || return 1 do_dup_gpg_sign ; [ $? = 0 ] || return 1
if [ "$dup_gpg_sign" == yes ]; then if [ "$dup_gpg_sign" == yes ]; then
do_dup_gpg_signkey ; [ $? = 0 ] || return 1 do_dup_gpg_signkey ; [ $? = 0 ] || return 1
fi fi
else else
dup_gpg_sign=no dup_gpg_sign=no
@ -334,7 +334,7 @@ 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 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 fi
@ -432,49 +432,49 @@ EOF
dup_main_menu() { dup_main_menu() {
while true; do while true; do
srcitem="choose files to include & exclude $_src_done" srcitem="choose files to include & exclude $_src_done"
destitem="configure backup destination $_dest_done" destitem="configure backup destination $_dest_done"
gpgitem="configure GnuPG encryption/signing $_gpg_done" gpgitem="configure GnuPG encryption/signing $_gpg_done"
conitem="set up ssh keys and test remote connection $_con_done" conitem="set up ssh keys and test remote connection $_con_done"
advitem="edit advanced settings $_adv_done" advitem="edit advanced settings $_adv_done"
# TODO: add the following to the menu when do_dup_conn is written # TODO: add the following to the menu when do_dup_conn is written
# conn "$conitem" \ # conn "$conitem" \
menuBox "$dup_title" "choose a step:" \ menuBox "$dup_title" "choose a step:" \
src "$srcitem" \ src "$srcitem" \
dest "$destitem" \ dest "$destitem" \
gpg "$gpgitem" \ gpg "$gpgitem" \
adv "$advitem" \ adv "$advitem" \
finish "finish and create config file" finish "finish and create config file"
[ $? = 0 ] || return 1 [ $? = 0 ] || return 1
result="$REPLY" result="$REPLY"
case "$result" in case "$result" in
"src") do_dup_src;; "src") do_dup_src;;
"dest") do_dup_dest;; "dest") do_dup_dest;;
"gpg") do_dup_gpg;; "gpg") do_dup_gpg;;
# TODO: enable the following when do_dup_conn is written # TODO: enable the following when do_dup_conn is written
# "conn") do_dup_conn;; # "conn") do_dup_conn;;
"adv") do_dup_adv;; "adv") do_dup_adv;;
"finish") "finish")
if [[ "$_dest_done$_gpg_done$_src_done" != "(DONE)(DONE)(DONE)" ]]; then if [[ "$_dest_done$_gpg_done$_src_done" != "(DONE)(DONE)(DONE)" ]]; then
# TODO: replace the previous test by the following when do_dup_conn is written # TODO: replace the previous test by the following when do_dup_conn is written
# if [[ "$_con_done$_dest_done$_gpg_done$_src_done" != "(DONE)(DONE)(DONE)(DONE)" ]]; then # if [[ "$_con_done$_dest_done$_gpg_done$_src_done" != "(DONE)(DONE)(DONE)(DONE)" ]]; then
msgBox "$dup_title" "You cannot create the configuration file until the four first steps are completed." msgBox "$dup_title" "You cannot create the configuration file until the four first steps are completed."
else else
do_dup_finish do_dup_finish
break break
fi fi
;; ;;
esac esac
done done
} }
### Main function ### Main function
dup_wizard() { dup_wizard() {
require_packages duplicity require_packages duplicity
# Global variables # Global variables

View File

@ -66,9 +66,9 @@ if [ "$testconnect" == "yes" ]; then
if [ ! $test ]; then if [ ! $test ]; then
result=`ssh $sshoptions -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'` result=`ssh $sshoptions -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'`
if [ "$result" != "1" ]; then if [ "$result" != "1" ]; then
fatal "Can't connect to $desthost as $destuser." fatal "Can't connect to $desthost as $destuser."
else else
debug "Connected to $desthost as $destuser successfully" debug "Connected to $desthost as $destuser successfully"
fi fi
fi fi
fi fi
@ -152,7 +152,7 @@ fi
# If incremental==no, force a full backup anyway. # If incremental==no, force a full backup anyway.
if [ "$incremental" == "no" ]; then if [ "$incremental" == "no" ]; then
# before 0.4.4, full was an option and not a command # before 0.4.4, full was an option and not a command
if [ "$duplicity_major" -le 0 -a "$duplicity_minor" -le 4 -a "$duplicity_sub" -lt 4 ]; then if [ "$duplicity_major" -le 0 -a "$duplicity_minor" -le 4 -a "$duplicity_sub" -lt 4 ]; then
execstr_options="${execstr_options} --full" execstr_options="${execstr_options} --full"
else else
execstr_command="full" execstr_command="full"
@ -204,9 +204,9 @@ done
if [ $usevserver = yes ]; then if [ $usevserver = yes ]; then
for vserver in $vsnames; do for vserver in $vsnames; do
for vi in $vsinclude; do for vi in $vsinclude; do
str="${vi//__star__/*}" str="${vi//__star__/*}"
str="$VROOTDIR/$vserver$str" str="$VROOTDIR/$vserver$str"
execstr_source="${execstr_source} --include '$str'" execstr_source="${execstr_source} --include '$str'"
done done
done done
fi fi
@ -229,11 +229,11 @@ if [ "$duplicity_major" -ge 0 -a "$duplicity_minor" -ge 4 -a "$duplicity_sub" -g
"$precmd duplicity cleanup --force $execstr_options $execstr_serverpart 2>&1"` "$precmd duplicity cleanup --force $execstr_options $execstr_serverpart 2>&1"`
exit_code=$? exit_code=$?
if [ $exit_code -eq 0 ]; then if [ $exit_code -eq 0 ]; then
debug $output debug $output
info "Duplicity cleanup finished successfully." info "Duplicity cleanup finished successfully."
else else
debug $output debug $output
warning "Duplicity cleanup failed." warning "Duplicity cleanup failed."
fi fi
fi fi
fi fi
@ -244,17 +244,17 @@ if [ "$keep" != "yes" ]; then
debug "$precmd duplicity remove-older-than $keep --force $execstr_options $execstr_serverpart" debug "$precmd duplicity remove-older-than $keep --force $execstr_options $execstr_serverpart"
if [ ! $test ]; then if [ ! $test ]; then
export PASSPHRASE=$password export PASSPHRASE=$password
output=`nice -n $nicelevel \ output=`nice -n $nicelevel \
su -c \ su -c \
"$precmd duplicity remove-older-than $keep --force $execstr_options $execstr_serverpart 2>&1"` "$precmd duplicity remove-older-than $keep --force $execstr_options $execstr_serverpart 2>&1"`
exit_code=$? exit_code=$?
if [ $exit_code -eq 0 ]; then if [ $exit_code -eq 0 ]; then
debug $output debug $output
info "Duplicity remove-older-than finished successfully." info "Duplicity remove-older-than finished successfully."
else else
debug $output debug $output
warning "Duplicity remove-older-than failed." warning "Duplicity remove-older-than failed."
fi fi
fi fi
fi fi
fi fi

View File

@ -3,7 +3,7 @@
HELPERS="$HELPERS ldap:ldap_database_backup" HELPERS="$HELPERS ldap:ldap_database_backup"
ldap_create_file() { ldap_create_file() {
while true; do while true; do
checkBox "ldap action wizard" "check options (slapcat OR ldapsearch)" \ checkBox "ldap action wizard" "check options (slapcat OR ldapsearch)" \
"slapcat" "export ldif using slapcat" yes \ "slapcat" "export ldif using slapcat" yes \
"ldapsearch" "export ldif using ldapsearch" no \ "ldapsearch" "export ldif using ldapsearch" no \
@ -22,21 +22,21 @@ while true; do
result="$REPLY" result="$REPLY"
for opt in $result; do for opt in $result; do
case $opt in case $opt in
'"compress"') compress="compress = yes";; '"compress"') compress="compress = yes";;
'"slapcat"') '"slapcat"')
method="method = slapcat" method="method = slapcat"
[ "$_RESTART" == "yes" ] && restart="restart = yes" [ "$_RESTART" == "yes" ] && restart="restart = yes"
;; ;;
'"ldapsearch"') '"ldapsearch"')
method="method = ldapsearch" method="method = ldapsearch"
inputBox "ldap action wizard" "ldapsearch requires authentication. Specify here what password file to use. It must have the password with no trailing return and it should not be world readable." inputBox "ldap action wizard" "ldapsearch requires authentication. Specify here what password file to use. It must have the password with no trailing return and it should not be world readable."
[ $? = 1 ] && return [ $? = 1 ] && return
passwordfile="passwordfile = $REPLY" passwordfile="passwordfile = $REPLY"
inputBox "ldap action wizard" "ldapsearch requires authentication. Specify here what DN to bind as:" inputBox "ldap action wizard" "ldapsearch requires authentication. Specify here what DN to bind as:"
[ $? = 1 ] && return [ $? = 1 ] && return
binddn="binddn = $REPLY" binddn="binddn = $REPLY"
require_packages ldap-utils require_packages ldap-utils
;; ;;
'"ssl"') ssl="ssl = yes";; '"ssl"') ssl="ssl = yes";;
'"tls"') tls="tls = yes";; '"tls"') tls="tls = yes";;
esac esac
@ -54,9 +54,9 @@ $tls
# conf = /etc/ldap/slapd.conf # conf = /etc/ldap/slapd.conf
# databases = all # databases = all
EOF EOF
chmod 600 $next_filename chmod 600 $next_filename
return return
done done
} }
ldap_wizard() { ldap_wizard() {
@ -71,7 +71,7 @@ ldap_wizard() {
elif [ "$backend" == "ldbm" ]; then elif [ "$backend" == "ldbm" ]; then
ldbm=yes ldbm=yes
fi fi
done done
if [ "$bdb" == "yes" -o "$hdb" == "yes" ]; then if [ "$bdb" == "yes" -o "$hdb" == "yes" ]; then
if [ "$ldbm" == "no" ]; then if [ "$ldbm" == "no" ]; then
@ -80,11 +80,11 @@ ldap_wizard() {
ldap_create_file ldap_create_file
fi fi
elif [ "$ldbm" == "yes" ]; then elif [ "$ldbm" == "yes" ]; then
msgBox "ldap action wizard" "It looks like the backend in your slapd.conf is set to LDBM. Because of this, you will have less options (because it is not safe to use slapcat while slapd is running LDBM)." msgBox "ldap action wizard" "It looks like the backend in your slapd.conf is set to LDBM. Because of this, you will have less options (because it is not safe to use slapcat while slapd is running LDBM)."
_RESTART=yes _RESTART=yes
ldap_create_file ldap_create_file
else else
msgBox "ldap action wizard" "I couldn't find any supported backend in your slapd.conf. Bailing out." msgBox "ldap action wizard" "I couldn't find any supported backend in your slapd.conf. Bailing out."
return return
fi fi
} }

View File

@ -35,25 +35,25 @@ dbsuffixes=(`@AWK@ 'BEGIN {OFS=":"} /[:space:]*^database[:space:]*\w*/ {db=$2};
if [ "$ldif" == "yes" ]; then if [ "$ldif" == "yes" ]; then
dumpdir="$backupdir" dumpdir="$backupdir"
[ -d $dumpdir ] || mkdir -p $dumpdir [ -d $dumpdir ] || mkdir -p $dumpdir
if [ "$databases" == 'all' ]; then if [ "$databases" == 'all' ]; then
dbcount=`grep '^database' $conf | wc -l` dbcount=`grep '^database' $conf | wc -l`
let "dbcount = dbcount - 1" let "dbcount = dbcount - 1"
databases=`seq 0 $dbcount`; databases=`seq 0 $dbcount`;
fi fi
for db in $databases; do for db in $databases; do
if [ `expr index "$db" "="` == "0" ]; then if [ `expr index "$db" "="` == "0" ]; then
# db is a number, get the suffix. # db is a number, get the suffix.
dbsuffix=${dbsuffixes[$db]/*:/} dbsuffix=${dbsuffixes[$db]/*:/}
else else
dbsuffix=$db dbsuffix=$db
fi fi
# some databases don't have suffix (like monitor), skip these # some databases don't have suffix (like monitor), skip these
if [ "$dbsuffix" == "" ]; then if [ "$dbsuffix" == "" ]; then
continue; continue;
fi fi
if [ "$method" == "slapcat" ]; then if [ "$method" == "slapcat" ]; then
execstr="$SLAPCAT -f $conf -b $dbsuffix" execstr="$SLAPCAT -f $conf -b $dbsuffix"
else else
@ -74,16 +74,16 @@ if [ "$ldif" == "yes" ]; then
debug "Shutting down ldap server..." debug "Shutting down ldap server..."
/etc/init.d/slapd stop /etc/init.d/slapd stop
fi fi
ext= ext=
if [ "$compress" == "yes" ]; then if [ "$compress" == "yes" ]; then
ext=".gz" ext=".gz"
fi fi
touch $dumpdir/$dbsuffix.ldif$ext touch $dumpdir/$dbsuffix.ldif$ext
if [ ! -f $dumpdir/$dbsuffix.ldif$ext ]; then if [ ! -f $dumpdir/$dbsuffix.ldif$ext ]; then
fatal "Couldn't create ldif dump file: $dumpdir/$dbsuffix.ldif$ext" fatal "Couldn't create ldif dump file: $dumpdir/$dbsuffix.ldif$ext"
fi fi
if [ "$compress" == "yes" ]; then if [ "$compress" == "yes" ]; then
execstr="$execstr | $GZIP > $dumpdir/$dbsuffix.ldif.gz" execstr="$execstr | $GZIP > $dumpdir/$dbsuffix.ldif.gz"
else else
@ -99,13 +99,13 @@ if [ "$ldif" == "yes" ]; then
warning $output warning $output
warning "Failed ldif export of $dbsuffix" warning "Failed ldif export of $dbsuffix"
fi fi
if [ "$restart" == "yes" ]; then if [ "$restart" == "yes" ]; then
debug "Starting ldap server..." debug "Starting ldap server..."
/etc/init.d/slapd start /etc/init.d/slapd start
fi fi
fi fi
done done
fi fi
return 0 return 0

View File

@ -6,17 +6,17 @@
# to a remote server. It is designed to be run with low overhead # to a remote server. It is designed to be run with low overhead
# in terms of cpu and bandwidth so it runs pretty slow. # in terms of cpu and bandwidth so it runs pretty slow.
# Hardlinking is used to save storage space. # Hardlinking is used to save storage space.
# #
# This handler expects that your maildir directory structure is # This handler expects that your maildir directory structure is
# either one of the following: # either one of the following:
# #
# 1. /$srcdir/[a-zA-Z0-9]/$user for example: # 1. /$srcdir/[a-zA-Z0-9]/$user for example:
# /var/maildir/a/anarchist # /var/maildir/a/anarchist
# /var/maildir/a/arthur # /var/maildir/a/arthur
# ... # ...
# /var/maildir/Z/Zaphod # /var/maildir/Z/Zaphod
# /var/maildir/Z/Zebra # /var/maildir/Z/Zebra
# #
# 2. or the following: # 2. or the following:
# /var/maildir/domain.org/user1 # /var/maildir/domain.org/user1
# /var/maildir/domain.org/user2 # /var/maildir/domain.org/user2
@ -25,7 +25,7 @@
# /var/maildir/anotherdomain.org/user2 # /var/maildir/anotherdomain.org/user2
# ... # ...
# #
# if the configuration is setup to have keepdaily at 3, # if the configuration is setup to have keepdaily at 3,
# keepweekly is 2, and keepmonthly is 1, then each user's # keepweekly is 2, and keepmonthly is 1, then each user's
# maildir backup snapshot directory will contain these files: # maildir backup snapshot directory will contain these files:
# daily.1 # daily.1
@ -41,15 +41,15 @@
# We handle each maildir individually because it becomes very # We handle each maildir individually because it becomes very
# unweldy to hardlink and rsync many hundreds of thousands # unweldy to hardlink and rsync many hundreds of thousands
# of files at once. It is much faster to take on smaller # of files at once. It is much faster to take on smaller
# chunks at a time. # chunks at a time.
# #
# For the backup rotation to work, destuser must be able to run # For the backup rotation to work, destuser must be able to run
# arbitrary bash commands on the desthost. # arbitrary bash commands on the desthost.
# #
# Any maildir which is deleted from the source will be moved to # Any maildir which is deleted from the source will be moved to
# "deleted" directory in the destination. It is up to you to # "deleted" directory in the destination. It is up to you to
# periodically remove this directory or old maildirs in it. # periodically remove this directory or old maildirs in it.
# #
############################################################## ##############################################################
getconf rotate yes getconf rotate yes
@ -91,33 +91,33 @@ excludes="--exclude '.Trash/\*' --exclude '.Mistakes/\*' --exclude '.Spam/\*'"
### FUNCTIONS ### FUNCTIONS
function do_user() { function do_user() {
local user=$1 local user=$1
local btype=$2 local btype=$2
local userdir=${3%/} local userdir=${3%/}
local source="$srcdir/$userdir/$user/" local source="$srcdir/$userdir/$user/"
local target="$destdir/$userdir/$user/$btype.1" local target="$destdir/$userdir/$user/$btype.1"
if [ ! -d $source ]; then if [ ! -d $source ]; then
warning "maildir $source not found" warning "maildir $source not found"
return return
fi fi
debug "syncing" debug "syncing"
ret=`$RSYNC -e "ssh -p $destport -i $destid_file" -r \ ret=`$RSYNC -e "ssh -p $destport -i $destid_file" -r \
--links --ignore-existing --delete --size-only --bwlimit=$speedlimit \ --links --ignore-existing --delete --size-only --bwlimit=$speedlimit \
--exclude '.Trash/*' --exclude '.Mistakes/*' --exclude '.Spam/*' \ --exclude '.Trash/*' --exclude '.Mistakes/*' --exclude '.Spam/*' \
$source $destuser@$desthost:$target \ $source $destuser@$desthost:$target \
2>&1` 2>&1`
ret=$? ret=$?
# ignore 0 (success) and 24 (file vanished before it could be copied) # ignore 0 (success) and 24 (file vanished before it could be copied)
if [ $ret != 0 -a $ret != 24 ]; then if [ $ret != 0 -a $ret != 24 ]; then
warning "rsync $user failed" warning "rsync $user failed"
warning " returned: $ret" warning " returned: $ret"
let "failedcount = failedcount + 1" let "failedcount = failedcount + 1"
if [ $failedcount -gt 100 ]; then if [ $failedcount -gt 100 ]; then
fatal "100 rsync errors -- something is not working right. bailing out." fatal "100 rsync errors -- something is not working right. bailing out."
fi fi
fi fi
ssh -o PasswordAuthentication=no $desthost -l $destuser -i $destid_file "date +%c%n%s > $target/created" ssh -o PasswordAuthentication=no $desthost -l $destuser -i $destid_file "date +%c%n%s > $target/created"
} }
# remove any maildirs from backup which might have been deleted # remove any maildirs from backup which might have been deleted
@ -125,116 +125,116 @@ function do_user() {
# (actually, it just moved them to the directory "deleted") # (actually, it just moved them to the directory "deleted")
function do_remove() { function do_remove() {
local tmp1=`maketemp maildir-tmp-file` local tmp1=`maketemp maildir-tmp-file`
local tmp2=`maketemp maildir-tmp-file` local tmp2=`maketemp maildir-tmp-file`
ssh -p $destport -i $destid_file $destuser@$desthost mkdir -p "$destdir/deleted" ssh -p $destport -i $destid_file $destuser@$desthost mkdir -p "$destdir/deleted"
cd "$srcdir" cd "$srcdir"
for userdir in `ls -d1 */`; do for userdir in `ls -d1 */`; do
ls -1 "$srcdir/$userdir" | sort > $tmp1 ls -1 "$srcdir/$userdir" | sort > $tmp1
ssh -p $destport -i $destid_file $destuser@$desthost ls -1 "$destdir/$userdir" | sort > $tmp2 ssh -p $destport -i $destid_file $destuser@$desthost ls -1 "$destdir/$userdir" | sort > $tmp2
for deluser in `join -v 2 $tmp1 $tmp2`; do for deluser in `join -v 2 $tmp1 $tmp2`; do
[ "$deluser" != "" ] || continue [ "$deluser" != "" ] || continue
info "removing $destuser@$desthost:$destdir/$userdir$deluser/" info "removing $destuser@$desthost:$destdir/$userdir$deluser/"
ssh -p $destport -i $destid_file $destuser@$desthost mv "$destdir/$userdir$deluser/" "$destdir/deleted" ssh -p $destport -i $destid_file $destuser@$desthost mv "$destdir/$userdir$deluser/" "$destdir/deleted"
ssh -p $destport -i $destid_file $destuser@$desthost "date +%c%n%s > '$destdir/deleted/$deluser/deleted_on'" ssh -p $destport -i $destid_file $destuser@$desthost "date +%c%n%s > '$destdir/deleted/$deluser/deleted_on'"
done done
done done
rm $tmp1 rm $tmp1
rm $tmp2 rm $tmp2
} }
function do_rotate() { function do_rotate() {
[ "$rotate" == "yes" ] || return; [ "$rotate" == "yes" ] || return;
local user=$1 local user=$1
local userdir=${2%/} local userdir=${2%/}
local backuproot="$destdir/$userdir/$user" local backuproot="$destdir/$userdir/$user"
( (
ssh -T -o PasswordAuthentication=no $desthost -l $destuser -i $destid_file <<EOF ssh -T -o PasswordAuthentication=no $desthost -l $destuser -i $destid_file <<EOF
##### BEGIN REMOTE SCRIPT ##### ##### BEGIN REMOTE SCRIPT #####
seconds_daily=86400 seconds_daily=86400
seconds_weekly=604800 seconds_weekly=604800
seconds_monthly=2628000 seconds_monthly=2628000
keepdaily=$keepdaily keepdaily=$keepdaily
keepweekly=$keepweekly keepweekly=$keepweekly
keepmonthly=$keepmonthly keepmonthly=$keepmonthly
now=\`date +%s\` now=\`date +%s\`
if [ ! -d "$backuproot" ]; then if [ ! -d "$backuproot" ]; then
echo "Debug: skipping rotate of $user. $backuproot doesn't exist." echo "Debug: skipping rotate of $user. $backuproot doesn't exist."
exit exit
fi fi
for rottype in daily weekly monthly; do for rottype in daily weekly monthly; do
seconds=\$((seconds_\${rottype})) seconds=\$((seconds_\${rottype}))
dir="$backuproot/\$rottype" dir="$backuproot/\$rottype"
if [ ! -d \$dir.1 ]; then if [ ! -d \$dir.1 ]; then
echo "Debug: \$dir.1 does not exist, skipping." echo "Debug: \$dir.1 does not exist, skipping."
continue 1 continue 1
elif [ ! -f \$dir.1/created ]; then elif [ ! -f \$dir.1/created ]; then
echo "Warning: \$dir.1/created does not exist. This backup may be only partially completed. Skipping rotation." echo "Warning: \$dir.1/created does not exist. This backup may be only partially completed. Skipping rotation."
continue 1 continue 1
fi fi
# Rotate the current list of backups, if we can.
oldest=\`find $backuproot -maxdepth 1 -type d -name \$rottype'.*' | @SED@ 's/^.*\.//' | sort -n | tail -1\`
#echo "Debug: oldest \$oldest"
[ "\$oldest" == "" ] && oldest=0
for (( i=\$oldest; i > 0; i-- )); do
if [ -d \$dir.\$i ]; then
if [ -f \$dir.\$i/created ]; then
created=\`tail -1 \$dir.\$i/created\`
else
created=0
fi
cutoff_time=\$(( now - (seconds*(i-1)) ))
if [ ! \$created -gt \$cutoff_time ]; then
next=\$(( i + 1 ))
if [ ! -d \$dir.\$next ]; then
echo "Debug: \$rottype.\$i --> \$rottype.\$next"
mv \$dir.\$i \$dir.\$next
date +%c%n%s > \$dir.\$next/rotated
else
echo "Debug: skipping rotation of \$dir.\$i because \$dir.\$next already exists."
fi
else
echo "Debug: skipping rotation of \$dir.\$i because it was created" \$(( (now-created)/86400)) "days ago ("\$(( (now-cutoff_time)/86400))" needed)."
fi
fi
done
done
max=\$((keepdaily+1)) # Rotate the current list of backups, if we can.
if [ \( \$keepweekly -gt 0 -a -d $backuproot/daily.\$max \) -a ! -d $backuproot/weekly.1 ]; then oldest=\`find $backuproot -maxdepth 1 -type d -name \$rottype'.*' | @SED@ 's/^.*\.//' | sort -n | tail -1\`
echo "Debug: daily.\$max --> weekly.1" #echo "Debug: oldest \$oldest"
mv $backuproot/daily.\$max $backuproot/weekly.1 [ "\$oldest" == "" ] && oldest=0
date +%c%n%s > $backuproot/weekly.1/rotated for (( i=\$oldest; i > 0; i-- )); do
fi if [ -d \$dir.\$i ]; then
if [ -f \$dir.\$i/created ]; then
created=\`tail -1 \$dir.\$i/created\`
else
created=0
fi
cutoff_time=\$(( now - (seconds*(i-1)) ))
if [ ! \$created -gt \$cutoff_time ]; then
next=\$(( i + 1 ))
if [ ! -d \$dir.\$next ]; then
echo "Debug: \$rottype.\$i --> \$rottype.\$next"
mv \$dir.\$i \$dir.\$next
date +%c%n%s > \$dir.\$next/rotated
else
echo "Debug: skipping rotation of \$dir.\$i because \$dir.\$next already exists."
fi
else
echo "Debug: skipping rotation of \$dir.\$i because it was created" \$(( (now-created)/86400)) "days ago ("\$(( (now-cutoff_time)/86400))" needed)."
fi
fi
done
done
max=\$((keepweekly+1)) max=\$((keepdaily+1))
if [ \( \$keepmonthly -gt 0 -a -d $backuproot/weekly.\$max \) -a ! -d $backuproot/monthly.1 ]; then if [ \( \$keepweekly -gt 0 -a -d $backuproot/daily.\$max \) -a ! -d $backuproot/weekly.1 ]; then
echo "Debug: weekly.\$max --> monthly.1" echo "Debug: daily.\$max --> weekly.1"
mv $backuproot/weekly.\$max $backuproot/monthly.1 mv $backuproot/daily.\$max $backuproot/weekly.1
date +%c%n%s > $backuproot/monthly.1/rotated date +%c%n%s > $backuproot/weekly.1/rotated
fi fi
for rottype in daily weekly monthly; do max=\$((keepweekly+1))
max=\$((keep\${rottype}+1)) if [ \( \$keepmonthly -gt 0 -a -d $backuproot/weekly.\$max \) -a ! -d $backuproot/monthly.1 ]; then
dir="$backuproot/\$rottype" echo "Debug: weekly.\$max --> monthly.1"
oldest=\`find $backuproot -maxdepth 1 -type d -name \$rottype'.*' | @SED@ 's/^.*\.//' | sort -n | tail -1\` mv $backuproot/weekly.\$max $backuproot/monthly.1
[ "\$oldest" == "" ] && oldest=0 date +%c%n%s > $backuproot/monthly.1/rotated
# if we've rotated the last backup off the stack, remove it. fi
for (( i=\$oldest; i >= \$max; i-- )); do
if [ -d \$dir.\$i ]; then for rottype in daily weekly monthly; do
if [ -d $backuproot/rotate.tmp ]; then max=\$((keep\${rottype}+1))
echo "Debug: removing rotate.tmp" dir="$backuproot/\$rottype"
rm -rf $backuproot/rotate.tmp oldest=\`find $backuproot -maxdepth 1 -type d -name \$rottype'.*' | @SED@ 's/^.*\.//' | sort -n | tail -1\`
fi [ "\$oldest" == "" ] && oldest=0
echo "Debug: moving \$rottype.\$i to rotate.tmp" # if we've rotated the last backup off the stack, remove it.
mv \$dir.\$i $backuproot/rotate.tmp for (( i=\$oldest; i >= \$max; i-- )); do
fi if [ -d \$dir.\$i ]; then
done if [ -d $backuproot/rotate.tmp ]; then
done echo "Debug: removing rotate.tmp"
rm -rf $backuproot/rotate.tmp
fi
echo "Debug: moving \$rottype.\$i to rotate.tmp"
mv \$dir.\$i $backuproot/rotate.tmp
fi
done
done
####### END REMOTE SCRIPT ####### ####### END REMOTE SCRIPT #######
EOF EOF
) | (while read a; do passthru $a; done) ) | (while read a; do passthru $a; done)
@ -243,67 +243,67 @@ EOF
function setup_remote_dirs() { function setup_remote_dirs() {
local user=$1 local user=$1
local backuptype=$2 local backuptype=$2
local userdir=${3%/} local userdir=${3%/}
local dir="$destdir/$userdir/$user/$backuptype" local dir="$destdir/$userdir/$user/$backuptype"
local tmpdir="$destdir/$userdir/$user/rotate.tmp" local tmpdir="$destdir/$userdir/$user/rotate.tmp"
( (
ssh -T -o PasswordAuthentication=no $desthost -l $destuser -i $destid_file <<EOF ssh -T -o PasswordAuthentication=no $desthost -l $destuser -i $destid_file <<EOF
if [ ! -d $destdir ]; then if [ ! -d $destdir ]; then
echo "Fatal: Destination directory $destdir does not exist on host $desthost." echo "Fatal: Destination directory $destdir does not exist on host $desthost."
exit 1 exit 1
elif [ -d $dir.1 ]; then elif [ -d $dir.1 ]; then
if [ -f $dir.1/created ]; then if [ -f $dir.1/created ]; then
echo "Warning: $dir.1 already exists. Overwriting contents." echo "Warning: $dir.1 already exists. Overwriting contents."
else else
echo "Warning: we seem to be resuming a partially written $dir.1" echo "Warning: we seem to be resuming a partially written $dir.1"
fi fi
else else
if [ -d $tmpdir ]; then if [ -d $tmpdir ]; then
mv $tmpdir $dir.1 mv $tmpdir $dir.1
if [ \$? == 1 ]; then if [ \$? == 1 ]; then
echo "Fatal: could mv $destdir/rotate.tmp $dir.1 on host $desthost" echo "Fatal: could mv $destdir/rotate.tmp $dir.1 on host $desthost"
exit 1 exit 1
fi fi
else else
mkdir --parents $dir.1 mkdir --parents $dir.1
if [ \$? == 1 ]; then if [ \$? == 1 ]; then
echo "Fatal: could not create directory $dir.1 on host $desthost" echo "Fatal: could not create directory $dir.1 on host $desthost"
exit 1 exit 1
fi fi
fi fi
if [ -d $dir.2 ]; then if [ -d $dir.2 ]; then
echo "Debug: update links $backuptype.2 --> $backuptype.1" echo "Debug: update links $backuptype.2 --> $backuptype.1"
cp -alf $dir.2/. $dir.1 cp -alf $dir.2/. $dir.1
#if [ \$? == 1 ]; then #if [ \$? == 1 ]; then
# echo "Fatal: could not create hard links to $dir.1 on host $desthost" # echo "Fatal: could not create hard links to $dir.1 on host $desthost"
# exit 1 # exit 1
#fi #fi
fi fi
fi fi
[ -f $dir.1/created ] && rm $dir.1/created [ -f $dir.1/created ] && rm $dir.1/created
[ -f $dir.1/rotated ] && rm $dir.1/rotated [ -f $dir.1/rotated ] && rm $dir.1/rotated
exit 0 exit 0
EOF EOF
) | (while read a; do passthru $a; done) ) | (while read a; do passthru $a; done)
if [ $? == 1 ]; then exit; fi if [ $? == 1 ]; then exit; fi
} }
function start_mux() { function start_mux() {
if [ "$multiconnection" == "yes" ]; then if [ "$multiconnection" == "yes" ]; then
debug "Starting dummy ssh connection" debug "Starting dummy ssh connection"
ssh -p $destport -i $destid_file $destuser@$desthost sleep 1d & ssh -p $destport -i $destid_file $destuser@$desthost sleep 1d &
sleep 1 sleep 1
fi fi
} }
function end_mux() { function end_mux() {
if [ "$multiconnection" == "yes" ]; then if [ "$multiconnection" == "yes" ]; then
debug "Stopping dummy ssh connection" debug "Stopping dummy ssh connection"
ssh -p $destport -i $destid_file $destuser@$desthost pkill sleep ssh -p $destport -i $destid_file $destuser@$desthost pkill sleep
fi fi
} }
### ###
@ -312,10 +312,10 @@ function end_mux() {
# see if we can login # see if we can login
debug "ssh -o PasswordAuthentication=no $desthost -l $destuser -i $destid_file 'echo -n 1'" debug "ssh -o PasswordAuthentication=no $desthost -l $destuser -i $destid_file 'echo -n 1'"
if [ ! $test ]; then if [ ! $test ]; then
result=`ssh -o PasswordAuthentication=no $desthost -l $destuser -i $destid_file 'echo -n 1' 2>&1` result=`ssh -o PasswordAuthentication=no $desthost -l $destuser -i $destid_file 'echo -n 1' 2>&1`
if [ "$result" != "1" ]; then if [ "$result" != "1" ]; then
fatal "Can't connect to $desthost as $destuser using $destid_file." fatal "Can't connect to $desthost as $destuser using $destid_file."
fi fi
fi fi
end_mux end_mux
@ -324,47 +324,46 @@ start_mux
## SANITY CHECKS ## ## SANITY CHECKS ##
status=`ssh -p $destport -i $destid_file $destuser@$desthost "[ -d \"$destdir\" ] && echo 'ok'"` status=`ssh -p $destport -i $destid_file $destuser@$desthost "[ -d \"$destdir\" ] && echo 'ok'"`
if [ "$status" != "ok" ]; then if [ "$status" != "ok" ]; then
end_mux end_mux
fatal "Destination directory $destdir doesn't exist!" fatal "Destination directory $destdir doesn't exist!"
exit exit
fi fi
### REMOVE OLD MAILDIRS ### ### REMOVE OLD MAILDIRS ###
if [ "$remove" == "yes" ]; then if [ "$remove" == "yes" ]; then
do_remove do_remove
fi fi
### MAKE BACKUPS ### ### MAKE BACKUPS ###
if [ "$backup" == "yes" ]; then if [ "$backup" == "yes" ]; then
if [ $keepdaily -gt 0 ]; then btype=daily if [ $keepdaily -gt 0 ]; then btype=daily
elif [ $keepweekly -gt 0 ]; then btype=weekly elif [ $keepweekly -gt 0 ]; then btype=weekly
elif [ $keepmonthly -gt 0 ]; then btype=monthly elif [ $keepmonthly -gt 0 ]; then btype=monthly
else fatal "keeping no backups"; fi else fatal "keeping no backups"; fi
if [ "$testuser" != "" ]; then if [ "$testuser" != "" ]; then
cd "$srcdir/${user:0:1}" cd "$srcdir/${user:0:1}"
do_rotate $testuser do_rotate $testuser
setup_remote_dirs $testuser $btype setup_remote_dirs $testuser $btype
do_user $testuser $btype do_user $testuser $btype
else else
[ -d "$srcdir" ] || fatal "directory $srcdir not found." [ -d "$srcdir" ] || fatal "directory $srcdir not found."
cd "$srcdir" cd "$srcdir"
for userdir in `ls -d1 */`; do for userdir in `ls -d1 */`; do
[ -d "$srcdir/$userdir" ] || fatal "directory $srcdir/$userdir not found." [ -d "$srcdir/$userdir" ] || fatal "directory $srcdir/$userdir not found."
cd "$srcdir/$userdir" cd "$srcdir/$userdir"
debug $userdir debug $userdir
for user in `ls -1`; do for user in `ls -1`; do
[ "$user" != "" ] || continue [ "$user" != "" ] || continue
debug "$user $userdir" debug "$user $userdir"
do_rotate $user $userdir do_rotate $user $userdir
setup_remote_dirs $user $btype $userdir setup_remote_dirs $user $btype $userdir
do_user $user $btype $userdir do_user $user $btype $userdir
done done
done done
fi fi
fi fi
end_mux end_mux

View File

@ -7,59 +7,59 @@ declare -a makecd_excludes
makecd_wizard() { makecd_wizard() {
inputBox "$wizardname" "specify a burner type cd or dvd:" inputBox "$wizardname" "specify a burner type cd or dvd:"
[ $? = 1 ] && return [ $? = 1 ] && return
burnertype="burnertype = $REPLY" burnertype="burnertype = $REPLY"
booleanBox "$wizardname" "Make iso image only? or burn" booleanBox "$wizardname" "Make iso image only? or burn"
if [ $? = 0 ]; then if [ $? = 0 ]; then
isoonly="isoonly = yes" isoonly="isoonly = yes"
else else
isoonly="isoonly = no" isoonly="isoonly = no"
fi fi
# backupdir # backupdir
inputBox "$wizardname" "Directory where to store the backups:" inputBox "$wizardname" "Directory where to store the backups:"
[ $? = 1 ] && return [ $? = 1 ] && return
backupdir="backupdir = $REPLY" backupdir="backupdir = $REPLY"
inputBox "$wizardname" "what name to give to the image file?" inputBox "$wizardname" "what name to give to the image file?"
[ $? = 1 ] && return [ $? = 1 ] && return
imagefile="imagefile = $REPLY" imagefile="imagefile = $REPLY"
inputBox "$wizardname" "specify a burner device:" inputBox "$wizardname" "specify a burner device:"
[ $? = 1 ] && return [ $? = 1 ] && return
device="device = $REPLY" device="device = $REPLY"
# target - root of system to be included # target - root of system to be included
inputBox "$wizardname" "root of filesystem for burn:" inputBox "$wizardname" "root of filesystem for burn:"
[ $? = 1 ] && return [ $? = 1 ] && return
target="target = $REPLY" target="target = $REPLY"
# excludes # excludes
formBegin "$wizardname: excludes" formBegin "$wizardname: excludes"
for ((i=0; i < ${#makecd_excludes[@]} ; i++)); do for ((i=0; i < ${#makecd_excludes[@]} ; i++)); do
formItem exclude ${makecd_excludes[$i]} formItem exclude ${makecd_excludes[$i]}
done done
formItem exclude formItem exclude
formItem exclude formItem exclude
formItem exclude formItem exclude
formItem exclude formItem exclude
formItem exclude formItem exclude
formItem exclude formItem exclude
formItem exclude formItem exclude
formItem exclude formItem exclude
formItem exclude formItem exclude
formDisplay formDisplay
[ $? = 1 ] && return; [ $? = 1 ] && return;
unset makecd_excludes unset makecd_excludes
makecd_excludes=($REPLY) makecd_excludes=($REPLY)
get_next_filename $configdirectory/20.makecd get_next_filename $configdirectory/20.makecd
cat >> $next_filename <<EOF cat >> $next_filename <<EOF
# TYP is cd or dvd AS WELL AS the disk inside!! # TYP is cd or dvd AS WELL AS the disk inside!!
$burnertype $burnertype
@ -88,10 +88,10 @@ $target
# exclude = /dev # exclude = /dev
EOF EOF
for ((j=0; j < ${#makecd_excludes[@]} ; j++)); do for ((j=0; j < ${#makecd_excludes[@]} ; j++)); do
echo "exclude = ${makecd_excludes[$j]}" >> $next_filename echo "exclude = ${makecd_excludes[$j]}" >> $next_filename
done done
chmod 600 $next_filename chmod 600 $next_filename
} }

View File

@ -31,7 +31,7 @@ DVDINFO="/usr/bin/dvd+rw-mediainfo"
[ -x "$CDRDAO" ] || debug 3 "echo executable $CDRDAO not present" [ -x "$CDRDAO" ] || debug 3 "echo executable $CDRDAO not present"
if [ "$isoonly" == "no" ]; then if [ "$isoonly" == "no" ]; then
[ -e $device ] || fatal "No Burner device available" [ -e $device ] || fatal "No Burner device available"
fi fi
outputfile="$backupdir/$imagefile" outputfile="$backupdir/$imagefile"
@ -40,7 +40,7 @@ execstr="nice -n $nicelevel $MKISOFS --quiet -R -o $outputfile "
str="" str=""
# excludes # excludes
for i in $exclude; do for i in $exclude; do
str=" -x ${i}$str" str=" -x ${i}$str"
done done
debug 0 "echo $str " debug 0 "echo $str "
@ -50,39 +50,39 @@ debug 0 "echo $execstr "
output=` $execstr 2>&1 ` output=` $execstr 2>&1 `
code=$? code=$?
if [ "$code" == "0" ]; then if [ "$code" == "0" ]; then
debug $output debug $output
info "Successfully finished creation of iso" info "Successfully finished creation of iso"
else else
warning $output warning $output
warning "Failed to create iso" warning "Failed to create iso"
fi fi
if [ "$isoonly" == "no" ]; then if [ "$isoonly" == "no" ]; then
if [ "$burnertype" == "cd" ]; then if [ "$burnertype" == "cd" ]; then
# burning iso to CD # burning iso to CD
$CDRECORD -v gracetime=2 dev=$device speed=8 -dao -data $outputfile $CDRECORD -v gracetime=2 dev=$device speed=8 -dao -data $outputfile
code=$? code=$?
if [ "$code" == "0" ]; then if [ "$code" == "0" ]; then
debug $output debug $output
info "Successfully burned CD" info "Successfully burned CD"
else else
warning $output warning $output
warning "Failed to create CD" warning "Failed to create CD"
fi fi
fi fi
if [ "$burnertype" == "dvd" ]; then if [ "$burnertype" == "dvd" ]; then
# burning iso dvd # burning iso dvd
$GROWISOFS -speed=2 -Z $device=$outputfile -use-the-force-luke=notray -use-the-force-luke=tty $GROWISOFS -speed=2 -Z $device=$outputfile -use-the-force-luke=notray -use-the-force-luke=tty
code=$? code=$?
if [ "$code" == "0" ]; then if [ "$code" == "0" ]; then
debug $output debug $output
info "Successfully burned DVD" info "Successfully burned DVD"
else else
warning $output warning $output
warning "Failed to create DVD" warning "Failed to create DVD"
fi fi
fi fi
fi fi
return 0 return 0

View File

@ -13,43 +13,43 @@ do_mysql_databases() {
while [ -z "$REPLY" ]; do while [ -z "$REPLY" ]; do
formBegin "$mysql_title: databases" formBegin "$mysql_title: databases"
formItem "Database:" formItem "Database:"
formItem "Database:" formItem "Database:"
formItem "Database:" formItem "Database:"
formItem "Database:" formItem "Database:"
formItem "Database:" formItem "Database:"
formItem "Database:" formItem "Database:"
formItem "Database:" formItem "Database:"
formItem "Database:" formItem "Database:"
formItem "Database:" formItem "Database:"
formItem "Database:" formItem "Database:"
formDisplay formDisplay
[ $? = 0 ] || return 1 [ $? = 0 ] || return 1
mysql_databases="databases = " mysql_databases="databases = "
for i in $REPLY; do for i in $REPLY; do
[ -n "$i" ] && mysql_databases="$mysql_databases $i" [ -n "$i" ] && mysql_databases="$mysql_databases $i"
done done
done done
} }
do_mysql_password() { do_mysql_password() {
inputBox "$mysql_title" "specify a mysql user:" inputBox "$mysql_title" "specify a mysql user:"
[ $? = 1 ] && return [ $? = 1 ] && return
user=$REPLY user=$REPLY
inputBox "$mysql_title" "specify the mysql user's password:" inputBox "$mysql_title" "specify the mysql user's password:"
[ $? = 1 ] && return [ $? = 1 ] && return
password=$REPLY password=$REPLY
do_mysql_final "dbusername = $user\ndbpassword = $password" do_mysql_final "dbusername = $user\ndbpassword = $password"
} }
do_mysql_debian() { do_mysql_debian() {
_DISABLE_HOTCOPY=yes _DISABLE_HOTCOPY=yes
do_mysql_final "configfile = /etc/mysql/debian.cnf" do_mysql_final "configfile = /etc/mysql/debian.cnf"
} }
do_mysql_user() { do_mysql_user() {
inputBox "$mysql_title" "what system user does mysql backup use?" inputBox "$mysql_title" "what system user does mysql backup use?"
[ $? = 1 ] && return [ $? = 1 ] && return
do_mysql_final "user = $REPLY" do_mysql_final "user = $REPLY"
} }
do_mysql_final() { do_mysql_final() {
@ -69,18 +69,18 @@ do_mysql_final() {
hotcopy="hotcopy = no" hotcopy="hotcopy = no"
fi fi
[ $status = 1 ] && return; [ $status = 1 ] && return;
result="$REPLY" result="$REPLY"
compress="compress = no" compress="compress = no"
for opt in $result; do for opt in $result; do
case $opt in case $opt in
'"sqldump"') sqldump="sqldump = yes";; '"sqldump"') sqldump="sqldump = yes";;
'"hotcopy"') hotcopy="hotcopy = yes";; '"hotcopy"') hotcopy="hotcopy = yes";;
'"compress"') compress="compress = yes";; '"compress"') compress="compress = yes";;
esac esac
done done
get_next_filename $configdirectory/20.mysql get_next_filename $configdirectory/20.mysql
cat >> $next_filename <<EOF cat >> $next_filename <<EOF
### backupninja MySQL config file ### ### backupninja MySQL config file ###
@ -114,7 +114,7 @@ EOF
$mysql_backupdir $mysql_backupdir
# databases = <all | db1 db2 db3 > (default = all) # databases = <all | db1 db2 db3 > (default = all)
# which databases to backup. should either be the word 'all' or a # which databases to backup. should either be the word 'all' or a
# space separated list of database names. # space separated list of database names.
$mysql_databases $mysql_databases
@ -122,43 +122,43 @@ EOF
if [ $host_or_vservers == vservers ] if [ $host_or_vservers == vservers ]
then then
cat >> $next_filename <<EOF cat >> $next_filename <<EOF
# #
# vsname = <vserver> (no default) # vsname = <vserver> (no default)
# vsname indicates which vserver to operate on, this is only used if # vsname indicates which vserver to operate on, this is only used if
# vserver is set to yes in /etc/backupninja.conf # vserver is set to yes in /etc/backupninja.conf
# NOTE: if you do not specify a vsname the host will be operated on # NOTE: if you do not specify a vsname the host will be operated on
# alsoNOTE: if operating on a vserver, $VROOTDIR will be # alsoNOTE: if operating on a vserver, $VROOTDIR will be
# prepended to backupdir. # prepended to backupdir.
EOF EOF
echo -e "$mysql_vsname\n" >> $next_filename echo -e "$mysql_vsname\n" >> $next_filename
fi fi
echo -e $@ >> $next_filename echo -e $@ >> $next_filename
chmod 600 $next_filename chmod 600 $next_filename
} }
mysql_wizard() { mysql_wizard() {
# Global variables # Global variables
mysql_title="MySQL action wizard" mysql_title="MySQL action wizard"
# backup the host system or a Vserver? # backup the host system or a Vserver?
choose_host_or_one_vserver "$mysql_title" choose_host_or_one_vserver "$mysql_title"
[ $? = 0 ] || return 1 [ $? = 0 ] || return 1
if [ $host_or_vservers == vservers ] if [ $host_or_vservers == vservers ]
then then
do_mysql_vserver do_mysql_vserver
[ $? = 0 ] || return 1 [ $? = 0 ] || return 1
fi fi
# backupdir # backupdir
if [ $host_or_vservers == vservers ] if [ $host_or_vservers == vservers ]
then then
inputBox "$mysql_title" "Directory where to store the backups:`echo \"\n(Relative to chosen vserver's root directory)\"`" "/var/backups/mysql" inputBox "$mysql_title" "Directory where to store the backups:`echo \"\n(Relative to chosen vserver's root directory)\"`" "/var/backups/mysql"
else else
inputBox "$mysql_title" "Directory where to store the backups" "/var/backups/mysql" inputBox "$mysql_title" "Directory where to store the backups" "/var/backups/mysql"
fi fi
[ $? = 1 ] && return [ $? = 1 ] && return
mysql_backupdir="backupdir = $REPLY" mysql_backupdir="backupdir = $REPLY"
@ -171,23 +171,23 @@ mysql_wizard() {
do_mysql_databases do_mysql_databases
[ $? = 0 ] || return 1 [ $? = 0 ] || return 1
fi fi
while true; do while true; do
_DISABLE_HOTCOPY= _DISABLE_HOTCOPY=
menuBoxHelpFile "$mysql_title" "choose a mysql authentication method:" \ menuBoxHelpFile "$mysql_title" "choose a mysql authentication method:" \
user "change to a linux user first." \ user "change to a linux user first." \
password "manually specify mysql user and password." \ password "manually specify mysql user and password." \
debian "use default mysql user debian-sys-maint." debian "use default mysql user debian-sys-maint."
status=$? status=$?
if [ $status = 2 ]; then if [ $status = 2 ]; then
# show help. # show help.
helptmp="/tmp/backupninja.help.$$" helptmp="/tmp/backupninja.help.$$"
cat > $helptmp <<EOF cat > $helptmp <<EOF
To connect to mysql, backupninja must authenticate. To connect to mysql, backupninja must authenticate.
There are three possible authentication methods: There are three possible authentication methods:
USER USER
With this method, you specify a system user. Backupninja will With this method, you specify a system user. Backupninja will
then become this user before running mysqldump or mysqlhotcopy. then become this user before running mysqldump or mysqlhotcopy.
The result is that ~/.my.cnf is used for authentication. The result is that ~/.my.cnf is used for authentication.
@ -199,11 +199,11 @@ DEBIAN
With this method, we use the debian-sys-maint user which is With this method, we use the debian-sys-maint user which is
already defined in /etc/mysql/debian.cnf. If you are running already defined in /etc/mysql/debian.cnf. If you are running
debian, this is recommended, because no further configuration debian, this is recommended, because no further configuration
is needed. The drawback is that this is incompatible with is needed. The drawback is that this is incompatible with
mysqlhotcopy: you must use mysqldump. mysqlhotcopy: you must use mysqldump.
EOF EOF
dialog --textbox $helptmp 0 0 dialog --textbox $helptmp 0 0
rm $helptmp rm $helptmp
fi fi
[ $status = 1 ] && return; [ $status = 1 ] && return;
@ -213,5 +213,5 @@ EOF
"password") do_mysql_password;return;; "password") do_mysql_password;return;;
"debian") do_mysql_debian;return;; "debian") do_mysql_debian;return;;
esac esac
done done
} }

View File

@ -47,9 +47,9 @@ fi
ignore='' ignore=''
for i in $ignores $nodata; do 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, $vroot will be empty if no vsname was specified
# 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 $vroot$backupdir ] || mkdir -p $vroot$backupdir
@ -59,11 +59,11 @@ dumpdir="$backupdir/sqldump"
if [ $usevserver = yes ] if [ $usevserver = yes ]
then then
[ "$sqldump" == "no" -o -d $vroot$dumpdir ] || $VSERVER $vsname exec mkdir -p $dumpdir [ "$sqldump" == "no" -o -d $vroot$dumpdir ] || $VSERVER $vsname exec mkdir -p $dumpdir
[ "$hotcopy" == "no" -o -d $vroot$hotdir ] || $VSERVER $vsname exec mkdir -p $hotdir [ "$hotcopy" == "no" -o -d $vroot$hotdir ] || $VSERVER $vsname exec mkdir -p $hotdir
else 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 fi
####################################################################### #######################################################################
@ -87,29 +87,29 @@ defaultsfile=""
if [ "$dbusername" != "" -a "$dbpassword" != "" ] if [ "$dbusername" != "" -a "$dbpassword" != "" ]
then then
if [ $usevserver = yes ] if [ $usevserver = yes ]
then then
vhome=`$VSERVER $vsname exec getent passwd "root" | @AWK@ -F: '{print $6}'` vhome=`$VSERVER $vsname exec getent passwd "root" | @AWK@ -F: '{print $6}'`
home="$vroot$vhome" home="$vroot$vhome"
else else
home=`getent passwd "root" | @AWK@ -F: '{print $6}'` home=`getent passwd "root" | @AWK@ -F: '{print $6}'`
fi 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 [ -f $mycnf ] if [ -f $mycnf ]
then then
# rename temporarily # rename temporarily
tmpcnf="$home/my.cnf.disable" tmpcnf="$home/my.cnf.disable"
debug "mv $mycnf $tmpcnf" debug "mv $mycnf $tmpcnf"
mv $mycnf $tmpcnf mv $mycnf $tmpcnf
fi fi
oldmask=`umask` oldmask=`umask`
umask 077 umask 077
cat > $mycnf <<EOF cat > $mycnf <<EOF
# auto generated backupninja mysql conf # auto generated backupninja mysql conf
[mysql] [mysql]
host=$dbhost host=$dbhost
@ -126,41 +126,41 @@ host=$dbhost
user=$dbusername user=$dbusername
password="$dbpassword" password="$dbpassword"
EOF EOF
umask $oldmask umask $oldmask
if [ $usevserver = yes ] if [ $usevserver = yes ]
then then
defaultsfile="--defaults-extra-file=$vhome/.my.cnf" defaultsfile="--defaults-extra-file=$vhome/.my.cnf"
else else
defaultsfile="--defaults-extra-file=$mycnf" defaultsfile="--defaults-extra-file=$mycnf"
fi fi
fi fi
# if a user is not set, use $configfile, otherwise use $mycnf # if a user is not set, use $configfile, otherwise use $mycnf
if [ "$user" == "" ]; then if [ "$user" == "" ]; then
user=root; user=root;
defaultsfile="--defaults-extra-file=$configfile" defaultsfile="--defaults-extra-file=$configfile"
else else
userset=true; userset=true;
if [ $usevserver = yes ] if [ $usevserver = yes ]
then then
vuserhome=`$VSERVER $vsname exec getent passwd "$user" | @AWK@ -F: '{print $6}'` vuserhome=`$VSERVER $vsname exec getent passwd "$user" | @AWK@ -F: '{print $6}'`
if [ $? -eq 2 ] if [ $? -eq 2 ]
then then
fatal "User $user not found in /etc/passwd" fatal "User $user not found in /etc/passwd"
fi fi
userhome="$vroot$vuserhome" userhome="$vroot$vuserhome"
else else
userhome=`getent passwd "$user" | @AWK@ -F: '{print $6}'` userhome=`getent passwd "$user" | @AWK@ -F: '{print $6}'`
if [ $? -eq 2 ] if [ $? -eq 2 ]
then then
fatal "User $user not found in /etc/passwd" fatal "User $user not found in /etc/passwd"
fi fi
fi fi
debug "User home set to: $userhome" debug "User home set to: $userhome"
[ -f $userhome/.my.cnf ] || fatal "Can't find config file in $userhome/.my.cnf" [ -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"
fi fi
####################################################################### #######################################################################
@ -168,55 +168,55 @@ fi
if [ "$hotcopy" == "yes" ] if [ "$hotcopy" == "yes" ]
then then
info "Initializing hotcopy method" info "Initializing hotcopy method"
if [ "$databases" == "all" ] if [ "$databases" == "all" ]
then then
if [ $usevserver = yes ] if [ $usevserver = yes ]
then then
info "dbhost: $dbhost" info "dbhost: $dbhost"
execstr="$VSERVER $vsname exec $MYSQLHOTCOPY -h $dbhost --quiet --allowold --regexp /.\*/./.\*/ $hotdir" execstr="$VSERVER $vsname exec $MYSQLHOTCOPY -h $dbhost --quiet --allowold --regexp /.\*/./.\*/ $hotdir"
else else
execstr="$MYSQLHOTCOPY --quiet --allowold --regexp /.\*/./.\*/ $hotdir" execstr="$MYSQLHOTCOPY --quiet --allowold --regexp /.\*/./.\*/ $hotdir"
fi fi
debug "su $user -c \"$execstr\"" debug "su $user -c \"$execstr\""
if [ ! $test ] if [ ! $test ]
then then
output=`su $user -c "$execstr" 2>&1` output=`su $user -c "$execstr" 2>&1`
code=$? code=$?
if [ "$code" == "0" ] if [ "$code" == "0" ]
then then
debug $output debug $output
info "Successfully finished hotcopy of all mysql databases" info "Successfully finished hotcopy of all mysql databases"
else else
warning $output warning $output
warning "Failed to hotcopy all mysql databases" warning "Failed to hotcopy all mysql databases"
fi fi
fi fi
else else
for db in $databases for db in $databases
do do
if [ $usevserver = yes ] if [ $usevserver = yes ]
then then
execstr="$VSERVER $vsname exec $MYSQLHOTCOPY --allowold $db $hotdir" execstr="$VSERVER $vsname exec $MYSQLHOTCOPY --allowold $db $hotdir"
else else
execstr="$MYSQLHOTCOPY --allowold $db $hotdir" execstr="$MYSQLHOTCOPY --allowold $db $hotdir"
fi fi
debug 'su $user -c \"$execstr\"' debug 'su $user -c \"$execstr\"'
if [ ! $test ] if [ ! $test ]
then then
output=`su $user -c "$execstr" 2>&1` output=`su $user -c "$execstr" 2>&1`
code=$? code=$?
if [ "$code" == "0" ] if [ "$code" == "0" ]
then then
debug $output debug $output
info "Successfully finished hotcopy of mysql database $db" info "Successfully finished hotcopy of mysql database $db"
else else
warning $output warning $output
warning "Failed to hotcopy mysql database $db" warning "Failed to hotcopy mysql database $db"
fi fi
fi fi
done done
fi fi
fi fi
########################################################################## ##########################################################################
@ -224,97 +224,97 @@ fi
if [ "$sqldump" == "yes" ] if [ "$sqldump" == "yes" ]
then then
info "Initializing SQL dump method" info "Initializing SQL dump method"
if [ "$databases" == "all" ] if [ "$databases" == "all" ]
then then
if [ $usevserver = yes ] if [ $usevserver = yes ]
then then
debug 'echo show databases | $VSERVER $vsname exec su $user -c \"$MYSQL $defaultsfile\" | grep -v Database' debug 'echo show databases | $VSERVER $vsname exec su $user -c \"$MYSQL $defaultsfile\" | grep -v Database'
databases=`echo 'show databases' | $VSERVER $vsname exec su $user -c "$MYSQL $defaultsfile" | grep -v Database` databases=`echo 'show databases' | $VSERVER $vsname exec su $user -c "$MYSQL $defaultsfile" | grep -v Database`
if [ $? -ne 0 ] if [ $? -ne 0 ]
then then
fatal "Authentication problem, maybe user/password is wrong or mysqld is not running?" fatal "Authentication problem, maybe user/password is wrong or mysqld is not running?"
fi fi
else else
databases=$(su $user -c "$MYSQL $defaultsfile -N -B -e 'show databases'" | sed 's/|//g;/\+----/d') databases=$(su $user -c "$MYSQL $defaultsfile -N -B -e 'show databases'" | sed 's/|//g;/\+----/d')
if [ $? -ne 0 ] if [ $? -ne 0 ]
then then
fatal "Authentication problem, maybe user/password is wrong or mysqld is not running?" fatal "Authentication problem, maybe user/password is wrong or mysqld is not running?"
fi fi
fi fi
fi fi
for db in $databases for db in $databases
do do
DUMP_BASE="$MYSQLDUMP $defaultsfile $sqldumpoptions" DUMP_BASE="$MYSQLDUMP $defaultsfile $sqldumpoptions"
# Dumping structure and data # Dumping structure and data
DUMP="$DUMP_BASE $ignore $db" DUMP="$DUMP_BASE $ignore $db"
# If requested, dump only the table structure for this database # If requested, dump only the table structure for this database
if echo "$nodata" | grep -E '(^|[[:space:]])'"$db\." >/dev/null if echo "$nodata" | grep -E '(^|[[:space:]])'"$db\." >/dev/null
then then
# Get the structure of the tables, without data # Get the structure of the tables, without data
DUMP_STRUCT="$DUMP_BASE --no-data $db" DUMP_STRUCT="$DUMP_BASE --no-data $db"
for qualified_table in $nodata for qualified_table in $nodata
do do
table=$( expr match "$qualified_table" "$db\.\([^\w]*\)" ) table=$( expr match "$qualified_table" "$db\.\([^\w]*\)" )
DUMP_STRUCT="$DUMP_STRUCT $table" DUMP_STRUCT="$DUMP_STRUCT $table"
done done
DUMP="( $DUMP; $DUMP_STRUCT )" DUMP="( $DUMP; $DUMP_STRUCT )"
fi fi
if [ $usevserver = yes ] if [ $usevserver = yes ]
then 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
$VSERVER $vsname exec 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="$VSERVER $vsname exec $DUMP | $GZIP > $vroot$dumpdir/${db}.sql.gz" execstr="$VSERVER $vsname exec $DUMP | $GZIP > $vroot$dumpdir/${db}.sql.gz"
else else
execstr="$VSERVER $vsname exec $DUMP -r $vroot$dumpdir/${db}.sql" execstr="$VSERVER $vsname exec $DUMP -r $vroot$dumpdir/${db}.sql"
fi fi
else else
# 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" 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 > $dumpdir/${db}.sql.gz" execstr="$DUMP | $GZIP > $dumpdir/${db}.sql.gz"
else else
execstr="$DUMP -r $dumpdir/${db}.sql" execstr="$DUMP -r $dumpdir/${db}.sql"
fi fi
fi fi
debug "su $user -c \"$execstr\"" debug "su $user -c \"$execstr\""
if [ ! $test ] if [ ! $test ]
then then
output=`su $user -c "$execstr" 2>&1` output=`su $user -c "$execstr" 2>&1`
code=$? code=$?
if [ "$code" == "0" ] if [ "$code" == "0" ]
then then
debug $output debug $output
info "Successfully finished dump of mysql database $db" info "Successfully finished dump of mysql database $db"
else else
warning $output warning $output
warning "Failed to dump mysql databases $db" warning "Failed to dump mysql databases $db"
fi fi
fi fi
done done
fi fi
# clean up tmp config file # clean up tmp config file
if [ "$dbusername" != "" -a "$dbpassword" != "" ] if [ "$dbusername" != "" -a "$dbpassword" != "" ]
then then
## clean up tmp config file ## clean up tmp config file
debug "rm $mycnf" debug "rm $mycnf"
rm $mycnf rm $mycnf
if [ -f "$tmpcnf" ] if [ -f "$tmpcnf" ]
then then
debug "mv $tmpcnf $mycnf" debug "mv $tmpcnf $mycnf"
mv $tmpcnf $mycnf mv $tmpcnf $mycnf
fi fi
fi fi
return 0 return 0

View File

@ -13,20 +13,20 @@ do_pgsql_databases() {
while [ -z "$REPLY" ]; do while [ -z "$REPLY" ]; do
formBegin "$pgsql_title: databases" formBegin "$pgsql_title: databases"
formItem "Database:" formItem "Database:"
formItem "Database:" formItem "Database:"
formItem "Database:" formItem "Database:"
formItem "Database:" formItem "Database:"
formItem "Database:" formItem "Database:"
formItem "Database:" formItem "Database:"
formItem "Database:" formItem "Database:"
formItem "Database:" formItem "Database:"
formItem "Database:" formItem "Database:"
formItem "Database:" formItem "Database:"
formDisplay formDisplay
[ $? = 0 ] || return 1 [ $? = 0 ] || return 1
pgsql_databases="databases = " pgsql_databases="databases = "
for i in $REPLY; do for i in $REPLY; do
[ -n "$i" ] && pgsql_databases="$pgsql_databases $i" [ -n "$i" ] && pgsql_databases="$pgsql_databases $i"
done done
done done
} }
@ -86,14 +86,14 @@ EOF
$pgsql_backupdir $pgsql_backupdir
# databases = < all | db1 db2 db3 > (default = all) # databases = < all | db1 db2 db3 > (default = all)
# which databases to backup. should either be the word 'all' or a # which databases to backup. should either be the word 'all' or a
# space separated list of database names. # space separated list of database names.
# Note: when using 'all', pg_dumpall is used instead of pg_dump, which means # Note: when using 'all', pg_dumpall is used instead of pg_dump, which means
# that cluster-wide data (such as users and groups) are saved. # that cluster-wide data (such as users and groups) are saved.
$pgsql_databases $pgsql_databases
# compress = < yes | no > (default = yes) # compress = < yes | no > (default = yes)
# if yes, compress the pg_dump/pg_dumpall output. # if yes, compress the pg_dump/pg_dumpall output.
$pgsql_compress $pgsql_compress
### You can also set the following variables in backupninja.conf: ### You can also set the following variables in backupninja.conf:

View File

@ -36,18 +36,18 @@ if [ $usevserver = yes ]; then
debug "Examining vserver '$vsname'." debug "Examining vserver '$vsname'."
if [ "$databases" == "all" ]; then if [ "$databases" == "all" ]; then
[ -x "$vroot`$VSERVER $vsname exec which $PGSQLDUMPALL`" ] || \ [ -x "$vroot`$VSERVER $vsname exec which $PGSQLDUMPALL`" ] || \
fatal "Can't find $PGSQLDUMPALL in vserver $vsname." fatal "Can't find $PGSQLDUMPALL in vserver $vsname."
else else
[ -x "$vroot`$VSERVER $vsname exec which $PGSQLDUMP`" ] || \ [ -x "$vroot`$VSERVER $vsname exec which $PGSQLDUMP`" ] || \
fatal "Can't find $PGSQLDUMP in vserver $vsname." fatal "Can't find $PGSQLDUMP in vserver $vsname."
fi fi
else else
if [ "$databases" == "all" ]; then if [ "$databases" == "all" ]; then
[ -x "`which $PGSQLDUMPALL`" ] || \ [ -x "`which $PGSQLDUMPALL`" ] || \
fatal "Can't find $PGSQLDUMPALL." fatal "Can't find $PGSQLDUMPALL."
else else
[ -x "`which $PGSQLDUMP`" ] || \ [ -x "`which $PGSQLDUMP`" ] || \
fatal "Can't find $PGSQLDUMP." fatal "Can't find $PGSQLDUMP."
fi fi
fi fi
@ -64,7 +64,7 @@ else
pguid=`getent passwd $PGSQLUSER | @AWK@ -F: '{print $3}'` pguid=`getent passwd $PGSQLUSER | @AWK@ -F: '{print $3}'`
fi fi
[ -n "$pguid" ] || \ [ -n "$pguid" ] || \
fatal "No user called $PGSQLUSER`[ $usevserver = no ] || echo \" on vserver $vsname\"`." fatal "No user called $PGSQLUSER`[ $usevserver = no ] || echo \" on vserver $vsname\"`."
debug "chown $pguid $vroot$backupdir" debug "chown $pguid $vroot$backupdir"
chown $pguid $vroot$backupdir chown $pguid $vroot$backupdir
debug "chmod 700 $vroot$backupdir" debug "chmod 700 $vroot$backupdir"
@ -72,61 +72,61 @@ chmod 700 $vroot$backupdir
# 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 [ $usevserver = yes ]; then
if [ "$compress" == "yes" ]; then if [ "$compress" == "yes" ]; then
execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMPALL | $GZIP > $backupdir/${vsname}.sql.gz\"" execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMPALL | $GZIP > $backupdir/${vsname}.sql.gz\""
else else
execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMPALL > $backupdir/${vsname}.sql\"" execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMPALL > $backupdir/${vsname}.sql\""
fi fi
else else
if [ "$compress" == "yes" ]; then if [ "$compress" == "yes" ]; then
execstr="su - $PGSQLUSER -c \"$PGSQLDUMPALL | $GZIP > $backupdir/${localhost}-all.sql.gz\"" execstr="su - $PGSQLUSER -c \"$PGSQLDUMPALL | $GZIP > $backupdir/${localhost}-all.sql.gz\""
else else
execstr="su - $PGSQLUSER -c \"$PGSQLDUMPALL > $backupdir/${localhost}-all.sql\"" execstr="su - $PGSQLUSER -c \"$PGSQLDUMPALL > $backupdir/${localhost}-all.sql\""
fi fi
fi fi
debug "$execstr" debug "$execstr"
if [ ! $test ]; then if [ ! $test ]; then
output=`eval $execstr 2>&1` output=`eval $execstr 2>&1`
code=$? code=$?
if [ "$code" == "0" ]; then if [ "$code" == "0" ]; then
debug $output debug $output
info "Successfully finished dump of pgsql cluster" info "Successfully finished dump of pgsql cluster"
else else
warning $output warning $output
warning "Failed to dump pgsql cluster" warning "Failed to dump pgsql cluster"
fi fi
fi fi
# else use pg_dump on each specified database # else use pg_dump on each specified database
else else
for db in $databases; do for db in $databases; do
if [ $usevserver = yes ]; then if [ $usevserver = yes ]; then
if [ "$compress" == "yes" ]; then if [ "$compress" == "yes" ]; then
execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMP $db | $GZIP > $backupdir/${db}.sql.gz\"" execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMP $db | $GZIP > $backupdir/${db}.sql.gz\""
else else
execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMP $db | > $backupdir/${db}.sql\"" execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMP $db | > $backupdir/${db}.sql\""
fi fi
else else
if [ "$compress" == "yes" ]; then if [ "$compress" == "yes" ]; then
execstr="su - $PGSQLUSER -c \"$PGSQLDUMP $db | $GZIP > $backupdir/${db}.sql.gz\"" execstr="su - $PGSQLUSER -c \"$PGSQLDUMP $db | $GZIP > $backupdir/${db}.sql.gz\""
else else
execstr="su - $PGSQLUSER -c \"$PGSQLDUMP $db > $backupdir/${db}.sql\"" execstr="su - $PGSQLUSER -c \"$PGSQLDUMP $db > $backupdir/${db}.sql\""
fi fi
fi fi
debug "$execstr" debug "$execstr"
if [ ! $test ]; then if [ ! $test ]; then
output=`eval $execstr 2>&1` output=`eval $execstr 2>&1`
code=$? code=$?
if [ "$code" == "0" ]; then if [ "$code" == "0" ]; then
debug $output debug $output
info "Successfully finished dump of pgsql database ${db}" info "Successfully finished dump of pgsql database ${db}"
else else
warning $output warning $output
warning "Failed to dump pgsql database ${db}" warning "Failed to dump pgsql database ${db}"
fi fi
fi fi
done done
fi fi
return 0 return 0

View File

@ -18,9 +18,9 @@ do_rdiff_host_includes() {
for ((i=0; i < ${#rdiff_includes[@]} ; i++)); do for ((i=0; i < ${#rdiff_includes[@]} ; i++)); do
formItem include ${rdiff_includes[$i]} formItem include ${rdiff_includes[$i]}
done done
formItem include formItem include
formItem include formItem include
formItem include formItem include
formDisplay formDisplay
[ $? = 0 ] || return [ $? = 0 ] || return
unset rdiff_includes unset rdiff_includes
@ -41,7 +41,7 @@ do_rdiff_vserver() {
while [ -z "$REPLY" ]; do while [ -z "$REPLY" ]; do
formBegin "$rdiff_title - vsincludes (backup these directories from every vserver)" formBegin "$rdiff_title - vsincludes (backup these directories from every vserver)"
[ -z "$rdiff_vsincludes" ] && rdiff_vsincludes="$rdiff_default_includes" [ -z "$rdiff_vsincludes" ] && rdiff_vsincludes="$rdiff_default_includes"
for i in $rdiff_vsincludes; do for i in $rdiff_vsincludes; do
formItem include "$i" formItem include "$i"
done done
@ -52,19 +52,19 @@ do_rdiff_vserver() {
[ $? = 0 ] || return 1 [ $? = 0 ] || return 1
rdiff_vsincludes=($REPLY) rdiff_vsincludes=($REPLY)
done done
set +o noglob set +o noglob
} }
do_rdiff_excludes() { do_rdiff_excludes() {
set -o noglob set -o noglob
formBegin "$rdiff_title: excludes" formBegin "$rdiff_title: excludes"
for ((i=0; i < ${#rdiff_excludes[@]} ; i++)) for ((i=0; i < ${#rdiff_excludes[@]} ; i++))
do do
formItem exclude ${rdiff_excludes[$i]} formItem exclude ${rdiff_excludes[$i]}
done done
formItem exclude formItem exclude
formItem exclude formItem exclude
formDisplay formDisplay
[ $? = 0 ] || return [ $? = 0 ] || return
unset rdiff_excludes unset rdiff_excludes
@ -102,10 +102,10 @@ do_rdiff_src() {
do_rdiff_dest() { do_rdiff_dest() {
declare -a tmp_array declare -a tmp_array
set -o noglob set -o noglob
REPLY= REPLY=
while [ -z "$REPLY" -o -z "$rdiff_directory" -o -z "$rdiff_host" -o -z "$rdiff_user" ] while [ -z "$REPLY" -o -z "$rdiff_directory" -o -z "$rdiff_host" -o -z "$rdiff_user" ]
do do
formBegin "$rdiff_title - destination: last three items are required" formBegin "$rdiff_title - destination: last three items are required"
formItem "keep" "$rdiff_keep" formItem "keep" "$rdiff_keep"
@ -119,11 +119,11 @@ do_rdiff_dest() {
rdiff_keep=${tmp_array[0]} rdiff_keep=${tmp_array[0]}
rdiff_directory=${tmp_array[1]} rdiff_directory=${tmp_array[1]}
rdiff_host=${tmp_array[2]} rdiff_host=${tmp_array[2]}
rdiff_user=${tmp_array[3]} rdiff_user=${tmp_array[3]}
rdiff_type=${tmp_array[4]} rdiff_type=${tmp_array[4]}
done done
set +o noglob set +o noglob
_dest_done="(DONE)" _dest_done="(DONE)"
setDefault conn setDefault conn
} }
@ -155,7 +155,7 @@ do_rdiff_ssh_con() {
echo "Done. hit return to continue" echo "Done. hit return to continue"
read read
fi fi
ssh -o PreferredAuthentications=publickey $rdiff_host -l $rdiff_user "exit" 2> /dev/null ssh -o PreferredAuthentications=publickey $rdiff_host -l $rdiff_user "exit" 2> /dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Copying root's public ssh key to authorized_keys of $rdiff_user@$rdiff_host. When prompted, specify the password for user $rdiff_user@$rdiff_host." echo "Copying root's public ssh key to authorized_keys of $rdiff_user@$rdiff_host. When prompted, specify the password for user $rdiff_user@$rdiff_host."
@ -171,7 +171,7 @@ do_rdiff_ssh_con() {
1 ) msgBox "$rdiff_title: error" "Connected successfully to $rdiff_user@$rdiff_host, but unable to write. Check ownership and modes of ~$rdiff_user on $rdiff_host." ;; 1 ) msgBox "$rdiff_title: error" "Connected successfully to $rdiff_user@$rdiff_host, but unable to write. Check ownership and modes of ~$rdiff_user on $rdiff_host." ;;
255 ) msgBox "$rdiff_title: error" "Failed to connect to $rdiff_user@$rdiff_host. Check hostname, username, and password. Also, make sure sshd is running on the destination host." ;; 255 ) msgBox "$rdiff_title: error" "Failed to connect to $rdiff_user@$rdiff_host. Check hostname, username, and password. Also, make sure sshd is running on the destination host." ;;
* ) msgBox "$rdiff_title: error" "Unexpected error." ;; * ) msgBox "$rdiff_title: error" "Unexpected error." ;;
esac esac
return return
else else
echo "Done. hit return to continue" echo "Done. hit return to continue"
@ -195,20 +195,20 @@ do_rdiff_ssh_con() {
else else
booleanBox "Remote directory does not exist" "The destination backup directory does not exist, do you want me to create it for you?" booleanBox "Remote directory does not exist" "The destination backup directory does not exist, do you want me to create it for you?"
if [ $? = 0 ]; then if [ $? = 0 ]; then
ssh $rdiff_user@$rdiff_host "mkdir -p ${rdiff_directory}" ssh $rdiff_user@$rdiff_host "mkdir -p ${rdiff_directory}"
result=$? result=$?
case $result in case $result in
0) msgBox "$rdiff_title: success" "Creation of the remote destination directory was a success!";; 0) msgBox "$rdiff_title: success" "Creation of the remote destination directory was a success!";;
1) msgBox "$rdiff_title: error" "Connected successfully to $rdiff_user@$rdiff_host, but was unable to create the destination directory, check the directory permissions." 1) msgBox "$rdiff_title: error" "Connected successfully to $rdiff_user@$rdiff_host, but was unable to create the destination directory, check the directory permissions."
remote_status=failed;; remote_status=failed;;
255) msgBox "$rdiff_title: error" "Failed to connect to $rdiff_user@$rdiff_host. Check hostname, username, and password. Also, make sure sshd is running on the destination host." 255) msgBox "$rdiff_title: error" "Failed to connect to $rdiff_user@$rdiff_host. Check hostname, username, and password. Also, make sure sshd is running on the destination host."
remote_status=failed;; remote_status=failed;;
*) msgBox "$rdiff_title: error" "Unexpected error." *) msgBox "$rdiff_title: error" "Unexpected error."
remote_status=failed;; remote_status=failed;;
esac esac
fi fi
fi fi
if [ "$remote_status" = "ok" ]; then if [ "$remote_status" = "ok" ]; then
do_rdiff_con do_rdiff_con
fi fi
@ -231,12 +231,12 @@ do_rdiff_con() {
echo "Hit return to continue." echo "Hit return to continue."
read read
case $result in case $result in
0) msgBox "$rdiff_title: success" "Installation of rdiff-backup was a success!" 0) msgBox "$rdiff_title: success" "Installation of rdiff-backup was a success!"
do_rdiff_con;; do_rdiff_con;;
1) msgBox "$rdiff_title: error" "Connected successfully to $rdiff_user@$rdiff_host, but was unable to install the package for some reason.";; 1) msgBox "$rdiff_title: error" "Connected successfully to $rdiff_user@$rdiff_host, but was unable to install the package for some reason.";;
255) msgBox "$rdiff_title: error" "Failed to connect to $rdiff_user@$rdiff_host. Check hostname, username, and password. Also, make sure sshd is running on the destination host.";; 255) msgBox "$rdiff_title: error" "Failed to connect to $rdiff_user@$rdiff_host. Check hostname, username, and password. Also, make sure sshd is running on the destination host.";;
*) msgBox "$rdiff_title: error" "Unexpected error.";; *) msgBox "$rdiff_title: error" "Unexpected error.";;
esac esac
return return
fi fi
else else
@ -256,9 +256,9 @@ do_rdiff_con() {
fi fi
fi fi
else else
echo "SUCCESS: Everything looks good!" echo "SUCCESS: Everything looks good!"
echo "Hit return to continue." echo "Hit return to continue."
read read
fi fi
_con_done="(DONE)" _con_done="(DONE)"
@ -298,11 +298,11 @@ EOF
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 fi
if [ "$host_or_vservers" == vservers -o "$host_or_vservers" == both ]; then if [ "$host_or_vservers" == vservers -o "$host_or_vservers" == both ]; then
cat >> $next_filename <<EOF cat >> $next_filename <<EOF
# #
# If vservers = yes in /etc/backupninja.conf then the following variables can # If vservers = yes in /etc/backupninja.conf then the following variables can
@ -328,7 +328,7 @@ EOF
done done
set +o noglob set +o noglob
fi fi
## excludes ## ## excludes ##
set -o noglob set -o noglob
for ((i=0; i < ${#rdiff_excludes[@]} ; i++)); do for ((i=0; i < ${#rdiff_excludes[@]} ; i++)); do
@ -340,7 +340,7 @@ EOF
###################################################### ######################################################
## destination section ## destination section
## (where the files are copied to) ## (where the files are copied to)
[dest] [dest]
type = remote type = remote
directory = $rdiff_directory directory = $rdiff_directory
@ -382,7 +382,7 @@ rdiff_main_menu() {
} }
rdiff_wizard() { rdiff_wizard() {
# Global variables # Global variables
rdiff_title="rdiff-backup action wizard" rdiff_title="rdiff-backup action wizard"
_src_done= _src_done=
@ -401,7 +401,7 @@ rdiff_wizard() {
rdiff_excludes=(/home/*/.gnupg /home/*/.local/share/Trash /home/*/.Trash /home/*/.thumbnails /home/*/.beagle /home/*/.aMule /home/*/gtk-gnutella-downloads) rdiff_excludes=(/home/*/.gnupg /home/*/.local/share/Trash /home/*/.Trash /home/*/.thumbnails /home/*/.beagle /home/*/.aMule /home/*/gtk-gnutella-downloads)
rdiff_vsincludes= rdiff_vsincludes=
set +o noglob set +o noglob
rdiff_main_menu rdiff_main_menu
} }

View File

@ -7,68 +7,68 @@
### FUNCTIONS ### ### FUNCTIONS ###
function test_connection() { function test_connection() {
# given a user and host, # given a user and host,
# tests the connection. # tests the connection.
# if user or host is missing, returns 0 # if user or host is missing, returns 0
# (ie, assume it's a local connection). # (ie, assume it's a local connection).
if [ $# -lt 2 ]; then if [ $# -lt 2 ]; then
debug "(local is assumed to be a good connection)" debug "(local is assumed to be a good connection)"
return 0 return 0
fi fi
local user=$1 local user=$1
local host=$2 local host=$2
debug "ssh $sshoptions -o PasswordAuthentication=no $host -l $user 'echo -n 1'" debug "ssh $sshoptions -o PasswordAuthentication=no $host -l $user 'echo -n 1'"
local ret=`ssh $sshoptions -o PasswordAuthentication=no $host -l $user 'echo -n host is alive'` local ret=`ssh $sshoptions -o PasswordAuthentication=no $host -l $user 'echo -n host is alive'`
if echo $ret | grep "host is alive"; then if echo $ret | grep "host is alive"; then
debug "Connected to $host as $user successfully" debug "Connected to $host as $user successfully"
else else
fatal "Can't connect to $host as $user." fatal "Can't connect to $host as $user."
fi fi
} }
function get_version() { function get_version() {
# given no arguments, returns the local version. # given no arguments, returns the local version.
# given a user and host, returns the remote version. # given a user and host, returns the remote version.
# if user or host is missing, returns the local version. # if user or host is missing, returns the local version.
if [ "$#" -lt 2 ]; then if [ "$#" -lt 2 ]; then
debug "$RDIFFBACKUP -V" debug "$RDIFFBACKUP -V"
echo `$RDIFFBACKUP -V` echo `$RDIFFBACKUP -V`
else else
local user=$1 local user=$1
local host=$2 local host=$2
debug "ssh $sshoptions $host -l $user '$RDIFFBACKUP -V'" debug "ssh $sshoptions $host -l $user '$RDIFFBACKUP -V'"
echo `ssh $sshoptions $host -l $user "$RDIFFBACKUP -V | grep rdiff-backup"` echo `ssh $sshoptions $host -l $user "$RDIFFBACKUP -V | grep rdiff-backup"`
fi fi
} }
function check_consistency() { function check_consistency() {
local section=$1 local section=$1
local type=$2 local type=$2
local user=$3 local user=$3
local host=$4 local host=$4
if [ "$type" == "local" ]; then if [ "$type" == "local" ]; then
if [ "$user" != "" ]; then if [ "$user" != "" ]; then
warning "User should not be specified for local $section." warning "User should not be specified for local $section."
fi fi
if [ "$host" != "" ]; then if [ "$host" != "" ]; then
warning "Host should not be specified for local $section." warning "Host should not be specified for local $section."
fi fi
fi fi
if [ "$type" == "remote" ]; then if [ "$type" == "remote" ]; then
if [ "$user" == "" ]; then if [ "$user" == "" ]; then
fatal "User must be specified for remote $section." fatal "User must be specified for remote $section."
fi fi
if [ "host" == "" ]; then if [ "host" == "" ]; then
fatal "Host must be specifed for remote $section." fatal "Host must be specifed for remote $section."
fi fi
fi fi
} }
function check_cstream() { function check_cstream() {
local cstream=$1 local cstream=$1
if [ ! -x $cstream ]; then if [ ! -x $cstream ]; then
fatal "Can't find your cstream binary (trying: $cstream). If you use bwlimit you must have cstream installed." fatal "Can't find your cstream binary (trying: $cstream). If you use bwlimit you must have cstream installed."
fi fi
} }
### GET CONFIG ### ### GET CONFIG ###
@ -102,7 +102,7 @@ getconf sshoptions
check_consistency "destination" "$type" "$user" "$host" check_consistency "destination" "$type" "$user" "$host"
if [ -n "$sshoptions" ] && echo $options | grep -qv "remote-schema"; then if [ -n "$sshoptions" ] && echo $options | grep -qv "remote-schema"; then
options="$options --remote-schema 'ssh -C $sshoptions %s rdiff-backup --server'" options="$options --remote-schema 'ssh -C $sshoptions %s rdiff-backup --server'"
fi fi
### CHECK CONFIG ### ### CHECK CONFIG ###
@ -114,7 +114,7 @@ if [ $vservers_are_available = yes ]; then
vsnames="$found_vservers" vsnames="$found_vservers"
else else
if ! vservers_exist "$vsnames" ; then if ! vservers_exist "$vsnames" ; then
fatal "At least one of the vservers listed in vsnames ($vsnames) does not exist." fatal "At least one of the vservers listed in vsnames ($vsnames) does not exist."
fi fi
fi fi
if [ -n "$vsinclude" ]; then if [ -n "$vsinclude" ]; then
@ -128,40 +128,40 @@ fi
# check the connection at the source and destination # check the connection at the source and destination
[ -n "$test" ] || test=0 [ -n "$test" ] || test=0
if [ "$testconnect" = "yes" ] || [ "${test}" -eq 1 ]; then if [ "$testconnect" = "yes" ] || [ "${test}" -eq 1 ]; then
test_connection $sourceuser $sourcehost test_connection $sourceuser $sourcehost
test_connection $destuser $desthost test_connection $destuser $desthost
fi fi
if [ "$ignore_version" != "yes" ]; then if [ "$ignore_version" != "yes" ]; then
# see that rdiff-backup has the same version at the source and destination # see that rdiff-backup has the same version at the source and destination
sourceversion=`get_version $sourceuser $sourcehost` sourceversion=`get_version $sourceuser $sourcehost`
destversion=`get_version $destuser $desthost` destversion=`get_version $destuser $desthost`
if [ "$sourceversion" != "$destversion" ]; then if [ "$sourceversion" != "$destversion" ]; then
fatal "rdiff-backup does not have the same version at the source and at the destination." fatal "rdiff-backup does not have the same version at the source and at the destination."
fi fi
fi fi
# source specific checks # source specific checks
case $sourcetype in case $sourcetype in
remote ) execstr_sourcepart="$sourceuser@$sourcehost::/" ;; remote ) execstr_sourcepart="$sourceuser@$sourcehost::/" ;;
local ) execstr_sourcepart="/" ;; local ) execstr_sourcepart="/" ;;
* ) fatal "sourcetype '$sourcetype' is neither local nor remote" ;; * ) fatal "sourcetype '$sourcetype' is neither local nor remote" ;;
esac esac
# destination specific checks # destination specific checks
[ "$destdir" != "" ] || fatal "Destination directory not set" [ "$destdir" != "" ] || fatal "Destination directory not set"
case $desttype in case $desttype in
remote ) execstr_destpart="$destuser@$desthost::$destdir/$label" ;; remote ) execstr_destpart="$destuser@$desthost::$destdir/$label" ;;
local ) execstr_destpart="$destdir/$label" ;; local ) execstr_destpart="$destdir/$label" ;;
* ) fatal "desttype '$desttype' is neither local nor remote" ;; * ) fatal "desttype '$desttype' is neither local nor remote" ;;
esac esac
### REMOVE OLD BACKUPS ### ### REMOVE OLD BACKUPS ###
if [ "$keep" != yes ]; then if [ "$keep" != yes ]; then
if [ "`echo $keep | tr -d 0-9`" == "" ]; then if [ "`echo $keep | tr -d 0-9`" == "" ]; then
# add D if no other date unit is specified # add D if no other date unit is specified
keep="${keep}D" keep="${keep}D"
fi fi
@ -175,27 +175,27 @@ if [ "$keep" != yes ]; then
if [ $test = 0 ]; then if [ $test = 0 ]; then
output="`su -c "$removestr" 2>&1`" output="`su -c "$removestr" 2>&1`"
if [ $? = 0 ]; then if [ $? = 0 ]; then
debug $output debug $output
info "Removing backups older than $keep days succeeded." info "Removing backups older than $keep days succeeded."
else else
warning $output warning $output
warning "Failed removing backups older than $keep." warning "Failed removing backups older than $keep."
fi fi
fi fi
fi fi
# Add cstream # Add cstream
if [ ! -z $bwlimit ]; then if [ ! -z $bwlimit ]; then
check_cstream $CSTREAM; check_cstream $CSTREAM;
if [ "$desttype" = "remote" ]; then if [ "$desttype" = "remote" ]; then
RDIFFBACKUP="$RDIFFBACKUP --remote-schema 'cstream -t $bwlimit | ssh %s \''rdiff-backup --server\'''" RDIFFBACKUP="$RDIFFBACKUP --remote-schema 'cstream -t $bwlimit | ssh %s \''rdiff-backup --server\'''"
elif [ "$sourcetype" = "remote" ]; then elif [ "$sourcetype" = "remote" ]; then
RDIFFBACKUP="$RDIFFBACKUP --remote-schema 'ssh %s \''rdiff-backup --server\'' | cstream -t $bwlimit'" RDIFFBACKUP="$RDIFFBACKUP --remote-schema 'ssh %s \''rdiff-backup --server\'' | cstream -t $bwlimit'"
else else
fatal "You specified a bandwidth limit but neither your source nor destination types are remote." fatal "You specified a bandwidth limit but neither your source nor destination types are remote."
fi fi
fi fi
### EXECUTE ### ### EXECUTE ###
@ -212,7 +212,7 @@ for i in $exclude; do
str="${i//__star__/*}" str="${i//__star__/*}"
execstr="${execstr}--exclude '$str' " execstr="${execstr}--exclude '$str' "
done done
# includes # includes
for i in $include; do for i in $include; do
[ "$i" != "/" ] || fatal "Sorry, you cannot use 'include = /'" [ "$i" != "/" ] || fatal "Sorry, you cannot use 'include = /'"
str="${i//__star__/*}" str="${i//__star__/*}"
@ -223,10 +223,10 @@ done
if [ $usevserver = yes ]; then if [ $usevserver = yes ]; then
for vserver in $vsnames; do for vserver in $vsnames; do
for vi in $vsinclude; do for vi in $vsinclude; do
str="${vi//__star__/*}" str="${vi//__star__/*}"
str="$VROOTDIR/$vserver$str" str="$VROOTDIR/$vserver$str"
if [ -n "$str" ]; then if [ -n "$str" ]; then
execstr="${execstr}--include '$str' " execstr="${execstr}--include '$str' "
else else
warning "vsinclude statement '${vi//__star__/*}' will be ignored for VServer $vserver. $symlinks_warning" warning "vsinclude statement '${vi//__star__/*}' will be ignored for VServer $vserver. $symlinks_warning"
fi fi
@ -238,20 +238,20 @@ set +o noglob
# exclude everything else # exclude everything else
[ "$include" != "" -o "$vsinclude" != "" ] && execstr="${execstr}--exclude '/*' " [ "$include" != "" -o "$vsinclude" != "" ] && execstr="${execstr}--exclude '/*' "
# include client-part and server-part # include client-part and server-part
execstr="${execstr}$execstr_sourcepart $execstr_destpart" execstr="${execstr}$execstr_sourcepart $execstr_destpart"
debug "$execstr" debug "$execstr"
if [ $test = 0 ]; then if [ $test = 0 ]; then
output=`nice -n $nicelevel su -c "$execstr" 2>&1` output=`nice -n $nicelevel su -c "$execstr" 2>&1`
if [ $? = 0 ]; then if [ $? = 0 ]; then
debug $output debug $output
info "Successfully finished backing up source $label" info "Successfully finished backing up source $label"
else else
warning $output warning $output
warning "Failed backup up source $label" warning "Failed backup up source $label"
fi fi
fi fi
return 0 return 0

View File

@ -102,40 +102,40 @@ getconf service
function rotate { function rotate {
if [[ "$2" < 4 ]]; then if [[ "$2" < 4 ]]; then
error "Rotate: minimum of 4 rotations" error "Rotate: minimum of 4 rotations"
exit 1 exit 1
fi fi
if [ -d $1.$2 ]; then if [ -d $1.$2 ]; then
$nice $mv /$1.$2 /$1.tmp $nice $mv /$1.$2 /$1.tmp
fi fi
for ((n=`echo "$2 - 1" | bc`; n >= 0; n--)); do for ((n=`echo "$2 - 1" | bc`; n >= 0; n--)); do
if [ -d $1.$n ]; then if [ -d $1.$n ]; then
dest=`echo "$n + 1" | bc` dest=`echo "$n + 1" | bc`
$nice $mv /$1.$n /$1.$dest $nice $mv /$1.$n /$1.$dest
$touch /$1.$dest $touch /$1.$dest
fi fi
done done
if [ -d $1.tmp ]; then if [ -d $1.tmp ]; then
$nice $mv /$1.tmp /$1.0 $nice $mv /$1.tmp /$1.0
fi fi
if [ -d $1.1 ]; then if [ -d $1.1 ]; then
$nice $cp -alf /$1.1/. /$1.0 $nice $cp -alf /$1.1/. /$1.0
fi fi
} }
function move_files { function move_files {
ref=$tmp/makesnapshot-mymv-$$; ref=$tmp/makesnapshot-mymv-$$;
$touch -r $1 $ref; $touch -r $1 $ref;
$mv $1 $2; $mv $1 $2;
$touch -r $ref $2; $touch -r $ref $2;
$rm $ref; $rm $ref;
} }
@ -143,54 +143,54 @@ backupdir="$mountpoint/$backupdir"
# does $backupdir exists? # does $backupdir exists?
if [ ! -d "$backupdir" ]; then if [ ! -d "$backupdir" ]; then
error "Backupdir $backupdir does not exist" error "Backupdir $backupdir does not exist"
exit 1 exit 1
fi fi
# setup number of increments # setup number of increments
if [ -z "$days" ]; then if [ -z "$days" ]; then
keep="4" keep="4"
else else
keep="`echo $days - 1 | bc -l`" keep="`echo $days - 1 | bc -l`"
fi fi
# lockfile setup # lockfile setup
if [ ! -z "$lockfile" ]; then if [ ! -z "$lockfile" ]; then
$touch $lockfile || warning "Could not create lockfile $lockfile" $touch $lockfile || warning "Could not create lockfile $lockfile"
fi fi
# nicelevel setup # nicelevel setup
if [ ! -z "$nicelevel" ]; then if [ ! -z "$nicelevel" ]; then
nice="nice -n $nicelevel" nice="nice -n $nicelevel"
else else
nice="" nice=""
fi fi
# connection test # connection test
if [ "$from" == "remote" ] && [ "$testconnect" == "yes" ]; then if [ "$from" == "remote" ] && [ "$testconnect" == "yes" ]; then
debug "$ssh -o PasswordAuthentication=no $user@$host 'echo -n 1'" debug "$ssh -o PasswordAuthentication=no $user@$host 'echo -n 1'"
result=`ssh -o PasswordAuthentication=no $user@$host 'echo -n 1'` result=`ssh -o PasswordAuthentication=no $user@$host 'echo -n 1'`
if [ "$result" != "1" ]; then if [ "$result" != "1" ]; then
fatal "Can't connect to $host as $user." fatal "Can't connect to $host as $user."
else else
debug "Connected to $srchost successfully" debug "Connected to $srchost successfully"
fi fi
fi fi
# rsync options for local sources # rsync options for local sources
if [ "$from" == "local" ]; then if [ "$from" == "local" ]; then
rsync_local_options="$rsync_options" rsync_local_options="$rsync_options"
if [ ! -z "$numericids" ]; then if [ ! -z "$numericids" ]; then
rsync_local_options="$rsync_local_options --numeric-ids " rsync_local_options="$rsync_local_options --numeric-ids "
fi fi
fi fi
@ -198,41 +198,41 @@ fi
if [ "$from" == "remote" ]; then if [ "$from" == "remote" ]; then
rsync_remote_options="$rsync_options --rsync-path=$remote_rsync" rsync_remote_options="$rsync_options --rsync-path=$remote_rsync"
if [ "$compress" == "1" ]; then if [ "$compress" == "1" ]; then
rsync_remote_options="$rsync_remote_options --compress" rsync_remote_options="$rsync_remote_options --compress"
fi fi
if [ ! -z "$bandwidthlimit" ]; then if [ ! -z "$bandwidthlimit" ]; then
rsync_remote_options="$rsync_remote_options --bwlimit=$bandwidthlimit" rsync_remote_options="$rsync_remote_options --bwlimit=$bandwidthlimit"
fi fi
if [ ! -z "$numericids" ]; then if [ ! -z "$numericids" ]; then
rsync_remote_options="$rsync_remote_options --numeric-ids" rsync_remote_options="$rsync_remote_options --numeric-ids"
fi fi
fi fi
# set mv procedure # set mv procedure
if [ $enable_mv_timestamp_bug == "yes" ]; then if [ $enable_mv_timestamp_bug == "yes" ]; then
mv=move_files mv=move_files
fi fi
# set excludes # set excludes
for path in $exclude; do for path in $exclude; do
EXCLUDES="$EXCLUDES --exclude=$path" EXCLUDES="$EXCLUDES --exclude=$path"
done done
# stop services # stop services
if [ ! -z "$service" ]; then if [ ! -z "$service" ]; then
for daemon in $service; do for daemon in $service; do
info "Stopping service $daemon..." info "Stopping service $daemon..."
$initscripts/$daemon stop $initscripts/$daemon stop
done done
fi fi
echo "Starting backup at `date`" >> $log echo "Starting backup at `date`" >> $log
@ -240,110 +240,110 @@ echo "Starting backup at `date`" >> $log
# mount backup destination folder as read-write # mount backup destination folder as read-write
if [ "$read_only" == "1" ] || [ "$read_only" == "yes" ]; then if [ "$read_only" == "1" ] || [ "$read_only" == "yes" ]; then
if [ -d "$mountpoint" ]; then if [ -d "$mountpoint" ]; then
mount -o remount,rw $mountpoint mount -o remount,rw $mountpoint
if (($?)); then if (($?)); then
error "Could not mount $mountpoint" error "Could not mount $mountpoint"
exit 1 exit 1
fi fi
fi fi
fi fi
# add vservers to included folders # add vservers to included folders
if [ "$vservers_are_available" == "yes" ]; then if [ "$vservers_are_available" == "yes" ]; then
# sane permission on backup # sane permission on backup
mkdir -p $backupdir/$VROOTDIR mkdir -p $backupdir/$VROOTDIR
chmod 000 $backupdir/$VROOTDIR chmod 000 $backupdir/$VROOTDIR
for candidate in $found_vservers; do for candidate in $found_vservers; do
candidate="`basename $candidate`" candidate="`basename $candidate`"
found_excluded_vserver="0" found_excluded_vserver="0"
for excluded_vserver in $exclude_vserver; do for excluded_vserver in $exclude_vserver; do
if [ "$excluded_vserver" == "$candidate" ]; then if [ "$excluded_vserver" == "$candidate" ]; then
found_excluded_vserver="1" found_excluded_vserver="1"
break break
fi
done
if [ "$found_excluded_vserver" == "0" ]; then
include="$include $VROOTDIR/$candidate"
fi fi
done done
if [ "$found_excluded_vserver" == "0" ]; then
include="$include $VROOTDIR/$candidate"
fi
done
fi fi
# the backup procedure # the backup procedure
for SECTION in $include; do for SECTION in $include; do
section="`basename $SECTION`" section="`basename $SECTION`"
if [ ! -d "$backupdir/$SECTION/$section.0" ]; then if [ ! -d "$backupdir/$SECTION/$section.0" ]; then
mkdir -p $backupdir/$SECTION/$section.0 mkdir -p $backupdir/$SECTION/$section.0
fi fi
info "Rotating $backupdir/$SECTION/$section..."
echo "Rotating $backupdir/$SECTION/$section..." >> $log
rotate $backupdir/$SECTION/$section $keep
info "Syncing $SECTION on $backupdir/$SECTION/$section.0..."
if [ "$from" == "local" ]; then info "Rotating $backupdir/$SECTION/$section..."
debug $rsync $rsync_local_options $EXCLUDES /$SECTION/ $backupdir/$SECTION/$section.0/ echo "Rotating $backupdir/$SECTION/$section..." >> $log
$nice $rsync $rsync_local_options $EXCLUDES /$SECTION/ $backupdir/$SECTION/$section.0/ >> $log rotate $backupdir/$SECTION/$section $keep
if [ "$?" != "0" ]; then info "Syncing $SECTION on $backupdir/$SECTION/$section.0..."
warning "Rsync error when trying to transfer $SECTION"
fi if [ "$from" == "local" ]; then
elif [ "$from" == "remote" ]; then debug $rsync $rsync_local_options $EXCLUDES /$SECTION/ $backupdir/$SECTION/$section.0/
if [ -z "$user" ] || [ -z "$host" ]; then $nice $rsync $rsync_local_options $EXCLUDES /$SECTION/ $backupdir/$SECTION/$section.0/ >> $log
error "Config file error: either user or host was not specified"
exit 1
else
debug $nice $rsync $rsync_remote_options $EXCLUDES -e "$ssh" $user@$host:/$SECTION/ $backupdir/$SECTION/$section.0
$nice $rsync $rsync_remote_options $EXCLUDES -e "$ssh" $user@$host:/$SECTION/ $backupdir/$SECTION/$section.0 >> $log
if [ "$?" != "0" ]; then if [ "$?" != "0" ]; then
warning "Rsync error when trying to transfer $SECTION" warning "Rsync error when trying to transfer $SECTION"
fi fi
fi elif [ "$from" == "remote" ]; then
else if [ -z "$user" ] || [ -z "$host" ]; then
error "Invalid source $from" error "Config file error: either user or host was not specified"
exit 1 exit 1
fi else
debug $nice $rsync $rsync_remote_options $EXCLUDES -e "$ssh" $user@$host:/$SECTION/ $backupdir/$SECTION/$section.0
$nice $rsync $rsync_remote_options $EXCLUDES -e "$ssh" $user@$host:/$SECTION/ $backupdir/$SECTION/$section.0 >> $log
if [ "$?" != "0" ]; then
warning "Rsync error when trying to transfer $SECTION"
fi
fi
else
error "Invalid source $from"
exit 1
fi
$touch $backupdir/$SECTION/$section.0 $touch $backupdir/$SECTION/$section.0
done done
# remount backup destination as read-only # remount backup destination as read-only
if [ "$read_only" == "1" ] || [ "$read_only" == "yes" ]; then if [ "$read_only" == "1" ] || [ "$read_only" == "yes" ]; then
mount -o remount,ro $mountpoint mount -o remount,ro $mountpoint
fi fi
# check partition for errors # check partition for errors
if [ "$fscheck" == "1" ] || [ "$fscheck" == "yes" ]; then if [ "$fscheck" == "1" ] || [ "$fscheck" == "yes" ]; then
umount $mountpoint umount $mountpoint
if (($?)); then if (($?)); then
warning "Could not umount $mountpoint to run fsck" warning "Could not umount $mountpoint to run fsck"
else else
$nice $fsck -v -y $partition >> $log $nice $fsck -v -y $partition >> $log
mount $mountpoint mount $mountpoint
fi fi
fi fi
# restart services # restart services
if [ ! -z "$service" ]; then if [ ! -z "$service" ]; then
for daemon in $service; do for daemon in $service; do
info "Starting service $daemon..." info "Starting service $daemon..."
$initscripts/$daemon start $initscripts/$daemon start
done done
fi fi
# removes the lockfile # removes the lockfile
if [ ! -z "$lockfile" ]; then if [ ! -z "$lockfile" ]; then
$rm $lockfile || warning "Could not remove lockfile $lockfile" $rm $lockfile || warning "Could not remove lockfile $lockfile"
fi fi
echo "Finnishing backup at `date`" >> $log echo "Finnishing backup at `date`" >> $log

View File

@ -2,6 +2,6 @@
# #
# shell script handler for backupninja # shell script handler for backupninja
# runs the file /etc/backup.d/scriptname.sh # runs the file /etc/backup.d/scriptname.sh
# #
[ $test ] || ( . $1 ) [ $test ] || ( . $1 )

View File

@ -7,7 +7,7 @@ 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/bin/svnadmin hotcopy" getconf HOTBACKUP "/usr/bin/svnadmin hotcopy"
getconf vsname getconf vsname
error=0 error=0
@ -35,43 +35,43 @@ fi
cd $vroot$src 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 $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 $vroot$tmp/$repo" error "command failed mkdir -p $vroot$tmp/$repo"
fi fi
if [ $usevserver = yes ] if [ $usevserver = yes ]
then then
ret=`$VSERVER $vsname exec $HOTBACKUP $src/$repo $tmp/$repo 2>&1` ret=`$VSERVER $vsname exec $HOTBACKUP $src/$repo $tmp/$repo 2>&1`
else else
ret=`$HOTBACKUP $src/$repo $tmp/$repo 2>&1` ret=`$HOTBACKUP $src/$repo $tmp/$repo 2>&1`
fi 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 $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 $vroot$tmp instead of $vroot$dest" echo "Error: because of earlier errors, we are leaving svn backups in $vroot$tmp instead of $vroot$dest"
else else
if [ -d $vroot$dest -a -d $vroot$tmp ]; then if [ -d $vroot$dest -a -d $vroot$tmp ]; then
rm -rf $vroot$dest rm -rf $vroot$dest
fi fi
if [ -d $vroot$tmp ]; then if [ -d $vroot$tmp ]; then
mv $vroot$tmp $vroot$dest mv $vroot$tmp $vroot$dest
fi fi
fi fi
exit 0 exit 0

View File

@ -5,13 +5,13 @@ HELPERS="$HELPERS sys:general_hardware_and_system_info"
sys_wizard() { sys_wizard() {
require_packages hwinfo debconf-utils require_packages hwinfo debconf-utils
checkBox "new sys action" "check options" \ checkBox "new sys action" "check options" \
"packages" "list of all installed packages." on \ "packages" "list of all installed packages." on \
"partitions" "the partition table of all disks." on \ "partitions" "the partition table of all disks." on \
"sfdisk" "use sfdisk to get partition information." on \ "sfdisk" "use sfdisk to get partition information." on \
"hardware" "detailed hardware information" on \ "hardware" "detailed hardware information" on \
"luksheaders" "Luks headers of all Luks partitions." off \ "luksheaders" "Luks headers of all Luks partitions." off \
"lvm" "LVM metadata for all volume groups." off "lvm" "LVM metadata for all volume groups." off
[ $? = 1 ] && return; [ $? = 1 ] && return;
result="$REPLY" result="$REPLY"
packages="packages = no" packages="packages = no"
partitions="partitions = no" partitions="partitions = no"
@ -21,12 +21,12 @@ sys_wizard() {
lvm="lvm = no" lvm="lvm = no"
for opt in $result; do for opt in $result; do
case $opt in case $opt in
'"packages"') packages="packages = yes";; '"packages"') packages="packages = yes";;
'"partitions"') partitions="partitions = yes";; '"partitions"') partitions="partitions = yes";;
'"sfdisk"') sfdisk="dosfdisk = yes";; '"sfdisk"') sfdisk="dosfdisk = yes";;
'"hardware"') hardware="hardware = yes";; '"hardware"') hardware="hardware = yes";;
'"luksheaders"') luksheaders="luksheaders = yes";; '"luksheaders"') luksheaders="luksheaders = yes";;
'"lvm"') lvm="lvm = yes";; '"lvm"') lvm="lvm = yes";;
esac esac
done done
get_next_filename $configdirectory/10.sys get_next_filename $configdirectory/10.sys

View File

@ -11,17 +11,17 @@
# (2) a list of all the packages installed and removed. # (2) a list of all the packages installed and removed.
# this file can be used to restore the state of installed packages # this file can be used to restore the state of installed packages
# by running "dpkg --set-selections < dpkg-selections.txt and # by running "dpkg --set-selections < dpkg-selections.txt and
# then run "apt-get -u dselect-upgrade". If you have the # then run "apt-get -u dselect-upgrade". If you have the
# debconf-set-selections file from (1), you should restore those first. # debconf-set-selections file from (1), you should restore those first.
# #
# (3) the partition table of all disks. # (3) the partition table of all disks.
# this partition table can be used to format another disk of # this partition table can be used to format another disk of
# the same size. this can be handy if using software raid and # the same size. this can be handy if using software raid and
# you have a disk go bad. just replace the disk and partition it # you have a disk go bad. just replace the disk and partition it
# by running "sfdisk /dev/sdb < partitions.sdb.txt" # by running "sfdisk /dev/sdb < partitions.sdb.txt"
# (MAKE SURE YOU PARTITION THE CORRECT DISK!!!) # (MAKE SURE YOU PARTITION THE CORRECT DISK!!!)
# #
# (4) hardware information. # (4) hardware information.
# write to a text file the important things which hwinfo can gleen. # write to a text file the important things which hwinfo can gleen.
# #
# (5) the Luks header of every Luks block device, if option luksheaders # (5) the Luks header of every Luks block device, if option luksheaders
@ -55,7 +55,7 @@ getconf dohwinfo yes
if [ ! -d $parentdir ]; then if [ ! -d $parentdir ]; then
mkdir -p $parentdir mkdir -p $parentdir
fi fi
if [ $os = "debian" ] if [ $os = "debian" ]
then then
getconf packagesfile $parentdir/dpkg-selections.txt getconf packagesfile $parentdir/dpkg-selections.txt
@ -65,9 +65,9 @@ then
getconf debconfgetselections `which debconf-get-selections` getconf debconfgetselections `which debconf-get-selections`
elif [ $os = "redhat" ] elif [ $os = "redhat" ]
then then
getconf packagesfile $parentdir/rpmpackages.txt getconf packagesfile $parentdir/rpmpackages.txt
getconf packagemgr `which rpm` getconf packagemgr `which rpm`
getconf packagemgroptions ' -qa ' getconf packagemgroptions ' -qa '
getconf SYSREPORT `which sysreport` getconf SYSREPORT `which sysreport`
getconf sysreport_options ' -norpm ' getconf sysreport_options ' -norpm '
@ -163,7 +163,7 @@ if [ "$packages" == "yes" ]; then
# don't expand * since it can be used in $packagemgroptions # don't expand * since it can be used in $packagemgroptions
set -o noglob set -o noglob
debug "$VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile" 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" $VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile || fatal "can not save $packagemgr info to $packagesfile"
set +o noglob set +o noglob
fi fi
# is $debconfgetselections available inside $vserver ? # is $debconfgetselections available inside $vserver ?
@ -184,9 +184,9 @@ if [ "$packages" == "yes" ]; then
unset found unset found
done done
fi fi
# We want to perform this on the host as well # 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
# don't expand * since it can be used in $packagemgroptions # don't expand * since it can be used in $packagemgroptions
@ -235,7 +235,7 @@ catiffile () {
done done
fi fi
echo $DASHES >> $sysreportfile echo $DASHES >> $sysreportfile
} }
catifexec () { catifexec () {
if [ -x $1 ]; then if [ -x $1 ]; then
@ -245,12 +245,12 @@ catifexec () {
$* >> $sysreportfile 2>&1 || info "executing of $1 failed" $* >> $sysreportfile 2>&1 || info "executing of $1 failed"
fi fi
} }
STATUS="Determining $os version:" STATUS="Determining $os version:"
catiffile $osversion catiffile $osversion
STATUS="Determinding your current hostname: " STATUS="Determinding your current hostname: "
catifexec "/bin/hostname" catifexec "/bin/hostname"
STATUS="Getting the date:" STATUS="Getting the date:"
@ -272,17 +272,17 @@ if [ $os = "redhat" ]; then
catiffile "/bin/ls /etc/rc.d/rc*.d/" catiffile "/bin/ls /etc/rc.d/rc*.d/"
elif [ $os = "debian" ]; then elif [ $os = "debian" ]; then
for level in 0 1 2 3 4 5 6 S; do for level in 0 1 2 3 4 5 6 S; do
echo "Level: $level" >> $sysreportfile echo "Level: $level" >> $sysreportfile
for f in /etc/rc${level}.d/*; do for f in /etc/rc${level}.d/*; do
# Remove /etc/Knn or Snn from beginning # Remove /etc/Knn or Snn from beginning
ff=$(echo $f | @SED@ 's_/etc/rc..d/[KS][0-9][0-9]__') ff=$(echo $f | @SED@ 's_/etc/rc..d/[KS][0-9][0-9]__')
if [ $f != $ff ]; then if [ $f != $ff ]; then
echo $ff >> $sysreportfile echo $ff >> $sysreportfile
fi fi
done done
echo "" >> $sysreportfile echo "" >> $sysreportfile
done done
fi fi
STATUS="Getting bootloader information:" STATUS="Getting bootloader information:"
@ -291,34 +291,34 @@ catifexec "/bin/ls" "-alR /boot"
# This covers sparc, alpha, and intel (respectively) # This covers sparc, alpha, and intel (respectively)
# updated for grub -mpg # updated for grub -mpg
if [ -f /etc/silo.conf ]; then if [ -f /etc/silo.conf ]; then
STATUS="Collecting information about the boot process (silo):" STATUS="Collecting information about the boot process (silo):"
catiffile "/etc/silo.conf" catiffile "/etc/silo.conf"
fi fi
if [ -f /etc/milo.conf ]; then if [ -f /etc/milo.conf ]; then
STATUS="Collecting information about the boot process (milo):" STATUS="Collecting information about the boot process (milo):"
catiffile "/etc/milo.conf" catiffile "/etc/milo.conf"
fi fi
if [ -f /etc/lilo.conf ]; then if [ -f /etc/lilo.conf ]; then
STATUS="Collecting information about the boot process (lilo):" STATUS="Collecting information about the boot process (lilo):"
catiffile "/etc/lilo.conf" catiffile "/etc/lilo.conf"
catifexec "/sbin/lilo" "-q" catifexec "/sbin/lilo" "-q"
fi fi
if [ -d /boot/grub -a -f /boot/grub/grub.conf -a -f /boot/grub/device.map ]; then if [ -d /boot/grub -a -f /boot/grub/grub.conf -a -f /boot/grub/device.map ]; then
STATUS="Collecting information about the boot process (grub.conf):" STATUS="Collecting information about the boot process (grub.conf):"
catiffile "/boot/grub/grub.conf" catiffile "/boot/grub/grub.conf"
STATUS="Collecting information about the boot process (grub.map):" STATUS="Collecting information about the boot process (grub.map):"
catiffile "/boot/grub/device.map" catiffile "/boot/grub/device.map"
fi fi
if [ -f /etc/cluster.conf -o -f /etc/cluster.xml ] ; then if [ -f /etc/cluster.conf -o -f /etc/cluster.xml ] ; then
STATUS="Gathering information on cluster setup" STATUS="Gathering information on cluster setup"
# 2.1 AS # 2.1 AS
if [ -f /etc/cluster.conf ] ; then if [ -f /etc/cluster.conf ] ; then
catiffile "/etc/cluster.conf" catiffile "/etc/cluster.conf"
fi fi
# Taroon # Taroon
if [ -f /etc/cluster.xml ] ; then if [ -f /etc/cluster.xml ] ; then
catiffile "/etc/cluster.xml" catiffile "/etc/cluster.xml"
fi fi
fi fi
STATUS="Gathering sysctl information (sysctl -a):" STATUS="Gathering sysctl information (sysctl -a):"
@ -349,10 +349,10 @@ STATUS="Getting kernel version:"
catifexec "/bin/uname" "-a" catifexec "/bin/uname" "-a"
STATUS="Checking module information:" STATUS="Checking module information:"
catifexec "/sbin/lsmod" catifexec "/sbin/lsmod"
for x in $(/sbin/lsmod | /bin/cut -f1 -d" " 2>/dev/null | /bin/grep -v Module 2>/dev/null for x in $(/sbin/lsmod | /bin/cut -f1 -d" " 2>/dev/null | /bin/grep -v Module 2>/dev/null
) ; do ) ; do
STATUS="Checking module information $x:" STATUS="Checking module information $x:"
catifexec "/sbin/modinfo" "$x" catifexec "/sbin/modinfo" "$x"
done done
STATUS="Gathering information about your filesystems:" STATUS="Gathering information about your filesystems:"
@ -375,27 +375,27 @@ STATUS="Collecting information regarding kernel modules"
VER=`uname -r` VER=`uname -r`
catiffile "/lib/modules/$VER/modules.dep" catiffile "/lib/modules/$VER/modules.dep"
if [ -f /etc/conf.modules ]; then if [ -f /etc/conf.modules ]; then
STATUS="Collecting information regarding kernel modules (conf.modules)" STATUS="Collecting information regarding kernel modules (conf.modules)"
catiffile "/etc/conf.modules" catiffile "/etc/conf.modules"
fi fi
if [ -f /etc/modules.conf ]; then if [ -f /etc/modules.conf ]; then
STATUS="Collecting information regarding kernel modules (modules.conf)" STATUS="Collecting information regarding kernel modules (modules.conf)"
catiffile "/etc/modules.conf" catiffile "/etc/modules.conf"
fi fi
if [ -f /etc/modprobe.conf ]; then if [ -f /etc/modprobe.conf ]; then
STATUS="Collecting information regarding kernel modules (modeprobe.conf)" STATUS="Collecting information regarding kernel modules (modeprobe.conf)"
catiffile "/etc/modprobe.conf" catiffile "/etc/modprobe.conf"
fi fi
# dkms status # dkms status
if [ -x /usr/sbin/dkms ] ; then if [ -x /usr/sbin/dkms ] ; then
STATUS="Gathering current status of modules, versions and kernels (dkms):" STATUS="Gathering current status of modules, versions and kernels (dkms):"
catifexec "/usr/sbin/dkms" "status" catifexec "/usr/sbin/dkms" "status"
fi fi
if [ -f /etc/sysconfig/isdncard ] ; then if [ -f /etc/sysconfig/isdncard ] ; then
STATUS="Gathering information about ISDN:" STATUS="Gathering information about ISDN:"
catiffile "/etc/sysconfig/isdncard" catiffile "/etc/sysconfig/isdncard"
fi fi
STATUS="Collecting information from the proc directory:" STATUS="Collecting information from the proc directory:"
@ -481,18 +481,18 @@ fi
STATUS="Collecting device-mapper (dm) information:" STATUS="Collecting device-mapper (dm) information:"
catifexec '/sbin/dmsetup' 'info' catifexec '/sbin/dmsetup' 'info'
STATUS="Collecting SCSI Tape information (/etc/stinit.def)" STATUS="Collecting SCSI Tape information (/etc/stinit.def)"
catiffile "/etc/stinit.def" catiffile "/etc/stinit.def"
if [ -x /sbin/lsusb ] ; then if [ -x /sbin/lsusb ] ; then
STATUS="Collecting USB devices list (lsusb):" STATUS="Collecting USB devices list (lsusb):"
catifexec "/sbin/lsusb" catifexec "/sbin/lsusb"
fi fi
if [ -x /usr/bin/lshal ] ; then if [ -x /usr/bin/lshal ] ; then
STATUS="Collecting global devices list (lshal):" STATUS="Collecting global devices list (lshal):"
catifexec "/usr/bin/lshal" catifexec "/usr/bin/lshal"
fi fi
@ -511,24 +511,24 @@ 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
warning "can't find sfdisk, skipping sfdisk report." warning "can't find sfdisk, skipping sfdisk report."
partitions="no" partitions="no"
fi fi
fi fi
if [ "$dohwinfo" == "yes" ]; then if [ "$dohwinfo" == "yes" ]; then
if [ ! -x "$HWINFO" ]; then if [ ! -x "$HWINFO" ]; then
warning "can't find hwinfo, skipping partition report." warning "can't find hwinfo, skipping partition report."
partitions="no" partitions="no"
fi fi
fi fi
fi fi
if [ "$hardware" == "yes" ]; then if [ "$hardware" == "yes" ]; then
if [ ! -x "$HWINFO" ]; then if [ ! -x "$HWINFO" ]; then
warning "can't find hwinfo, skipping hardware report." warning "can't find hwinfo, skipping hardware report."
hardware="no" hardware="no"
fi fi
fi fi
## HARDWARE ############################# ## HARDWARE #############################
@ -536,47 +536,47 @@ fi
# #
# here we use hwinfo to dump a table listing all the # here we use hwinfo to dump a table listing all the
# information we can find on the hardware of this machine # information we can find on the hardware of this machine
# #
if [ "$hardware" == "yes" ]; then if [ "$hardware" == "yes" ]; then
if [ "dohwinfo" == "yes" ]; then if [ "dohwinfo" == "yes" ]; then
if [ -f $hardwarefile ]; then if [ -f $hardwarefile ]; then
rm $hardwarefile rm $hardwarefile
fi fi
touch $hardwarefile touch $hardwarefile
echo -e "\n\n====================== summary ======================\n" >> $hardwarefile echo -e "\n\n====================== summary ======================\n" >> $hardwarefile
debug "$HWINFO --short --cpu --network --disk --pci >> $hardwarefile" debug "$HWINFO --short --cpu --network --disk --pci >> $hardwarefile"
$HWINFO --short --cpu --network --disk --pci >> $hardwarefile $HWINFO --short --cpu --network --disk --pci >> $hardwarefile
for flag in cpu network bios pci; do for flag in cpu network bios pci; do
echo -e "\n\n====================== $flag ======================\n" >> $hardwarefile echo -e "\n\n====================== $flag ======================\n" >> $hardwarefile
$HWINFO --$flag >> $hardwarefile $HWINFO --$flag >> $hardwarefile
done done
fi fi
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.
# these files can be used to directly partition a disk of the same size. # these files can be used to directly partition a disk of the same size.
if [ "$partitions" == "yes" ]; then if [ "$partitions" == "yes" ]; then
if [ "$dosfdisk" == "yes" ]; then if [ "$dosfdisk" == "yes" ]; then
devices=`LC_ALL=C $SFDISK -l 2>/dev/null | grep "^Disk /dev" | @AWK@ '{print $2}' | cut -d: -f1` devices=`LC_ALL=C $SFDISK -l 2>/dev/null | grep "^Disk /dev" | @AWK@ '{print $2}' | cut -d: -f1`
if [ "$devices" == "" ]; then if [ "$devices" == "" ]; then
warning "No harddisks found" warning "No harddisks found"
fi fi
for dev in $devices; do for dev in $devices; do
debug "$SFDISK will try to backup partition tables for device $dev" debug "$SFDISK will try to backup partition tables for device $dev"
[ -b $dev ] || continue [ -b $dev ] || continue
label=${dev#/dev/} label=${dev#/dev/}
label=${label//\//-} label=${label//\//-}
outputfile=${partitionsfile//__star__/$label} outputfile=${partitionsfile//__star__/$label}
debug "$SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null" debug "$SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null"
$SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null $SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
warning "The partition table for $dev could not be saved." warning "The partition table for $dev could not be saved."
fi fi
done done
fi fi
if [ "$dohwinfo" == "yes" ]; then if [ "$dohwinfo" == "yes" ]; then
debug "Using $HWINFO to get all available disk information" debug "Using $HWINFO to get all available disk information"
@ -639,8 +639,8 @@ function doLvmBackup () {
fi fi
fi fi
if [ ! -w "$lvmdir" ]; then if [ ! -w "$lvmdir" ]; then
echo "can not write to directory $lvmdir" echo "can not write to directory $lvmdir"
return 2 return 2
fi fi
debug "Let's try to gather the list of LVM volume groups" debug "Let's try to gather the list of LVM volume groups"
debug "$VGS --options vg_name --noheadings | @SED@ 's/^[ ]*//' | @SED@ 's/[ ]*$//' | tr '\n' ' '" debug "$VGS --options vg_name --noheadings | @SED@ 's/^[ ]*//' | @SED@ 's/[ ]*$//' | tr '\n' ' '"

View File

@ -14,7 +14,7 @@ tar_wizard() {
inputBox "$tar_title" "\"Name\" of backups" "$backupname" inputBox "$tar_title" "\"Name\" of backups" "$backupname"
[ $? = 1 ] && return [ $? = 1 ] && return
tar_backupname="backupname = $REPLY" tar_backupname="backupname = $REPLY"
backupname="$REPLY" backupname="$REPLY"
inputBox "$tar_title" "Directory where to store the backups" "/net/backups/$backupname" inputBox "$tar_title" "Directory where to store the backups" "/net/backups/$backupname"
[ $? = 1 ] && return [ $? = 1 ] && return
@ -24,8 +24,8 @@ tar_wizard() {
"none" "do not filter trough" off \ "none" "do not filter trough" off \
"compress" "filter trough compress" off \ "compress" "filter trough compress" off \
"gzip" "filter trough gzip" off \ "gzip" "filter trough gzip" off \
"bzip" "filter trough bzip" on "bzip" "filter trough bzip" on
[ $? = 1 ] && return; [ $? = 1 ] && return;
result="$REPLY" result="$REPLY"
tar_compress="compress = $REPLY " tar_compress="compress = $REPLY "
@ -47,14 +47,14 @@ tar_wizard() {
[ $? = 0 ] || return 1 [ $? = 0 ] || return 1
tar_includes="includes = " tar_includes="includes = "
for i in $REPLY; do for i in $REPLY; do
[ -n "$i" ] && tar_includes="$tar_includes $i" [ -n "$i" ] && tar_includes="$tar_includes $i"
done done
done done
REPLY= REPLY=
while [ -z "$REPLY" ]; do while [ -z "$REPLY" ]; do
formBegin "$tar_title: Excludes" formBegin "$tar_title: Excludes"
formItem "Exclude:" /tmp formItem "Exclude:" /tmp
formItem "Exclude:" /proc formItem "Exclude:" /proc
formItem "Exclude:" /sys formItem "Exclude:" /sys
formItem "Exclude:" /dev formItem "Exclude:" /dev
@ -63,17 +63,17 @@ tar_wizard() {
formItem "Exclude:" /misc formItem "Exclude:" /misc
formItem "Exclude:" /net formItem "Exclude:" /net
formItem "Exclude:" /selinux formItem "Exclude:" /selinux
formItem "Exclude:" formItem "Exclude:"
formItem "Exclude:" formItem "Exclude:"
formDisplay formDisplay
[ $? = 0 ] || return 1 [ $? = 0 ] || return 1
tar_excludes="excludes = " tar_excludes="excludes = "
for i in $REPLY; do for i in $REPLY; do
[ -n "$i" ] && tar_excludes="$tar_excludes $i" [ -n "$i" ] && tar_excludes="$tar_excludes $i"
done done
done done
# Save the config # Save the config
get_next_filename $configdirectory/10.tar get_next_filename $configdirectory/10.tar
cat > $next_filename <<EOF cat > $next_filename <<EOF
$tar_when_run $tar_when_run
@ -85,8 +85,8 @@ $tar_excludes
# tar binary - have to be GNU tar # tar binary - have to be GNU tar
#TAR=/bin/tar #TAR=/bin/tar
#DATE /bin/date #DATE /bin/date
#DATEFORMAT "%Y.%m.%d-%H%M" #DATEFORMAT "%Y.%m.%d-%H%M"
EOF EOF
chmod 600 $next_filename chmod 600 $next_filename

View File

@ -2,16 +2,16 @@
# #
# tar handler script for backupninja # tar handler script for backupninja
getconf backupname `hostname --fqdn` getconf backupname `hostname --fqdn`
getconf backupdir /var/backups/`hostname --fqdn` getconf backupdir /var/backups/`hostname --fqdn`
getconf compress bzip getconf compress bzip
getconf includes "/etc /home /usr/local" getconf includes "/etc /home /usr/local"
getconf excludes "/tmp /proc /dev /sys /net /misc /media /srv /selinux" getconf excludes "/tmp /proc /dev /sys /net /misc /media /srv /selinux"
getconf TAR `which tar` getconf TAR `which tar`
getconf EXTENSION tar 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 # See if vservers are configured
if [ "$vservers" = "yes" ] if [ "$vservers" = "yes" ]
@ -65,7 +65,7 @@ done
debug "Running backup: " $TAR -c -p -v $compress_option $exclude_options \ debug "Running backup: " $TAR -c -p -v $compress_option $exclude_options \
-f "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`".$EXTENSION" \ -f "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`".$EXTENSION" \
$includes $includes
$TAR -c -p -v $compress_option $exclude_options \ $TAR -c -p -v $compress_option $exclude_options \
-f "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`".$EXTENSION" \ -f "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`".$EXTENSION" \
@ -73,7 +73,7 @@ $TAR -c -p -v $compress_option $exclude_options \
> "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`.list \ > "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`.list \
2> "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`.err 2> "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`.err
[ $? -ne 0 ] && fatal "Tar backup failed" [ $? -ne 0 ] && fatal "Tar backup failed"

View File

@ -12,39 +12,38 @@ getconf tmp /var/backups/trac.tmp
cd $src cd $src
for repo in `find . -name VERSION` for repo in `find . -name VERSION`
do do
repo=`dirname $repo`
if [ "$repo" == "." ]
then
repo=""
fi
repo=`dirname $repo` # Just make the parent directory for $tmp/$repo
if [ "$repo" == "." ] parentdir=`dirname $tmp/$repo`
then ret=`mkdir -p $parentdir 2>&1`
repo="" code=$?
fi if [ "$ret" ]; then
debug "$ret"
fi
if [ $code != 0 ]; then
error "command failed mkdir -p $parentdir"
fi
# Just make the parent directory for $tmp/$repo ret=`trac-admin $src/$repo hotcopy $tmp/$repo 2>&1`
parentdir=`dirname $tmp/$repo` code=$?
ret=`mkdir -p $parentdir 2>&1` if [ "$ret" ]; then
code=$? debug "$ret"
if [ "$ret" ]; then fi
debug "$ret" if [ $code != 0 ]; then
fi error "command failed -- trac-admin $src/$repo hotcopy $tmp/$repo"
if [ $code != 0 ]; then fi
error "command failed mkdir -p $parentdir"
fi
ret=`trac-admin $src/$repo hotcopy $tmp/$repo 2>&1`
code=$?
if [ "$ret" ]; then
debug "$ret"
fi
if [ $code != 0 ]; then
error "command failed -- trac-admin $src/$repo hotcopy $tmp/$repo"
fi
done done
if [ -d $dest -a -d $tmp ]; then if [ -d $dest -a -d $tmp ]; then
rm -rf $dest rm -rf $dest
fi fi
if [ -d $tmp ]; then if [ -d $tmp ]; then
mv $tmp $dest mv $tmp $dest
fi fi
exit 0 exit 0

View File

@ -77,84 +77,82 @@ getconf folder
function rotate { function rotate {
if [[ "$2" < 4 ]]; then if [[ "$2" < 4 ]]; then
error "Rotate: minimum of 4 rotations" error "Rotate: minimum of 4 rotations"
exit 1 exit 1
fi fi
if [ -d $1.$2 ]; then if [ -d $1.$2 ]; then
$nice $mv /$1.$2 /$1.tmp $nice $mv /$1.$2 /$1.tmp
fi fi
for ((n=`echo "$2 - 1" | bc`; n >= 0; n--)); do for ((n=`echo "$2 - 1" | bc`; n >= 0; n--)); do
if [ -d $1.$n ]; then if [ -d $1.$n ]; then
dest=`echo "$n + 1" | bc` dest=`echo "$n + 1" | bc`
$nice $mv /$1.$n /$1.$dest $nice $mv /$1.$n /$1.$dest
$touch /$1.$dest $touch /$1.$dest
fi fi
done done
if [ -d $1.tmp ]; then if [ -d $1.tmp ]; then
$nice $mv /$1.tmp /$1.0 $nice $mv /$1.tmp /$1.0
fi fi
if [ -d $1.1 ]; then if [ -d $1.1 ]; then
$nice $cp -alf /$1.1/. /$1.0 $nice $cp -alf /$1.1/. /$1.0
fi fi
} }
function move_files { function move_files {
ref=$tmp/makesnapshot-mymv-$$;
ref=$tmp/makesnapshot-mymv-$$; $touch -r $1 $ref;
$touch -r $1 $ref; $mv $1 $2;
$mv $1 $2; $touch -r $ref $2;
$touch -r $ref $2; $rm $ref;
$rm $ref;
} }
backupdir="$mountpoint/$backupdir" backupdir="$mountpoint/$backupdir"
# does $backupdir exists? # does $backupdir exists?
if [ ! -d "$backupdir" ]; then if [ ! -d "$backupdir" ]; then
error "Backupdir $backupdir does not exist" error "Backupdir $backupdir does not exist"
exit 1 exit 1
fi fi
# setup number of increments # setup number of increments
if [ -z "$days" ]; then if [ -z "$days" ]; then
keep="4" keep="4"
else else
keep="`echo $days - 1 | bc -l`" keep="`echo $days - 1 | bc -l`"
fi fi
# lockfile setup # lockfile setup
if [ ! -z "$lockfile" ]; then if [ ! -z "$lockfile" ]; then
$touch $lockfile || warning "Could not create lockfile $lockfile" $touch $lockfile || warning "Could not create lockfile $lockfile"
fi fi
# nicelevel setup # nicelevel setup
if [ ! -z "$nicelevel" ]; then if [ ! -z "$nicelevel" ]; then
nice="nice -n $nicelevel" nice="nice -n $nicelevel"
else else
nice="" nice=""
fi fi
# set mv procedure # set mv procedure
if [ $enable_mv_timestamp_bug == "yes" ]; then if [ $enable_mv_timestamp_bug == "yes" ]; then
mv=move_files mv=move_files
fi fi
# set excludes # set excludes
for path in $exclude; do for path in $exclude; do
EXCLUDES="$EXCLUDES --exclude=$path" EXCLUDES="$EXCLUDES --exclude=$path"
done done
echo "Starting backup at `date`" >> $log echo "Starting backup at `date`" >> $log
@ -162,19 +160,19 @@ echo "Starting backup at `date`" >> $log
# mount backup destination folder as read-write # mount backup destination folder as read-write
if [ "$read_only" == "1" ] || [ "$read_only" == "yes" ]; then if [ "$read_only" == "1" ] || [ "$read_only" == "yes" ]; then
if [ -d "$mountpoint" ]; then if [ -d "$mountpoint" ]; then
mount -o remount,rw $mountpoint mount -o remount,rw $mountpoint
if (($?)); then if (($?)); then
error "Could not mount $mountpoint" error "Could not mount $mountpoint"
exit 1 exit 1
fi fi
fi fi
fi fi
# the backup procedure # the backup procedure
if [ ! -d "$backupdir/$folder/$folder.0" ]; then if [ ! -d "$backupdir/$folder/$folder.0" ]; then
mkdir -p $backupdir/$folder/$folder.0 mkdir -p $backupdir/$folder/$folder.0
fi fi
info "Rotating $backupdir/$folder/$folder..." info "Rotating $backupdir/$folder/$folder..."
@ -183,7 +181,7 @@ rotate $backupdir/$folder/$folder $keep
info "Wget'ing $SECTION on $backupdir/$folder/$folder.0..." info "Wget'ing $SECTION on $backupdir/$folder/$folder.0..."
if [ ! -z "$badnwidth" ]; then if [ ! -z "$badnwidth" ]; then
limit_rate="--limit-rate=$badnwidth""k" limit_rate="--limit-rate=$badnwidth""k"
fi fi
cd $backupdir/$folder/$folder.0 cd $backupdir/$folder/$folder.0
@ -195,25 +193,25 @@ $touch $backupdir/$folder/$folder.0
# remount backup destination as read-only # remount backup destination as read-only
if [ "$read_only" == "1" ] || [ "$read_only" == "yes" ]; then if [ "$read_only" == "1" ] || [ "$read_only" == "yes" ]; then
mount -o remount,ro $mountpoint mount -o remount,ro $mountpoint
fi fi
# check partition for errors # check partition for errors
if [ "$fscheck" == "1" ] || [ "$fscheck" == "yes" ]; then if [ "$fscheck" == "1" ] || [ "$fscheck" == "yes" ]; then
umount $mountpoint umount $mountpoint
if (($?)); then if (($?)); then
warning "Could not umount $mountpoint to run fsck" warning "Could not umount $mountpoint to run fsck"
else else
$nice $fsck -v -y $partition >> $log $nice $fsck -v -y $partition >> $log
mount $mountpoint mount $mountpoint
fi fi
fi fi
# removes the lockfile # removes the lockfile
if [ ! -z "$lockfile" ]; then if [ ! -z "$lockfile" ]; then
$rm $lockfile || warning "Could not remove lockfile $lockfile" $rm $lockfile || warning "Could not remove lockfile $lockfile"
fi fi
echo "Finnishing backup at `date`" >> $log echo "Finnishing backup at `date`" >> $log

View File

@ -20,43 +20,43 @@ DIALOG=dialog
HELP= HELP=
setApplicationTitle() { setApplicationTitle() {
BACKTITLE=$* BACKTITLE=$*
} }
setHelp() { setHelp() {
HELP="$@" HELP="$@"
} }
setDimension() { setDimension() {
WIDTH=$1 WIDTH=$1
HEIGHT=$2 HEIGHT=$2
} }
booleanBox() { booleanBox() {
$DIALOG --backtitle "$BACKTITLE" --title "$1" \ $DIALOG --backtitle "$BACKTITLE" --title "$1" \
`[ "$3" == no ] && echo '--defaultno'` --yesno "$2" $HEIGHT $WIDTH `[ "$3" == no ] && echo '--defaultno'` --yesno "$2" $HEIGHT $WIDTH
} }
msgBox() { msgBox() {
$DIALOG --backtitle "$BACKTITLE" --title "$1" \ $DIALOG --backtitle "$BACKTITLE" --title "$1" \
--msgbox "$2" $HEIGHT $WIDTH --msgbox "$2" $HEIGHT $WIDTH
} }
gaugeBox() { gaugeBox() {
$DIALOG --backtitle "$BACKTITLE" --title "$1" \ $DIALOG --backtitle "$BACKTITLE" --title "$1" \
--gauge "$2" $HEIGHT $WIDTH 0 --gauge "$2" $HEIGHT $WIDTH 0
} }
inputBox() { inputBox() {
local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1 local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1
trap "rm -f $temp" 0 trap "rm -f $temp" 0
REPLY= REPLY=
$DIALOG --backtitle "$BACKTITLE" --title "$1" \ $DIALOG --backtitle "$BACKTITLE" --title "$1" \
--inputbox "$2" $HEIGHT $WIDTH "$3" 2> $temp --inputbox "$2" $HEIGHT $WIDTH "$3" 2> $temp
local status=$? local status=$?
[ $status = 0 ] && REPLY=$(cat $temp) [ $status = 0 ] && REPLY=$(cat $temp)
rm -f $temp rm -f $temp
return $status return $status
} }
# Xdialog and {dialog,whiptail} use different mechanism to "qoute" the # Xdialog and {dialog,whiptail} use different mechanism to "qoute" the
@ -67,7 +67,7 @@ inputBox() {
# mechanism to the standard double-quoting one. it receives two # mechanism to the standard double-quoting one. it receives two
# arguements, the file that has the data and the box type. # arguements, the file that has the data and the box type.
_listReplyHook() { _listReplyHook() {
cat $1 cat $1
} }
# this is the base implementation of all the list based boxes, it works # this is the base implementation of all the list based boxes, it works
@ -75,79 +75,79 @@ _listReplyHook() {
# this function with an extra argument specifying the actual box that # this function with an extra argument specifying the actual box that
# needs to be rendered. # needs to be rendered.
_genericListBox() { _genericListBox() {
local box=$1 local box=$1
shift 1 shift 1
local title=$1 local title=$1
local text=$2 local text=$2
shift 2 shift 2
local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1 local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1
trap "rm -f $temp" 0 trap "rm -f $temp" 0
REPLY= REPLY=
$DIALOG $HELP $_DEFAULT --backtitle "$BACKTITLE" --title "$title" \ $DIALOG $HELP $_DEFAULT --backtitle "$BACKTITLE" --title "$title" \
$box "$text" $HEIGHT $WIDTH 10 \ $box "$text" $HEIGHT $WIDTH 10 \
"$@" 2> $temp "$@" 2> $temp
local status=$? local status=$?
[ $status = 0 ] && REPLY=$(_listReplyHook $temp $box) [ $status = 0 ] && REPLY=$(_listReplyHook $temp $box)
rm -f $temp rm -f $temp
_DEFAULT= _DEFAULT=
return $status return $status
} }
setDefault() { setDefault() {
_DEFAULT="--default-item $1" _DEFAULT="--default-item $1"
} }
menuBox() { menuBox() {
_genericListBox --menu "$@" _genericListBox --menu "$@"
} }
## a menu box with additional help info displayed ## a menu box with additional help info displayed
## at the bottom of the window when an item is selected ## at the bottom of the window when an item is selected
menuBoxHelp() { menuBoxHelp() {
HELP="--item-help" HELP="--item-help"
_genericListBox --menu "$@" _genericListBox --menu "$@"
status=$? status=$?
HELP= HELP=
return $status return $status
} }
## a menu box with an addition button 'help' ## a menu box with an addition button 'help'
menuBoxHelpFile() { menuBoxHelpFile() {
HELP="--help-button" HELP="--help-button"
_genericListBox --menu "$@" _genericListBox --menu "$@"
status=$? status=$?
HELP= HELP=
return $status return $status
} }
checkBox() { checkBox() {
_genericListBox --checklist "$@" _genericListBox --checklist "$@"
} }
radioBox() { radioBox() {
_genericListBox --radiolist "$@" _genericListBox --radiolist "$@"
} }
textBox() { textBox() {
$DIALOG --backtitle "$BACKTITLE" --title "$1" --textbox "$2" $HEIGHT $WIDTH $DIALOG --backtitle "$BACKTITLE" --title "$1" --textbox "$2" $HEIGHT $WIDTH
} }
passwordBox() { passwordBox() {
local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1 local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1
trap "rm -f $temp" 0 trap "rm -f $temp" 0
REPLY= REPLY=
$DIALOG --backtitle "$BACKTITLE" --title "$1" \ $DIALOG --backtitle "$BACKTITLE" --title "$1" \
--passwordbox "$2" $HEIGHT $WIDTH 2> $temp --passwordbox "$2" $HEIGHT $WIDTH 2> $temp
local status=$? local status=$?
[ $status = 0 ] && REPLY=$(cat $temp) [ $status = 0 ] && REPLY=$(cat $temp)
rm -f $temp rm -f $temp
return $status return $status
} }
######################################################### #########################################################
## begin-item-display style lists ## begin-item-display style lists
## ##
## these lists are built by calling fuctions multiple times. ## these lists are built by calling fuctions multiple times.
## this can make it easier to build your list in a loop ## this can make it easier to build your list in a loop
## ##
@ -177,7 +177,7 @@ listDisplay() {
boxtype=$1 boxtype=$1
local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1 local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1
trap "rm -f $temp" 0 trap "rm -f $temp" 0
local label local label
local text local text
local status local status
@ -188,13 +188,13 @@ listDisplay() {
echo -ne " --$boxtype '$_menu_msg' " echo -ne " --$boxtype '$_menu_msg' "
echo -ne " $HEIGHT $WIDTH 10 " echo -ne " $HEIGHT $WIDTH 10 "
for ((i=0; i < $_menu_items ; i++)); do for ((i=0; i < $_menu_items ; i++)); do
label=${_menu_labels[$i]} label=${_menu_labels[$i]}
text=${_menu_text[$i]} text=${_menu_text[$i]}
status=${_menu_status[$i]} status=${_menu_status[$i]}
echo -ne " $label '$text' $status " echo -ne " $label '$text' $status "
done done
) | xargs $DIALOG 2> $temp ) | xargs $DIALOG 2> $temp
local status=$? local status=$?
REPLY="" REPLY=""
[ $status = 0 ] && REPLY=`cat $temp` [ $status = 0 ] && REPLY=`cat $temp`
@ -219,10 +219,10 @@ formItem() {
_form_text[$_form_items]=$2 _form_text[$_form_items]=$2
let "_form_items += 1" let "_form_items += 1"
} }
formDisplay() { formDisplay() {
local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1 local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1
max_length=0 max_length=0
for ((i=0; i < ${#_form_labels[@]} ; i++)); do for ((i=0; i < ${#_form_labels[@]} ; i++)); do
label=${_form_labels[$i]} label=${_form_labels[$i]}
@ -232,19 +232,19 @@ formDisplay() {
fi fi
done done
let "max_length += 2" let "max_length += 2"
local xpos=1 local xpos=1
( (
echo -n -e "--form '$_form_title' 0 0 20" echo -n -e "--form '$_form_title' 0 0 20"
for ((i=0; i < $_form_items ; i++)); do for ((i=0; i < $_form_items ; i++)); do
label=${_form_labels[$i]} label=${_form_labels[$i]}
text=${_form_text[$i]} text=${_form_text[$i]}
echo -n -e " $label $xpos 1 '$text' $xpos $max_length 30 30" echo -n -e " $label $xpos 1 '$text' $xpos $max_length 30 30"
let "xpos += _form_gap" let "xpos += _form_gap"
done done
) | xargs $DIALOG 2> $temp ) | xargs $DIALOG 2> $temp
local status=$? local status=$?
## ##
## the exit status is meaningless, it is always 0. ## the exit status is meaningless, it is always 0.
## i can't figure out how to get the exit status of dialog ## i can't figure out how to get the exit status of dialog
@ -254,7 +254,7 @@ formDisplay() {
## swallowed by xargs. xargs should return different exit status ## swallowed by xargs. xargs should return different exit status
## depending on the exit status of the command run, but i have ## depending on the exit status of the command run, but i have
## never been able to get that to work. ## never been able to get that to work.
## ##
REPLY= REPLY=
if [ $status = 0 ]; then if [ $status = 0 ]; then

View File

@ -10,39 +10,39 @@
# create a temporary file in a secure way. # create a temporary file in a secure way.
# #
function maketemp() { function maketemp() {
local tempfile=`mktemp /tmp/$1.XXXXXXXX` local tempfile=`mktemp /tmp/$1.XXXXXXXX`
echo $tempfile echo $tempfile
} }
##################################################### #####################################################
## CONFIG-FILE RELATED FUNCTIONS ## CONFIG-FILE RELATED FUNCTIONS
function setfile() { function setfile() {
CURRENT_CONF_FILE=$1 CURRENT_CONF_FILE=$1
} }
function setsection() { function setsection() {
CURRENT_SECTION=$1 CURRENT_SECTION=$1
} }
# #
# sets a global var with name equal to $1 # sets a global var with name equal to $1
# to the value of the configuration parameter $1 # to the value of the configuration parameter $1
# $2 is the default. # $2 is the default.
# #
function getconf() { function getconf() {
CURRENT_PARAM=$1 CURRENT_PARAM=$1
ret=`@AWK@ -f $libdirectory/parseini S=$CURRENT_SECTION P=$CURRENT_PARAM $CURRENT_CONF_FILE` ret=`@AWK@ -f $libdirectory/parseini S=$CURRENT_SECTION P=$CURRENT_PARAM $CURRENT_CONF_FILE`
# if nothing is returned, set the default # if nothing is returned, set the default
if [ "$ret" == "" -a "$2" != "" ]; then if [ "$ret" == "" -a "$2" != "" ]; then
ret="$2" ret="$2"
fi fi
# replace * with %, so that it is not globbed. # replace * with %, so that it is not globbed.
ret="${ret//\\*/__star__}" ret="${ret//\\*/__star__}"
# this is weird, but single quotes are needed to # this is weird, but single quotes are needed to
# allow for returned values with spaces. $ret is still expanded # allow for returned values with spaces. $ret is still expanded
# because it is in an 'eval' statement. # because it is in an 'eval' statement.
eval $1='$ret' eval $1='$ret'
} }

View File

@ -66,7 +66,7 @@ init_vservers() {
found_vservers=`ls $VROOTDIR | grep -E -v "lost\+found|ARCHIVES" | tr "\n" " "` found_vservers=`ls $VROOTDIR | grep -E -v "lost\+found|ARCHIVES" | tr "\n" " "`
if [ -z "$found_vservers" ]; then if [ -z "$found_vservers" ]; then
`if [ "$arg" = nodialog ]; then echo warning; else echo "msgBox warning"; fi` \ `if [ "$arg" = nodialog ]; then echo warning; else echo "msgBox warning"; fi` \
"vservers enabled in $conffile, but no vserver was found in $VROOTDIR."; "vservers enabled in $conffile, but no vserver was found in $VROOTDIR.";
return return
fi fi
vservers_are_available=yes vservers_are_available=yes
@ -142,9 +142,9 @@ choose_one_vserver() {
while [ -z "$REPLY" ]; do while [ -z "$REPLY" ]; do
[ -n "$selected_vservers" ] && setDefault $selected_vservers [ -n "$selected_vservers" ] && setDefault $selected_vservers
listBegin "$title" "Choose at least one Linux-Vserver to backup:" listBegin "$title" "Choose at least one Linux-Vserver to backup:"
for vserver in $found_vservers; do for vserver in $found_vservers; do
listItem "$vserver" "Backup $vserver vserver" listItem "$vserver" "Backup $vserver vserver"
done done
listDisplay menu listDisplay menu
[ $? = 0 ] || return 1 [ $? = 0 ] || return 1
done done
@ -152,17 +152,17 @@ choose_one_vserver() {
} }
## ##
## If Vservers are not enabled, set host_or_vservers='host' and then return ## 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 ## Else, have the user choose if he/she wants to perform the backup on the host
## system or on one Vserver. ## system or on one Vserver.
## Set, respectively, $host_or_vservers to 'host' or 'vservers'. ## Set, respectively, $host_or_vservers to 'host' or 'vservers'.
## Returns 1 if cancelled. ## Returns 1 if cancelled.
## ##
choose_host_or_one_vserver() { choose_host_or_one_vserver() {
if [ "$vservers_are_available" != "yes" ] if [ "$vservers_are_available" != "yes" ]
then then
host_or_vservers='host' host_or_vservers='host'
return return
fi fi
local title=$1 local title=$1
# if there is one, set the previously chosen item as the default # if there is one, set the previously chosen item as the default
@ -173,11 +173,11 @@ choose_host_or_one_vserver() {
[ $? = 0 ] || return 1 [ $? = 0 ] || return 1
case $REPLY in case $REPLY in
"host") "host")
host_or_vservers='host' host_or_vservers='host'
;; ;;
"vserver") "vserver")
host_or_vservers='vservers' host_or_vservers='vservers'
;; ;;
esac esac
} }
@ -191,10 +191,10 @@ choose_host_or_one_vserver() {
## Returns 1 if cancelled. ## Returns 1 if cancelled.
## ##
choose_host_or_vservers_or_both() { choose_host_or_vservers_or_both() {
if [ "$vservers_are_available" != "yes" ] if [ "$vservers_are_available" != "yes" ]
then then
host_or_vservers='host' host_or_vservers='host'
return return
fi fi
local title=$1 local title=$1
# if there is one, set the previously chosen item as the default # if there is one, set the previously chosen item as the default
@ -206,14 +206,14 @@ choose_host_or_vservers_or_both() {
[ $? = 0 ] || return 1 [ $? = 0 ] || return 1
case $REPLY in case $REPLY in
"host") "host")
host_or_vservers='host' host_or_vservers='host'
;; ;;
"vservers") "vservers")
host_or_vservers='vservers' host_or_vservers='vservers'
;; ;;
"both") "both")
host_or_vservers='both' host_or_vservers='both'
;; ;;
esac esac
} }
@ -236,13 +236,13 @@ choose_one_or_more_vservers() {
local vserver_was_selected= local vserver_was_selected=
REPLY= REPLY=
while [ -z "$REPLY" ]; do while [ -z "$REPLY" ]; do
listBegin "$title" "Choose at least one Linux-Vserver to backup:" listBegin "$title" "Choose at least one Linux-Vserver to backup:"
# list existing vservers, preselecting the previously selected ones # list existing vservers, preselecting the previously selected ones
for vserver in $found_vservers; do for vserver in $found_vservers; do
listItem "$vserver" "Backup $vserver vserver" `vserver_is_selected $vserver` listItem "$vserver" "Backup $vserver vserver" `vserver_is_selected $vserver`
done done
listDisplay checklist listDisplay checklist
[ $? = 0 ] || return 1 [ $? = 0 ] || return 1
done done
# remove quotes around each vserver name # remove quotes around each vserver name
selected_vservers=`echo $REPLY | tr -d '"'` selected_vservers=`echo $REPLY | tr -d '"'`

View File

@ -22,31 +22,31 @@
## FUNCTIONS ## FUNCTIONS
function setupcolors () { function setupcolors () {
BLUE="\033[34;01m" BLUE="\033[34;01m"
GREEN="\033[32;01m" GREEN="\033[32;01m"
YELLOW="\033[33;01m" YELLOW="\033[33;01m"
PURPLE="\033[35;01m" PURPLE="\033[35;01m"
RED="\033[31;01m" RED="\033[31;01m"
OFF="\033[0m" OFF="\033[0m"
CYAN="\033[36;01m" CYAN="\033[36;01m"
COLORS=($BLUE $GREEN $YELLOW $RED $PURPLE $CYAN) COLORS=($BLUE $GREEN $YELLOW $RED $PURPLE $CYAN)
} }
function colorize () { function colorize () {
if [ "$usecolors" == "yes" ]; then if [ "$usecolors" == "yes" ]; then
local typestr=`echo "$@" | @SED@ 's/\(^[^:]*\).*$/\1/'` local typestr=`echo "$@" | @SED@ 's/\(^[^:]*\).*$/\1/'`
[ "$typestr" == "Debug" ] && type=0 [ "$typestr" == "Debug" ] && type=0
[ "$typestr" == "Info" ] && type=1 [ "$typestr" == "Info" ] && type=1
[ "$typestr" == "Warning" ] && type=2 [ "$typestr" == "Warning" ] && type=2
[ "$typestr" == "Error" ] && type=3 [ "$typestr" == "Error" ] && type=3
[ "$typestr" == "Fatal" ] && type=4 [ "$typestr" == "Fatal" ] && type=4
[ "$typestr" == "Halt" ] && type=5 [ "$typestr" == "Halt" ] && type=5
color=${COLORS[$type]} color=${COLORS[$type]}
endcolor=$OFF endcolor=$OFF
echo -e "$color$@$endcolor" echo -e "$color$@$endcolor"
else else
echo -e "$@" echo -e "$@"
fi fi
} }
# We have the following message levels: # We have the following message levels:
@ -65,71 +65,71 @@ echo_debug_msg=0
usecolors=yes usecolors=yes
function printmsg() { function printmsg() {
[ ${#@} -gt 1 ] || return [ ${#@} -gt 1 ] || return
type=$1 type=$1
shift shift
if [ $type == 100 ]; then if [ $type == 100 ]; then
typestr=`echo "$@" | @SED@ 's/\(^[^:]*\).*$/\1/'` typestr=`echo "$@" | @SED@ 's/\(^[^:]*\).*$/\1/'`
[ "$typestr" == "Debug" ] && type=0 [ "$typestr" == "Debug" ] && type=0
[ "$typestr" == "Info" ] && type=1 [ "$typestr" == "Info" ] && type=1
[ "$typestr" == "Warning" ] && type=2 [ "$typestr" == "Warning" ] && type=2
[ "$typestr" == "Error" ] && type=3 [ "$typestr" == "Error" ] && type=3
[ "$typestr" == "Fatal" ] && type=4 [ "$typestr" == "Fatal" ] && type=4
[ "$typestr" == "Halt" ] && type=5 [ "$typestr" == "Halt" ] && type=5
typestr="" typestr=""
else else
types=(Debug Info Warning Error Fatal Halt) types=(Debug Info Warning Error Fatal Halt)
typestr="${types[$type]}: " typestr="${types[$type]}: "
fi fi
print=$[4-type] print=$[4-type]
if [ $echo_debug_msg == 1 ]; then if [ $echo_debug_msg == 1 ]; then
echo -e "$typestr$@" >&2 echo -e "$typestr$@" >&2
elif [ $debug ]; then elif [ $debug ]; then
colorize "$typestr$@" >&2 colorize "$typestr$@" >&2
fi fi
if [ $print -lt $loglevel ]; then if [ $print -lt $loglevel ]; then
logmsg "$typestr$@" logmsg "$typestr$@"
fi fi
} }
function logmsg() { function logmsg() {
if [ -w "$logfile" ]; then if [ -w "$logfile" ]; then
echo -e `LC_ALL=C date "+%h %d %H:%M:%S"` "$@" >> $logfile echo -e `LC_ALL=C date "+%h %d %H:%M:%S"` "$@" >> $logfile
fi fi
} }
function passthru() { function passthru() {
printmsg 100 "$@" printmsg 100 "$@"
} }
function debug() { function debug() {
printmsg 0 "$@" printmsg 0 "$@"
} }
function info() { function info() {
printmsg 1 "$@" printmsg 1 "$@"
} }
function warning() { function warning() {
printmsg 2 "$@" printmsg 2 "$@"
} }
function error() { function error() {
printmsg 3 "$@" printmsg 3 "$@"
} }
function fatal() { function fatal() {
printmsg 4 "$@" printmsg 4 "$@"
exit 2 exit 2
} }
function halt() { function halt() {
printmsg 5 "$@" printmsg 5 "$@"
exit 2 exit 2
} }
msgcount=0 msgcount=0
function msg { function msg {
messages[$msgcount]=$1 messages[$msgcount]=$1
let "msgcount += 1" let "msgcount += 1"
} }
# #
@ -158,7 +158,7 @@ function check_perms() {
echo "Configuration files must be owned by root! Dying on file $file" echo "Configuration files must be owned by root! Dying on file $file"
fatal "Configuration files must be owned by root! Dying on file $file" fatal "Configuration files must be owned by root! Dying on file $file"
fi fi
if [ "$wperm" != '---' ]; then if [ "$wperm" != '---' ]; then
echo "Configuration files must not be world writable/readable! Dying on file $file" echo "Configuration files must not be world writable/readable! Dying on file $file"
fatal "Configuration files must not be world writable/readable! Dying on file $file" fatal "Configuration files must not be world writable/readable! Dying on file $file"
@ -180,12 +180,12 @@ function check_perms() {
# simple lowercase function # simple lowercase function
function tolower() { function tolower() {
echo "$1" | tr '[:upper:]' '[:lower:]' echo "$1" | tr '[:upper:]' '[:lower:]'
} }
# simple to integer function # simple to integer function
function toint() { function toint() {
echo "$1" | tr -d '[:alpha:]' echo "$1" | tr -d '[:alpha:]'
} }
# #
@ -206,39 +206,39 @@ nowdayofweek=`LC_ALL=C date +%A`
nowdayofweek=`tolower "$nowdayofweek"` nowdayofweek=`tolower "$nowdayofweek"`
function isnow() { function isnow() {
local when="$1" local when="$1"
set -- $when set -- $when
[ "$when" == "manual" ] && return 0 [ "$when" == "manual" ] && return 0
whendayofweek=$1; at=$2; whentime=$3; whendayofweek=$1; at=$2; whentime=$3;
whenday=`toint "$whendayofweek"` whenday=`toint "$whendayofweek"`
whendayofweek=`tolower "$whendayofweek"` whendayofweek=`tolower "$whendayofweek"`
whentime=`echo "$whentime" | @SED@ 's/:[0-9][0-9]$//' | @SED@ -r 's/^([0-9])$/0\1/'` whentime=`echo "$whentime" | @SED@ 's/:[0-9][0-9]$//' | @SED@ -r 's/^([0-9])$/0\1/'`
if [ "$whendayofweek" == "everyday" -o "$whendayofweek" == "daily" ]; then if [ "$whendayofweek" == "everyday" -o "$whendayofweek" == "daily" ]; then
whendayofweek=$nowdayofweek whendayofweek=$nowdayofweek
fi fi
if [ "$whenday" == "" ]; then if [ "$whenday" == "" ]; then
if [ "$whendayofweek" != "$nowdayofweek" ]; then if [ "$whendayofweek" != "$nowdayofweek" ]; then
whendayofweek=${whendayofweek%s} whendayofweek=${whendayofweek%s}
if [ "$whendayofweek" != "$nowdayofweek" ]; then if [ "$whendayofweek" != "$nowdayofweek" ]; then
return 0 return 0
fi fi
fi fi
elif [ "$whenday" != "$nowday" ]; then elif [ "$whenday" != "$nowday" ]; then
return 0 return 0
fi fi
[ "$at" == "at" ] || return 0 [ "$at" == "at" ] || return 0
[ "$whentime" == "$nowtime" ] || return 0 [ "$whentime" == "$nowtime" ] || return 0
return 1 return 1
} }
function usage() { function usage() {
cat << EOF cat << EOF
$0 usage: $0 usage:
This script allows you to coordinate system backup by dropping a few This script allows you to coordinate system backup by dropping a few
simple configuration files into @CFGDIR@/backup.d/. Typically, this simple configuration files into @CFGDIR@/backup.d/. Typically, this
@ -257,18 +257,18 @@ The following options are available:
-n, --now Perform actions now, instead of when they might -n, --now Perform actions now, instead of when they might
be scheduled. No output will be created unless also be scheduled. No output will be created unless also
run with -d. run with -d.
--run FILE Execute the specified action file and then exit. --run FILE Execute the specified action file and then exit.
Also puts backupninja in debug mode. Also puts backupninja in debug mode.
When in debug mode, output to the console will be colored: When in debug mode, output to the console will be colored:
EOF EOF
usecolors=yes usecolors=yes
colorize "Debug: Debugging info (when run with -d)" colorize "Debug: Debugging info (when run with -d)"
colorize "Info: Informational messages (verbosity level 4)" colorize "Info: Informational messages (verbosity level 4)"
colorize "Warning: Warnings (verbosity level 3 and up)" colorize "Warning: Warnings (verbosity level 3 and up)"
colorize "Error: Errors (verbosity level 2 and up)" colorize "Error: Errors (verbosity level 2 and up)"
colorize "Fatal: Errors which halt a given backup action (always shown)" colorize "Fatal: Errors which halt a given backup action (always shown)"
colorize "Halt: Errors which halt the whole backupninja run (always shown)" colorize "Halt: Errors which halt the whole backupninja run (always shown)"
} }
## ##
@ -279,89 +279,89 @@ EOF
## ##
function process_action() { function process_action() {
local file="$1" local file="$1"
local suffix="$2" local suffix="$2"
local run="no" local run="no"
setfile $file setfile $file
# skip over this config if "when" option # skip over this config if "when" option
# is not set to the current time. # is not set to the current time.
getconf when "$defaultwhen" getconf when "$defaultwhen"
if [ "$processnow" == 1 ]; then if [ "$processnow" == 1 ]; then
info ">>>> starting action $file (because of --now)" info ">>>> starting action $file (because of --now)"
run="yes" run="yes"
elif [ "$when" == "hourly" ]; then elif [ "$when" == "hourly" ]; then
info ">>>> starting action $file (because 'when = hourly')" info ">>>> starting action $file (because 'when = hourly')"
run="yes" run="yes"
else else
IFS=$'\t\n' IFS=$'\t\n'
for w in $when; do for w in $when; do
IFS=$' \t\n' IFS=$' \t\n'
isnow "$w" isnow "$w"
ret=$? ret=$?
IFS=$'\t\n' IFS=$'\t\n'
if [ $ret == 0 ]; then if [ $ret == 0 ]; then
debug "skipping $file because current time does not match $w" debug "skipping $file because current time does not match $w"
else else
info ">>>> starting action $file (because current time matches $w)" info ">>>> starting action $file (because current time matches $w)"
run="yes" run="yes"
fi fi
done done
IFS=$' \t\n' IFS=$' \t\n'
fi fi
debug $run debug $run
[ "$run" == "no" ] && return [ "$run" == "no" ] && return
let "actions_run += 1"
# call the handler: let "actions_run += 1"
local bufferfile=`maketemp backupninja.buffer`
echo "" > $bufferfile
echo_debug_msg=1
(
. $scriptdirectory/$suffix $file
) 2>&1 | (
while read a; do
echo $a >> $bufferfile
[ $debug ] && colorize "$a"
done
)
retcode=$?
# ^^^^^^^^ we have a problem! we can't grab the return code "$?". grrr.
echo_debug_msg=0
_warnings=`cat $bufferfile | grep "^Warning: " | wc -l` # call the handler:
_errors=`cat $bufferfile | grep "^Error: " | wc -l` local bufferfile=`maketemp backupninja.buffer`
_fatals=`cat $bufferfile | grep "^Fatal: " | wc -l` echo "" > $bufferfile
_halts=`cat $bufferfile | grep "^Halt: " | wc -l` echo_debug_msg=1
(
ret=`grep "\(^Warning: \|^Error: \|^Fatal: \|Halt: \)" $bufferfile` . $scriptdirectory/$suffix $file
rm $bufferfile ) 2>&1 | (
if [ $_halts != 0 ]; then while read a; do
msg "*halt* -- $file" echo $a >> $bufferfile
errormsg="$errormsg\n== halt request from $file==\n\n$ret\n" [ $debug ] && colorize "$a"
passthru "Halt: <<<< finished action $file: FAILED" done
elif [ $_fatals != 0 ]; then )
msg "*failed* -- $file" retcode=$?
errormsg="$errormsg\n== fatal errors from $file ==\n\n$ret\n" # ^^^^^^^^ we have a problem! we can't grab the return code "$?". grrr.
passthru "Fatal: <<<< finished action $file: FAILED" echo_debug_msg=0
elif [ $_errors != 0 ]; then
msg "*error* -- $file"
errormsg="$errormsg\n== errors from $file ==\n\n$ret\n"
error "<<<< finished action $file: ERROR"
elif [ $_warnings != 0 ]; then
msg "*warning* -- $file"
errormsg="$errormsg\n== warnings from $file ==\n\n$ret\n"
warning "<<<< finished action $file: WARNING"
else
msg "success -- $file"
info "<<<< finished action $file: SUCCESS"
fi
let "halts += _halts" _warnings=`cat $bufferfile | grep "^Warning: " | wc -l`
let "fatals += _fatals" _errors=`cat $bufferfile | grep "^Error: " | wc -l`
let "errors += _errors" _fatals=`cat $bufferfile | grep "^Fatal: " | wc -l`
let "warnings += _warnings" _halts=`cat $bufferfile | grep "^Halt: " | wc -l`
ret=`grep "\(^Warning: \|^Error: \|^Fatal: \|Halt: \)" $bufferfile`
rm $bufferfile
if [ $_halts != 0 ]; then
msg "*halt* -- $file"
errormsg="$errormsg\n== halt request from $file==\n\n$ret\n"
passthru "Halt: <<<< finished action $file: FAILED"
elif [ $_fatals != 0 ]; then
msg "*failed* -- $file"
errormsg="$errormsg\n== fatal errors from $file ==\n\n$ret\n"
passthru "Fatal: <<<< finished action $file: FAILED"
elif [ $_errors != 0 ]; then
msg "*error* -- $file"
errormsg="$errormsg\n== errors from $file ==\n\n$ret\n"
error "<<<< finished action $file: ERROR"
elif [ $_warnings != 0 ]; then
msg "*warning* -- $file"
errormsg="$errormsg\n== warnings from $file ==\n\n$ret\n"
warning "<<<< finished action $file: WARNING"
else
msg "success -- $file"
info "<<<< finished action $file: SUCCESS"
fi
let "halts += _halts"
let "fatals += _fatals"
let "errors += _errors"
let "warnings += _warnings"
} }
##################################################### #####################################################
@ -374,71 +374,71 @@ loglevel=3
## process command line options ## process command line options
while [ $# -ge 1 ]; do while [ $# -ge 1 ]; do
case $1 in case $1 in
-h|--help) usage;; -h|--help) usage;;
-d|--debug) debug=1;; -d|--debug) debug=1;;
-t|--test) test=1;debug=1;; -t|--test) test=1;debug=1;;
-n|--now) processnow=1;; -n|--now) processnow=1;;
-f|--conffile) -f|--conffile)
if [ -f $2 ]; then if [ -f $2 ]; then
conffile=$2 conffile=$2
else else
echo "-f|--conffile option must be followed by an existing filename" echo "-f|--conffile option must be followed by an existing filename"
fatal "-f|--conffile option must be followed by an existing filename" fatal "-f|--conffile option must be followed by an existing filename"
usage usage
fi fi
# we shift here to avoid processing the file path # we shift here to avoid processing the file path
shift shift
;; ;;
--run) --run)
debug=1 debug=1
if [ -f $2 ]; then if [ -f $2 ]; then
singlerun=$2 singlerun=$2
processnow=1 processnow=1
else else
echo "--run option must be followed by a backupninja action file" echo "--run option must be followed by a backupninja action file"
fatal "--run option must be followed by a backupninja action file" fatal "--run option must be followed by a backupninja action file"
usage usage
fi fi
shift shift
;; ;;
*) *)
debug=1 debug=1
echo "Unknown option $1" echo "Unknown option $1"
fatal "Unknown option $1" fatal "Unknown option $1"
usage usage
exit exit
;; ;;
esac esac
shift shift
done done
#if [ $debug ]; then #if [ $debug ]; then
# usercolors=yes # usercolors=yes
#fi #fi
## Load and confirm basic configuration values ## Load and confirm basic configuration values
# bootstrap # bootstrap
if [ ! -r "$conffile" ]; then if [ ! -r "$conffile" ]; then
echo "Configuration file $conffile not found." echo "Configuration file $conffile not found."
fatal "Configuration file $conffile not found." fatal "Configuration file $conffile not found."
fi fi
# find $libdirectory # find $libdirectory
libdirectory=`grep '^libdirectory' $conffile | @AWK@ '{print $3}'` libdirectory=`grep '^libdirectory' $conffile | @AWK@ '{print $3}'`
if [ -z "$libdirectory" ]; then if [ -z "$libdirectory" ]; then
if [ -d "@libdir@" ]; then if [ -d "@libdir@" ]; then
libdirectory="@libdir@" libdirectory="@libdir@"
else else
echo "Could not find entry 'libdirectory' in $conffile." echo "Could not find entry 'libdirectory' in $conffile."
fatal "Could not find entry 'libdirectory' in $conffile." fatal "Could not find entry 'libdirectory' in $conffile."
fi fi
else else
if [ ! -d "$libdirectory" ]; then if [ ! -d "$libdirectory" ]; then
echo "Lib directory $libdirectory not found." echo "Lib directory $libdirectory not found."
fatal "Lib directory $libdirectory not found." fatal "Lib directory $libdirectory not found."
fi fi
fi fi
# include shared functions # include shared functions
@ -482,15 +482,15 @@ getconf admingroup root
init_vservers nodialog 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."
fi fi
[ -f "$logfile" ] || touch $logfile [ -f "$logfile" ] || touch $logfile
if [ "$UID" != "0" ]; then if [ "$UID" != "0" ]; then
echo "`basename $0` can only be run as root" echo "`basename $0` can only be run as root"
exit 1 exit 1
fi fi
## Process each configuration file ## Process each configuration file
@ -507,34 +507,34 @@ actions_run=0
errormsg="" errormsg=""
if [ "$singlerun" ]; then if [ "$singlerun" ]; then
files=$singlerun files=$singlerun
else else
files=`find $configdirectory -follow -mindepth 1 -maxdepth 1 -type f ! -name '.*.swp' | sort -n` files=`find $configdirectory -follow -mindepth 1 -maxdepth 1 -type f ! -name '.*.swp' | sort -n`
if [ -z "$files" ]; then if [ -z "$files" ]; then
fatal "No backup actions configured in '$configdirectory', run ninjahelper!" fatal "No backup actions configured in '$configdirectory', run ninjahelper!"
fi fi
fi fi
for file in $files; do for file in $files; do
[ -f "$file" ] || continue [ -f "$file" ] || continue
[ "$halts" = "0" ] || continue [ "$halts" = "0" ] || continue
check_perms ${file%/*} # check containing dir check_perms ${file%/*} # check containing dir
check_perms $file check_perms $file
suffix="${file##*.}" suffix="${file##*.}"
base=`basename $file` base=`basename $file`
if [ "${base:0:1}" == "0" -o "$suffix" == "disabled" ]; then if [ "${base:0:1}" == "0" -o "$suffix" == "disabled" ]; then
info "Skipping $file" info "Skipping $file"
continue continue
fi fi
if [ -e "$scriptdirectory/$suffix" ]; then if [ -e "$scriptdirectory/$suffix" ]; then
process_action $file $suffix process_action $file $suffix
else else
error "Can't process file '$file': no handler script for suffix '$suffix'" error "Can't process file '$file': no handler script for suffix '$suffix'"
msg "*missing handler* -- $file" msg "*missing handler* -- $file"
fi fi
done done
## mail the messages to the report address ## mail the messages to the report address
@ -549,38 +549,38 @@ else doit=0
fi fi
if [ $doit == 1 ]; then if [ $doit == 1 ]; then
debug "send report to $reportemail" debug "send report to $reportemail"
hostname=`hostname` hostname=`hostname`
[ $warnings == 0 ] || subject="WARNING" [ $warnings == 0 ] || subject="WARNING"
[ $errors == 0 ] || subject="ERROR" [ $errors == 0 ] || subject="ERROR"
[ $fatals == 0 ] || subject="FAILED" [ $fatals == 0 ] || subject="FAILED"
{ {
for ((i=0; i < ${#messages[@]} ; i++)); do for ((i=0; i < ${#messages[@]} ; i++)); do
echo ${messages[$i]} echo ${messages[$i]}
done done
echo -e "$errormsg" echo -e "$errormsg"
if [ "$reportspace" == "yes" ]; then if [ "$reportspace" == "yes" ]; then
previous="" previous=""
for i in $(ls "$configdirectory"); do for i in $(ls "$configdirectory"); do
backuploc=$(grep ^directory "$configdirectory"/"$i" | @AWK@ '{print $3}') backuploc=$(grep ^directory "$configdirectory"/"$i" | @AWK@ '{print $3}')
if [ "$backuploc" != "$previous" -a -n "$backuploc" ]; then if [ "$backuploc" != "$previous" -a -n "$backuploc" ]; then
df -h "$backuploc" df -h "$backuploc"
previous="$backuploc" previous="$backuploc"
fi fi
done done
fi fi
} | mail -s "backupninja: $hostname $subject" $reportemail } | mail -s "backupninja: $hostname $subject" $reportemail
fi fi
if [ $actions_run != 0 ]; then if [ $actions_run != 0 ]; then
info "FINISHED: $actions_run actions run. $fatals fatal. $errors error. $warnings warning." info "FINISHED: $actions_run actions run. $fatals fatal. $errors error. $warnings warning."
if [ "$halts" != "0" ]; then if [ "$halts" != "0" ]; then
info "Backup was halted prematurely. Some actions may not have run." info "Backup was halted prematurely. Some actions may not have run."
fi fi
fi fi
if [ -n "$reporthost" ]; then if [ -n "$reporthost" ]; then
debug "send $logfile to $reportuser@$reporthost:$reportdirectory" debug "send $logfile to $reportuser@$reporthost:$reportdirectory"
rsync -qt $logfile $reportuser@$reporthost:$reportdirectory rsync -qt $logfile $reportuser@$reporthost:$reportdirectory
fi fi

View File

@ -27,7 +27,7 @@ get_next_filename() {
require_packages() { require_packages() {
for pkg in "$@"; do for pkg in "$@"; do
installed=`dpkg -s $pkg | grep 'ok installed'` installed=`dpkg -s $pkg | grep 'ok installed'`
if [ -z "$installed" ]; then if [ -z "$installed" ]; then
booleanBox "install $pkg?" "This backup action requires package $pkg. Do you want to install it now?" booleanBox "install $pkg?" "This backup action requires package $pkg. Do you want to install it now?"
if [ $? = 0 ]; then if [ $? = 0 ]; then
apt-get install $pkg apt-get install $pkg
@ -54,7 +54,7 @@ donew() {
listItem $helper_function "$helper_info" listItem $helper_function "$helper_info"
done done
listDisplay menu listDisplay menu
[ $? = 1 ] && return [ $? = 1 ] && return
result="$REPLY" result="$REPLY"
[ "$result" = "return" -o "$result" = "" ] && return [ "$result" = "return" -o "$result" = "" ] && return
@ -62,10 +62,10 @@ donew() {
$run_wizard $run_wizard
result=$? result=$?
# 0 is ok, 1 is cancel, anything else is bad. # 0 is ok, 1 is cancel, anything else is bad.
if [ $result != 1 -a $result != 0 ]; then if [ $result != 1 -a $result != 0 ]; then
echo "An error occurred ($result), bailing out. Hit return to continue." echo "An error occurred ($result), bailing out. Hit return to continue."
read read
fi fi
} }
do_rm_action() { do_rm_action() {
@ -84,17 +84,17 @@ do_run() {
do_xedit() { do_xedit() {
if [ -z "$EDITOR" -o ! -x "`which $EDITOR`" ]; then if [ -z "$EDITOR" -o ! -x "`which $EDITOR`" ]; then
if [ -h /etc/alternatives/editor -a -x "`readlink /etc/alternatives/editor`" ]; then if [ -h /etc/alternatives/editor -a -x "`readlink /etc/alternatives/editor`" ]; then
EDITOR="`readlink /etc/alternatives/editor`" EDITOR="`readlink /etc/alternatives/editor`"
elif [ -x "`which nano`" ]; then elif [ -x "`which nano`" ]; then
EDITOR="`which nano`" EDITOR="`which nano`"
elif [ -x "`which vim`" ]; then elif [ -x "`which vim`" ]; then
EDITOR="`which vim`" EDITOR="`which vim`"
elif [ -x "`which vi`" ]; then elif [ -x "`which vi`" ]; then
EDITOR="`which vi`" EDITOR="`which vi`"
else else
echo "No suitable editor found." echo "No suitable editor found."
echo "Please define $EDITOR or configure /etc/alternatives/editor." echo "Please define $EDITOR or configure /etc/alternatives/editor."
exit exit
fi fi
fi fi
$EDITOR $1 $EDITOR $1
@ -138,17 +138,17 @@ doaction() {
name "change the filename" \ name "change the filename" \
run "run this action now" \ run "run this action now" \
test "do a test run" \ test "do a test run" \
kill "remove this action" kill "remove this action"
[ $? = 1 ] && return; [ $? = 1 ] && return;
result="$REPLY" result="$REPLY"
case "$result" in case "$result" in
"view") dialog --textbox $action 0 0;; "view") dialog --textbox $action 0 0;;
"xedit") do_xedit $action;; "xedit") do_xedit $action;;
"disable") do_disable $action; return;; "disable") do_disable $action; return;;
"enable") do_enable $action; return;; "enable") do_enable $action; return;;
"name") do_rename $action; return;; "name") do_rename $action; return;;
"run") do_run $action;; "run") do_run $action;;
"test") do_run_test $action;; "test") do_run_test $action;;
"kill") do_rm_action $action; return;; "kill") do_rm_action $action; return;;
"main") return;; "main") return;;
esac esac
@ -178,7 +178,7 @@ fi
# bootstrap # bootstrap
conffile="@CFGDIR@/backupninja.conf" conffile="@CFGDIR@/backupninja.conf"
if [ ! -r "$conffile" ]; then if [ ! -r "$conffile" ]; then
echo "Configuration file $conffile not found." echo "Configuration file $conffile not found."
exit 1 exit 1
fi fi
@ -188,12 +188,12 @@ if [ -z "$libdirectory" ]; then
if [ -d "@libdir@" ]; then if [ -d "@libdir@" ]; then
libdirectory="@libdir@" libdirectory="@libdir@"
else else
echo "Could not find entry 'libdirectory' in $conffile." echo "Could not find entry 'libdirectory' in $conffile."
exit 1 exit 1
fi fi
else else
if [ ! -d "$libdirectory" ]; then if [ ! -d "$libdirectory" ]; then
echo "Lib directory $libdirectory not found." echo "Lib directory $libdirectory not found."
exit 1 exit 1
fi fi
fi fi
@ -247,7 +247,7 @@ done
menuBox "main menu" "Select a backup action for more options, or create a new action:" $menulist \ menuBox "main menu" "Select a backup action for more options, or create a new action:" $menulist \
new "create a new backup action" \ new "create a new backup action" \
quit "leave ninjahelper" quit "leave ninjahelper"
[ $? = 1 -o $? = 255 ] && exit 0; [ $? = 1 -o $? = 255 ] && exit 0;

View File

@ -13,7 +13,7 @@
# . check for logs that are never updating and warn # . check for logs that are never updating and warn
# . change constantly updating logs (maildir) to be more friendly # . change constantly updating logs (maildir) to be more friendly
# . documentation # . documentation
# . maybe make config option that lists all hosts that should report-in, and if # . maybe make config option that lists all hosts that should report-in, and if
# one doesn't then warn # one doesn't then warn
# . restrict rsync somehow? # . restrict rsync somehow?
# . abstract path for logtail # . abstract path for logtail
@ -29,7 +29,7 @@ process() {
# #
# note: some backups never finish, such as the maildir one, need to handle these # note: some backups never finish, such as the maildir one, need to handle these
# perhaps by looking for FAILED messages? # perhaps by looking for FAILED messages?
# note2: what about logs that aren't being updated? this is a failure case and # note2: what about logs that aren't being updated? this is a failure case and
# should be looked for # should be looked for
# note3: there are also these entries: # note3: there are also these entries:
# Jan 20 14:00:01 Fatal: No backup actions configured in '/etc/backup.d', run ninjahelper! # Jan 20 14:00:01 Fatal: No backup actions configured in '/etc/backup.d', run ninjahelper!
@ -38,27 +38,27 @@ process() {
logupdates=`maketemp ninjadata` logupdates=`maketemp ninjadata`
/usr/sbin/logtail -f $host > $logupdates /usr/sbin/logtail -f $host > $logupdates
grep FINISHED $logupdates | grep FINISHED $logupdates |
( (
fatal=0 fatal=0
warning=0 warning=0
error=0 error=0
while read line while read line
do do
line_array=($line) line_array=($line)
fatal=$(($fatal + ${line_array[8]})) fatal=$(($fatal + ${line_array[8]}))
error=$(($error + ${line_array[10]})) error=$(($error + ${line_array[10]}))
warning=$(($warning + ${line_array[12]})) warning=$(($warning + ${line_array[12]}))
done done
if (( $fatal || $warning || $error )); then if (( $fatal || $warning || $error )); then
echo "`basename $host .log`: $fatal fatals found, $error errors found, $warning warnings found" >> $statusfile echo "`basename $host .log`: $fatal fatals found, $error errors found, $warning warnings found" >> $statusfile
echo "" >> $reportappend echo "" >> $reportappend
echo "`basename $host .log` log entries since last ninjareport" >> $reportappend echo "`basename $host .log` log entries since last ninjareport" >> $reportappend
echo "---------" >> $reportappend echo "---------" >> $reportappend
cat $logupdates >> $reportappend cat $logupdates >> $reportappend
rm $logupdates rm $logupdates
fi fi
) )
} }
@ -69,31 +69,31 @@ reportfile=`maketemp ninjareport`
# Generate a report, only if there are failures # Generate a report, only if there are failures
if [ -s $statusfile ]; then if [ -s $statusfile ]; then
echo " backupninja mission failures - `date`" >> $reportfile echo " backupninja mission failures - `date`" >> $reportfile
echo " --------------------------------------------------------------" >> $reportfile echo " --------------------------------------------------------------" >> $reportfile
echo "" >> $reportfile echo "" >> $reportfile
cat $statusfile | column -t >> $reportfile cat $statusfile | column -t >> $reportfile
echo "" >> $reportfile echo "" >> $reportfile
echo " log entries from failed reports" >> $reportfile echo " log entries from failed reports" >> $reportfile
echo " -----------------------------------" >> $reportfile echo " -----------------------------------" >> $reportfile
cat $reportappend >> $reportfile cat $reportappend >> $reportfile
fi fi
} }
usage() { usage() {
cat << EOF cat << EOF
This script generates a backupninja status report for all configured This script generates a backupninja status report for all configured
systems. It requires that each status report is placed in a spot where systems. It requires that each status report is placed in a spot where
ninjareport can read it, reports are mailed to the reportemail ninjareport can read it, reports are mailed to the reportemail
configured in @CFGDIR@/backupninja.conf. configured in @CFGDIR@/backupninja.conf.
The following options are available: The following options are available:
-h, --help This usage message -h, --help This usage message
-f, --conffile FILE Use FILE for the configuration instead -f, --conffile FILE Use FILE for the configuration instead
of @CFGDIR@/backupninja.conf of @CFGDIR@/backupninja.conf
-m, --mail <email> Mail the report to this address -m, --mail <email> Mail the report to this address
-o, --out Don't mail the report, just display it -o, --out Don't mail the report, just display it
EOF EOF
} }
@ -106,45 +106,45 @@ conffile="@CFGDIR@/backupninja.conf"
## process command line options ## process command line options
while [ $# -ge 1 ]; do while [ $# -ge 1 ]; do
case $1 in case $1 in
-h|--help) -h|--help)
usage usage
exit 0 exit 0
;; ;;
-f|--conffile) -f|--conffile)
if [ -f $2 ]; then if [ -f $2 ]; then
conffile=$2 conffile=$2
else else
echo "-f|--conffile option must be followed by an existing filename" echo "-f|--conffile option must be followed by an existing filename"
fatal "-f|--conffile option must be followed by an existing filename" fatal "-f|--conffile option must be followed by an existing filename"
usage usage
fi fi
# we shift here to avoid processing the file path # we shift here to avoid processing the file path
shift shift
;; ;;
-m|--mail) -m|--mail)
reportemail=$2 reportemail=$2
shift shift
;; ;;
-o|--out) -o|--out)
mail=0 mail=0
display=1 display=1
;; ;;
*) *)
echo "Unknown option $1" echo "Unknown option $1"
usage usage
exit exit
;; ;;
esac esac
shift shift
done done
## Load and confirm basic configuration values ## Load and confirm basic configuration values
# bootstrap # bootstrap
if [ ! -r "$conffile" ]; then if [ ! -r "$conffile" ]; then
echo "Configuration file $conffile not found." echo "Configuration file $conffile not found."
fatal "Configuration file $conffile not found." fatal "Configuration file $conffile not found."
fi fi
# find $libdirectory # find $libdirectory
@ -153,12 +153,12 @@ if [ -z "$libdirectory" ]; then
if [ -d "@libdir@" ]; then if [ -d "@libdir@" ]; then
libdirectory="@libdir@" libdirectory="@libdir@"
else else
echo "Could not find entry 'libdirectory' in $conffile." echo "Could not find entry 'libdirectory' in $conffile."
exit 1 exit 1
fi fi
else else
if [ ! -d "$libdirectory" ]; then if [ ! -d "$libdirectory" ]; then
echo "Lib directory $libdirectory not found." echo "Lib directory $libdirectory not found."
exit 1 exit 1
fi fi
fi fi
@ -176,17 +176,17 @@ getconf reportemail
hosts=`find $reportdirectory -follow -mindepth 1 -maxdepth 1 -type f ! -name '*.offset' | sort -n` hosts=`find $reportdirectory -follow -mindepth 1 -maxdepth 1 -type f ! -name '*.offset' | sort -n`
if [ -z "$hosts" ]; then if [ -z "$hosts" ]; then
echo "Fatal: No backupninja reports found in '$reportdirectory'!" echo "Fatal: No backupninja reports found in '$reportdirectory'!"
mail=0 mail=0
fi fi
statusfile=`maketemp ninjastatus` statusfile=`maketemp ninjastatus`
reportappend=`maketemp ninjaappend` reportappend=`maketemp ninjaappend`
for host in $hosts; do for host in $hosts; do
[ -f "$host" ] || continue [ -f "$host" ] || continue
# Check somehow that the file is a valid report file # Check somehow that the file is a valid report file
process $host process $host
done done
generatereport generatereport
@ -194,12 +194,11 @@ generatereport
## mail the report to the report address or display it ## mail the report to the report address or display it
if [ -s $reportfile ]; then if [ -s $reportfile ]; then
if [ $mail == 1 ]; then if [ $mail == 1 ]; then
mail -s "backupninja mission failure report" $reportemail < $reportfile mail -s "backupninja mission failure report" $reportemail < $reportfile
fi fi
fi fi
if [ $display == 1 ]; then if [ $display == 1 ]; then
cat $reportfile cat $reportfile
fi fi