diff options
Diffstat (limited to 'lib/beam/common.in')
-rw-r--r-- | lib/beam/common.in | 264 |
1 files changed, 132 insertions, 132 deletions
diff --git a/lib/beam/common.in b/lib/beam/common.in index 4f2184b..94b4565 100644 --- a/lib/beam/common.in +++ b/lib/beam/common.in @@ -34,111 +34,111 @@ backup_pidfile="/var/run/beam.pid" backup_tmp_dir=/tmp error() { - echo >&2 $0: $* + echo >&2 $0: $* } logit() { - echo `date`: $* + echo `date`: $* } abend() { - ec=$1 - shift - error $@ - exit $ec + ec=$1 + shift + error $@ + exit $ec } beam_lock() { - if [ -r $backup_pidfile ]; then + if [ -r $backup_pidfile ]; then pid=$(head -n 1 $backup_pidfile) if [ -z "$pid" ]; then - abend 1 "pidfile $backup_pidfile exists but is unreadable or empty" + abend 1 "pidfile $backup_pidfile exists but is unreadable or empty" fi abend 1 "another beam process (pid $pid) is still running; exiting" - fi - echo $$ > $backup_pidfile || exit 1 - epilogue_hook="$epilogue_hook beam_unlock" + fi + echo $$ > $backup_pidfile || exit 1 + epilogue_hook="$epilogue_hook beam_unlock" } beam_unlock() { - rm -f $backup_pidfile + rm -f $backup_pidfile } tarcode() { - case $1 in - 0) logit "success";; - 1) logit "some files changed while being archived";; - 2) logit "fatal error occurred, but trying to continue anyway" - tarerror=$((tarerror + 1));; - *) logit "unexpected error code $1" - tarerror=$((tarerror + 1)); - esac + case $1 in + 0) logit "success";; + 1) logit "some files changed while being archived";; + 2) logit "fatal error occurred, but trying to continue anyway" + tarerror=$((tarerror + 1));; + *) logit "unexpected error code $1" + tarerror=$((tarerror + 1)); + esac } load_config() { - local delayed_exit remote - - test -z "$BEAM_CONFIG" && BEAM_CONFIG=@SYSCONFDIR@/beam.conf - if [ -r $BEAM_CONFIG ]; then - . $BEAM_CONFIG - else - abend 1 "configuration file $BEAM_CONFIG does not exist or is unreadable" - fi + local delayed_exit remote - if [ -z "$backup_items" ]; then - abend 1 "backup_items not specified" - fi - - if [ -z "$backup_archive_dir" ]; then - if [ -n "$backup_bucket_name" ]; then - backup_archive_dir=$backup_mp_s3 + test -z "$BEAM_CONFIG" && BEAM_CONFIG=@SYSCONFDIR@/beam.conf + if [ -r $BEAM_CONFIG ]; then + . $BEAM_CONFIG else - abend 1 "backup_archive_dir not set" + abend 1 "configuration file $BEAM_CONFIG does not exist or is unreadable" fi - fi - - delayed_exit= - loaded_types= - for item in $backup_items - do - eval type=\$${item}_type - if [ -z "$type" ]; then - error "${item}_type not set" - delayed_exit=1 - continue + + if [ -z "$backup_items" ]; then + abend 1 "backup_items not specified" fi + + if [ -z "$backup_archive_dir" ]; then + if [ -n "$backup_bucket_name" ]; then + backup_archive_dir=$backup_mp_s3 + else + abend 1 "backup_archive_dir not set" + fi + fi + + delayed_exit= + loaded_types= + for item in $backup_items + do + eval type=\$${item}_type + if [ -z "$type" ]; then + error "${item}_type not set" + delayed_exit=1 + continue + fi - if echo "$loaded_types" | grep -wq $type; then - : - elif [ -x $libdir/${type}.sh ]; then - . $libdir/${type}.sh || delayed_exit=1 - loaded_types="$loaded_files + if echo "$loaded_types" | grep -wq $type; then + : + elif [ -x $libdir/${type}.sh ]; then + . $libdir/${type}.sh || delayed_exit=1 + loaded_types="$loaded_files $type" - else - error "$libdir/${type}.sh not found" - delayed_exit=1 - fi + else + error "$libdir/${type}.sh not found" + delayed_exit=1 + fi - ${type}_check $item || delayed_exit=1 - done + ${type}_check $item || delayed_exit=1 + done - test -n "$delayed_exit" && abend 1 "aborting" + test -n "$delayed_exit" && abend 1 "aborting" - tar_suffix=${backup_suffix:-.tar} + tar_suffix=${backup_suffix:-.tar} - if [ -n "$backup_bucket_name" ]; then - . @LIBDIR@/beam/s3.sh - prologue_hook="s3_mount $prologue_hook" - fi + if [ -n "$backup_bucket_name" ]; then + . @LIBDIR@/beam/s3.sh + prologue_hook="s3_mount $prologue_hook" + fi - remote=${backup_archive_dir%%:*} - if [ "$remote" != "$backup_archive_dir" ]; then - beam_rsh="${backup_rsh:-ssh} $remote" - backup_local_archive_dir=${backup_archive_dir#*:} - else - beam_rsh= - backup_local_archive_dir=$backup_archive_dir - fi + remote=${backup_archive_dir%%:*} + if [ "$remote" != "$backup_archive_dir" ]; then + beam_rsh="${backup_rsh:-ssh} $remote" + backup_local_archive_dir=${backup_archive_dir#*:} + else + beam_rsh= + backup_local_archive_dir=$backup_archive_dir + fi } beam_exec() { @@ -152,67 +152,67 @@ beam_exec() { } runhook() { - local hook_list + local hook_list - eval hook_list=\$$1 - for hook in $hook_list - do - $hook - done + eval hook_list=\$$1 + for hook in $hook_list + do + $hook + done } print_version() { - name=$(basename $0) - cat <<EOF + name=$(basename $0) + cat <<EOF $name (@PACKAGE_NAME@) @PACKAGE_VERSION@ Copyright (C) 2012 Sergey Poznyakoff License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. EOF - exit 0 + exit 0 } wtf() { - l=`echo "${1#beam-}"|sed "s|.|.|g"` - s=$(echo " " | sed "s|$l|${1#beam-}|") - shift - echo " $s $@" + l=$(echo "${1#beam-}"|sed "s|.|.|g") + s=$(echo " " | sed "s|$l|${1#beam-}|") + shift + echo " $s $@" } dry_mail() { - echo "=============================================================" - cat - - echo "=============================================================" + echo "=============================================================" + cat - + echo "=============================================================" } # mail_report FILE mail_report() { - : ${backup_mailer_program:=/usr/sbin/sendmail -oi -t -F $backup_sender_email} - if [ -n "$dry_run" ]; then - echo "Sending mail using $backup_mailer_program" - backup_mailer_program=dry_mail - fi - if [ -z "$backup_sender_email" ]; then - backup_sender_email=root@$(hostname) - fi - case $backup_sender_email in - "<"*) ;; - *) backup_sender_email="<$backup_sender_email>" - esac - if [ -n "$backup_sender_personal" ]; then - case $backup_sender_personal in - \"*) ;; - *) backup_sender_personal="\"$backup_sender_personal\"" + : ${backup_mailer_program:=/usr/sbin/sendmail -oi -t -F $backup_sender_email} + if [ -n "$dry_run" ]; then + echo "Sending mail using $backup_mailer_program" + backup_mailer_program=dry_mail + fi + if [ -z "$backup_sender_email" ]; then + backup_sender_email=root@$(hostname) + fi + case $backup_sender_email in + "<"*) ;; + *) backup_sender_email="<$backup_sender_email>" esac - backup_sender_personal="$backup_sender_personal " - fi - if [ -z "$backup_report_subject" ]; then - backup_report_subject="Backup of $(hostname) on $(date)" - fi - test -n "$backup_report_signature" && - echo "$backup_report_signature" >> $report - (cat - <<EOF + if [ -n "$backup_sender_personal" ]; then + case $backup_sender_personal in + \"*) ;; + *) backup_sender_personal="\"$backup_sender_personal\"" + esac + backup_sender_personal="$backup_sender_personal " + fi + if [ -z "$backup_report_subject" ]; then + backup_report_subject="Backup of $(hostname) on $(date)" + fi + test -n "$backup_report_signature" && + echo "$backup_report_signature" >> $report + (cat - <<EOF From: ${backup_sender_personal}$backup_sender_email To: $backup_notify_email Subject: $backup_report_subject @@ -220,34 +220,34 @@ X-Beam-Items: $backup_items X-Beam-Round: $round X-Beam-Level: $level EOF - if [ -n "$backup_report_headers" ]; then - echo "$backup_report_headers" - fi - echo "" - if [ -n "$backup_report_intro" ]; then - echo "$backup_report_intro" - fi - cat $report -) | $backup_mailer_program + if [ -n "$backup_report_headers" ]; then + echo "$backup_report_headers" + fi + echo "" + if [ -n "$backup_report_intro" ]; then + echo "$backup_report_intro" + fi + cat $report + ) | $backup_mailer_program } beam_logrotate() { - local conf=/tmp/beam-logrotate.conf u - if test -z "$backup_logrotate_conf"; then - backup_logrotate_conf="weekly + local conf=/tmp/beam-logrotate.conf u + if test -z "$backup_logrotate_conf"; then + backup_logrotate_conf="weekly rotate 4 " - fi - u=$(umask) - umask 077 - cat > $conf <<EOF + fi + u=$(umask) + umask 077 + cat > $conf <<EOF $backup_logfile { $backup_logrotate_conf missingok } EOF - umask $u - test -d @LOCALSTATEDIR@/lib/beam || mkdir @LOCALSTATEDIR@/lib/beam - logrotate ${dry_run+-d} $verbose --state @LOCALSTATEDIR@/lib/beam/logrotate.state $conf - rm $conf + umask $u + test -d @LOCALSTATEDIR@/lib/beam || mkdir @LOCALSTATEDIR@/lib/beam + logrotate ${dry_run+-d} $verbose --state @LOCALSTATEDIR@/lib/beam/logrotate.state $conf + rm $conf } |