aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2014-03-19 07:44:16 +0200
committerSergey Poznyakoff <gray@gnu.org>2014-03-19 07:44:16 +0200
commit22cddd5c61d150584a065c1a5e6963e8e95a43cb (patch)
tree86859e8dc93677226d668cd20a71f805d99181eb /lib
parent10d30373c6fdf0dd23f16251fa2302c18b7eef97 (diff)
downloadbeam-22cddd5c61d150584a065c1a5e6963e8e95a43cb.tar.gz
beam-22cddd5c61d150584a065c1a5e6963e8e95a43cb.tar.bz2
Use uniform indentation, add missing copyleft headers, update years.
Diffstat (limited to 'lib')
-rw-r--r--lib/beam/Makefile.am2
-rw-r--r--lib/beam/common.in264
-rwxr-xr-xlib/beam/fs.sh186
-rwxr-xr-xlib/beam/ldap.sh2
-rwxr-xr-xlib/beam/postgres.sh106
-rw-r--r--lib/beam/s3.sh114
6 files changed, 338 insertions, 336 deletions
diff --git a/lib/beam/Makefile.am b/lib/beam/Makefile.am
index 22c9a12..81385ad 100644
--- a/lib/beam/Makefile.am
+++ b/lib/beam/Makefile.am
@@ -1,5 +1,5 @@
# This file is part of BEAM
-# Copyright (C) 2012 Sergey Poznyakoff
+# Copyright (C) 2012-2014 Sergey Poznyakoff
#
# BEAM is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
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
}
diff --git a/lib/beam/fs.sh b/lib/beam/fs.sh
index b4d0c2d..015082b 100755
--- a/lib/beam/fs.sh
+++ b/lib/beam/fs.sh
@@ -1,6 +1,6 @@
#! /bin/sh
# This file is part of BEAM
-# Copyright (C) 2012 Sergey Poznyakoff
+# Copyright (C) 2012-2014 Sergey Poznyakoff
#
# BEAM is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -28,121 +28,121 @@
# initdb item
# Initializes snapshot for the given basename.
initdb() {
- local filename
-
- if [ -n "$dry_run" ]; then
- logit "initializing snapshot for $1"
- return
- fi
-
- if [ $level -eq 0 ]; then
- filename=$backup_snapshot_dir/$1-$week-$round-$level.db
- test -r $filename && rm $filename
- else
- if [ $level -eq 1 ]; then
- filename=$backup_snapshot_dir/$1-$week-0-0.db
- else
- filename=$backup_snapshot_dir/$1-$week-$round-$((level - 1)).db
+ local filename
+
+ if [ -n "$dry_run" ]; then
+ logit "initializing snapshot for $1"
+ return
fi
- if [ -r $filename ]; then
- cp $filename $backup_snapshot_dir/$1-$week-$round-$level.db
- else
- logit "previous snapshot file $filename not found; falling back to level 0"
- filename=$backup_snapshot_dir/$1-$week-$round-$level.db
- test -r $filename && rm $filename
+
+ if [ $level -eq 0 ]; then
+ filename=$backup_snapshot_dir/$1-$week-$round-$level.db
+ test -r $filename && rm $filename
+ else
+ if [ $level -eq 1 ]; then
+ filename=$backup_snapshot_dir/$1-$week-0-0.db
+ else
+ filename=$backup_snapshot_dir/$1-$week-$round-$((level - 1)).db
+ fi
+ if [ -r $filename ]; then
+ cp $filename $backup_snapshot_dir/$1-$week-$round-$level.db
+ else
+ logit "previous snapshot file $filename not found; falling back to level 0"
+ filename=$backup_snapshot_dir/$1-$week-$round-$level.db
+ test -r $filename && rm $filename
+ fi
fi
- fi
}
# fs_check item
fs_check() {
- local rc=0 root files
+ local rc=0 root files
- eval root=\$${1}_dir
- eval files=\$${1}_files
+ eval root=\$${1}_dir
+ eval files=\$${1}_files
- test -z "$root" && rc=1 && error "${1}_dir not set"
- test -z "$files" && rc=1 && error "${1}_files not set"
- return $rc
+ test -z "$root" && rc=1 && error "${1}_dir not set"
+ test -z "$files" && rc=1 && error "${1}_files not set"
+ return $rc
}
# fs_list item prefix
fs_list() {
- local dir files lsf=
+ local dir files lsf=
- eval dir=\$${1}_dir files=\$${1}_files
- for file in $files
- do
- if [ -d "$dir/$file" ]; then
- lsf="$lsf $file/"
- else
- lsf="$lsf $file"
- fi
- done
- echo "${2}Files and directories in $dir:$lsf"
+ eval dir=\$${1}_dir files=\$${1}_files
+ for file in $files
+ do
+ if [ -d "$dir/$file" ]; then
+ lsf="$lsf $file/"
+ else
+ lsf="$lsf $file"
+ fi
+ done
+ echo "${2}Files and directories in $dir:$lsf"
}
# fs_backup item
fs_backup() {
- local basename text root files exclude addopts s e
-
- basename=$1-$week-$round-$level
- eval text=\$${1}_text
- eval root=\$${1}_dir
- eval files=\$${1}_files
- eval addopts=\$${1}_tar_options
-
- eval exclude=\$${1}_exclude
- for e in $exclude
- do
- eval s="$e"
- addopts="$addopts --exclude=$s"
- done
-
- eval exclude=\$${1}_exclude_from
- for e in $exclude
- do
- addopts="$addopts --exclude-from=$e"
- done
-
- test -z "$root" && abend 1 "${1}_dir not set"
- test -z "$files" && abend 1 "${1}_files not set"
- test -z "$text" && text="$1"
- initdb $1
- logit "backing up $text ($basename.$tar_suffix)"
- $dry_run tar $verbose $taroptions $addopts \
- -f $backup_archive_dir/$basename.$tar_suffix \
- --listed=$backup_snapshot_dir/$basename.db \
- -C $root $files
- tarcode $?
+ local basename text root files exclude addopts s e
+
+ basename=$1-$week-$round-$level
+ eval text=\$${1}_text
+ eval root=\$${1}_dir
+ eval files=\$${1}_files
+ eval addopts=\$${1}_tar_options
+
+ eval exclude=\$${1}_exclude
+ for e in $exclude
+ do
+ eval s="$e"
+ addopts="$addopts --exclude=$s"
+ done
+
+ eval exclude=\$${1}_exclude_from
+ for e in $exclude
+ do
+ addopts="$addopts --exclude-from=$e"
+ done
+
+ test -z "$root" && abend 1 "${1}_dir not set"
+ test -z "$files" && abend 1 "${1}_files not set"
+ test -z "$text" && text="$1"
+ initdb $1
+ logit "backing up $text ($basename.$tar_suffix)"
+ $dry_run tar $verbose $taroptions $addopts \
+ -f $backup_archive_dir/$basename.$tar_suffix \
+ --listed=$backup_snapshot_dir/$basename.db \
+ -C $root $files
+ tarcode $?
}
# fs_restore item
fs_restore() {
- local i text root files tarcommand
-
- eval text=\$${1}_text
- eval root=\$${1}_dir
- eval files=\$${1}_files
-
- test -z "$root" && abend 1 "${1}_dir not set"
- test -z "$files" && abend 1 "${1}_files not set"
- test -z "$text" && text="$1"
-
- tarcommand="tar $verbose $taroptions -C $root --listed-incremental=/dev/null -f"
+ local i text root files tarcommand
+
+ eval text=\$${1}_text
+ eval root=\$${1}_dir
+ eval files=\$${1}_files
+
+ test -z "$root" && abend 1 "${1}_dir not set"
+ test -z "$files" && abend 1 "${1}_files not set"
+ test -z "$text" && text="$1"
+
+ tarcommand="tar $verbose $taroptions -C $root --listed-incremental=/dev/null -f"
- logit "restoring $text"
- logit "restoring from level 0 backup"
-
- $dry_run $tarcommand $backup_archive_dir/$1-$week-0-0.$tar_suffix
- tarcode $?
+ logit "restoring $text"
+ logit "restoring from level 0 backup"
- for i in $(seq 1 $level)
- do
- logit "restoring from the $round/$i backup"
- $dry_run $tarcommand $backup_archive_dir/$1-$week-$round-$i.$tar_suffix
+ $dry_run $tarcommand $backup_archive_dir/$1-$week-0-0.$tar_suffix
tarcode $?
- done
- logit "finished restoring $text"
+
+ for i in $(seq 1 $level)
+ do
+ logit "restoring from the $round/$i backup"
+ $dry_run $tarcommand $backup_archive_dir/$1-$week-$round-$i.$tar_suffix
+ tarcode $?
+ done
+ logit "finished restoring $text"
}
diff --git a/lib/beam/ldap.sh b/lib/beam/ldap.sh
index f6e56b8..40b9a4b 100755
--- a/lib/beam/ldap.sh
+++ b/lib/beam/ldap.sh
@@ -1,6 +1,6 @@
#! /bin/sh
# This file is part of BEAM
-# Copyright (C) 2012 Sergey Poznyakoff
+# Copyright (C) 2012-2014 Sergey Poznyakoff
#
# BEAM is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
diff --git a/lib/beam/postgres.sh b/lib/beam/postgres.sh
index b5a9b6e..3938c1a 100755
--- a/lib/beam/postgres.sh
+++ b/lib/beam/postgres.sh
@@ -1,6 +1,6 @@
#! /bin/sh
# This file is part of BEAM
-# Copyright (C) 2012 Sergey Poznyakoff
+# Copyright (C) 2012-2014 Sergey Poznyakoff
#
# BEAM is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -22,81 +22,81 @@
# postgres_check item
postgres_check() {
- local database
+ local database
- eval database=\$${1}_database
- test -z "$database" && error "${1}_database not set" && return 1
- return 0
+ eval database=\$${1}_database
+ test -z "$database" && error "${1}_database not set" && return 1
+ return 0
}
# postgres_list item prefix
postgres_list() {
- local database
+ local database
- eval database=\$${1}_database
- echo "${2}PostgreSQL database $database"
+ eval database=\$${1}_database
+ echo "${2}PostgreSQL database $database"
}
# postgres_backup item
postgres_backup() {
- local database
+ local database
- eval database=\$${1}_database
- logit "backing up PostgreSQL database $database"
- test -z "$database" && abend 1 "${1}_database not set"
- if [ -z "$dry_run" ]; then
- su postgres -c "pg_dump $verbose $database" > $backup_tmp_dir/$1-$week-$round-$level
- else
- echo "su postgres -c \"pg_dump $verbose $database\" > $backup_tmp_dir/$1-$week-$round-$level"
- fi
+ eval database=\$${1}_database
+ logit "backing up PostgreSQL database $database"
+ test -z "$database" && abend 1 "${1}_database not set"
+ if [ -z "$dry_run" ]; then
+ su postgres -c "pg_dump $verbose $database" > $backup_tmp_dir/$1-$week-$round-$level
+ else
+ echo "su postgres -c \"pg_dump $verbose $database\" > $backup_tmp_dir/$1-$week-$round-$level"
+ fi
- if [ $? -ne 0 ]; then
- tarerror=$((tarerror + 1))
- logit "failed"
- else
- logit "creating $1-$week-$round-$level.$tar_suffix"
- $dry_run tar $verbose $taroptions \
+ if [ $? -ne 0 ]; then
+ tarerror=$((tarerror + 1))
+ logit "failed"
+ else
+ logit "creating $1-$week-$round-$level.$tar_suffix"
+ $dry_run tar $verbose $taroptions \
-f $backup_archive_dir/$1-$week-$round-$level.$tar_suffix \
-C $backup_tmp_dir $1-$week-$round-$level
- tarcode $?
- $dry_run rm $backup_tmp_dir/$1-$week-$round-$level
- fi
+ tarcode $?
+ $dry_run rm $backup_tmp_dir/$1-$week-$round-$level
+ fi
}
postgres_restore() {
- local u database
+ local u database
- eval database=\$${1}_database
- logit "restoring PostgreSQL database $database"
- u=$(umask)
- trap "umask $u" 1 2 3 13 15
- umask 077
- $dry_run tar $verbose $taroptions \
+ eval database=\$${1}_database
+ logit "restoring PostgreSQL database $database"
+ u=$(umask)
+ trap "umask $u" 1 2 3 13 15
+ umask 077
+ $dry_run tar $verbose $taroptions \
-f $backup_archive_dir/$1-$week-$round-$level.$tar_suffix
- e=$?
- tarcode $e
- if [ $e -eq 0 ]; then
- logit "restoring database from the dump"
- if [ -n "$dry_run" ]; then
- cat <<-EOT
+ e=$?
+ tarcode $e
+ if [ $e -eq 0 ]; then
+ logit "restoring database from the dump"
+ if [ -n "$dry_run" ]; then
+ cat <<-EOT
su postgres -c "dropdb $database"
su postgres -c "createdb $database"
su postgres -c "psql -d $database -f $1-$week-$round-$level"
rm $1-$week-$round-$level
EOT
- elif [ -r $1-$week-$round-$level ]; then
- su postgres -c "dropdb $database"
- su postgres -c "createdb $database"
- su postgres -c "psql -d $database -f $1-$week-$round-$level" > db-$1.log
- if grep ERROR db-$1.log >/dev/null; then
- error "errors occurred during restore; see db-$1.log for details"
- error "dump preserved in file $1-$week-$round-$level"
- tarerror=$((tarerror + 1))
- else
- rm $1-$week-$round-$level
- fi
+ elif [ -r $1-$week-$round-$level ]; then
+ su postgres -c "dropdb $database"
+ su postgres -c "createdb $database"
+ su postgres -c "psql -d $database -f $1-$week-$round-$level" > db-$1.log
+ if grep ERROR db-$1.log >/dev/null; then
+ error "errors occurred during restore; see db-$1.log for details"
+ error "dump preserved in file $1-$week-$round-$level"
+ tarerror=$((tarerror + 1))
+ else
+ rm $1-$week-$round-$level
+ fi
+ fi
fi
- fi
- umask $u
- trap - 1 2 3 13 15
+ umask $u
+ trap - 1 2 3 13 15
}
diff --git a/lib/beam/s3.sh b/lib/beam/s3.sh
index d2fcfe6..7b6ad91 100644
--- a/lib/beam/s3.sh
+++ b/lib/beam/s3.sh
@@ -1,6 +1,6 @@
#! /bin/sh
# This file is part of BEAM
-# Copyright (C) 2012 Sergey Poznyakoff
+# Copyright (C) 2012-2014 Sergey Poznyakoff
#
# BEAM is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@ test -z "$backup_mp" && backup_mp_s3=/mnt/s3
s3_getmpoint()
{
- case $1 in
+ case $1 in
# Sample mount output, split into several lines:
# a) With --vhost:
# http://BUCKETNAME.s3.amazonaws.com/ on /mnt/s3backer type fuse.s3backer
@@ -33,71 +33,73 @@ s3_getmpoint()
# b) Without --vhost:
# http://s3.amazonaws.com/BUCKETNAME/ on /mnt/s3backer type fuse.s3backer
# (rw,nosuid,nodev,allow_other,default_permissions)
- backer)
- mount -tfuse.s3backer |
- awk '/https?:\/\/.*'$backup_bucket_name'/ { print $3 }';;
- s3)
- s=$(mount | grep "^${backup_mp_s3backer}/file" | awk '{ print $3 }')
- if [ -z "$s" ]; then
- # Some kernels print device name instead of the actual mount file:
- s=$(mount | grep "^/dev/loop[0-9] on ${backup_mp_s3}" | awk '{ print $3 }')
- fi
- echo $s;;
- *)
- abent 1 "invalid usage of getmpoint"
- esac
+ backer)
+ mount -tfuse.s3backer |
+ awk '/https?:\/\/.*'$backup_bucket_name'/ { print $3 }';;
+ s3)
+ s=$(mount | grep "^${backup_mp_s3backer}/file" | awk '{ print $3 }')
+ if [ -z "$s" ]; then
+ # Some kernels print device name instead of the actual mount file:
+ s=$(mount | grep "^/dev/loop[0-9] on ${backup_mp_s3}" |
+ awk '{ print $3 }')
+ fi
+ echo $s;;
+ *)
+ abent 1 "invalid usage of getmpoint"
+ esac
}
# This variable is populated by s3_mount and is used by s3_unmount to unmount
# s3-backed file system.
umount_list=""
-s3_mount() {
- # Make sure both mountpoints exist
- test -d $backup_mp_s3backer || mkdir $backup_mp_s3backer
- test -d $backup_mp_s3 || mkdir $backup_mp_s3
+s3_mount() {
+ # Make sure both mountpoints exist
+ test -d $backup_mp_s3backer || mkdir $backup_mp_s3backer
+ test -d $backup_mp_s3 || mkdir $backup_mp_s3
- set -- $(s3_getmpoint backer)
- if test -z "$1"; then
- $dry_run s3backer $backup_s3backer_options \
+ set -- $(s3_getmpoint backer)
+ if test -z "$1"; then
+ $dry_run s3backer $backup_s3backer_options \
$backup_bucket_name $backup_mp_s3backer ||
abend 1 "unable to mount $backup_bucket_name"
- umount_list="$backup_mp_s3backer"
- else
- backup_mp_s3backer=$1
- fi
- set -- $(s3_getmpoint s3)
- if test -z "$1"; then
- case $(basename $0) in
- beam-restore|restore) mountopt=",ro";;
- beam-backup|backup) mountopt=",rw";;
- beam-s3) ;;
- *) error "called as $0: assuming default mount options"
- esac
- test -n "$backup_s3_mount_options" &&
- mountopt="$mountopt,$backup_s3_mount_options"
- # NOTE: For ext4 add the journal_async_commit option.
- $dry_run mount -oloop$mountopt $backup_mp_s3backer/file $backup_mp_s3 ||
- abend 1 "unable to mount $backup_mp_s3backer/file"
- umount_list="$backup_mp_s3 $umount_list"
- else
- backup_mp_s3=$1
- fi
- epilogue_hook="s3_unmount $epilogue_hook"
+ umount_list="$backup_mp_s3backer"
+ else
+ backup_mp_s3backer=$1
+ fi
+ set -- $(s3_getmpoint s3)
+ if test -z "$1"; then
+ case $(basename $0) in
+ beam-restore|restore) mountopt=",ro";;
+ beam-backup|backup) mountopt=",rw";;
+ beam-s3) ;;
+ *) error "called as $0: assuming default mount options"
+ esac
+ test -n "$backup_s3_mount_options" &&
+ mountopt="$mountopt,$backup_s3_mount_options"
+ # NOTE: For ext4 add the journal_async_commit option.
+ $dry_run mount -oloop$mountopt \
+ $backup_mp_s3backer/file $backup_mp_s3 ||
+ abend 1 "unable to mount $backup_mp_s3backer/file"
+ umount_list="$backup_mp_s3 $umount_list"
+ else
+ backup_mp_s3=$1
+ fi
+ epilogue_hook="s3_unmount $epilogue_hook"
}
s3_unmount()
{
- if test "$1" = "--force"; then
- for id in s3 backer
- do
- mpoint=$(s3_getmpoint $id)
- test -n "$mpoint" && $dry_run umount $mpoint
- done
- else
- for mpoint in $umount_list
- do
- test -n "$mpoint" && $dry_run umount $mpoint
- done
- fi
+ if test "$1" = "--force"; then
+ for id in s3 backer
+ do
+ mpoint=$(s3_getmpoint $id)
+ test -n "$mpoint" && $dry_run umount $mpoint
+ done
+ else
+ for mpoint in $umount_list
+ do
+ test -n "$mpoint" && $dry_run umount $mpoint
+ done
+ fi
}

Return to:

Send suggestions and report system problems to the System administrator.