diff options
-rw-r--r-- | backup.in | 1 | ||||
-rw-r--r-- | lib/beam/common.in | 17 | ||||
-rw-r--r-- | lib/beam/s3.sh | 12 |
3 files changed, 26 insertions, 4 deletions
@@ -119,12 +119,13 @@ backup() { runhook epilogue_hook logit "finished" } umask ${backup_umask:-077} +prologue_hook="beam_lock $prologue_hook" if [ -n "$backup_logfile" ]; then runhook openlog_hook exec >>$backup_logfile exec 2>&1 fi diff --git a/lib/beam/common.in b/lib/beam/common.in index 1be075e..7e69640 100644 --- a/lib/beam/common.in +++ b/lib/beam/common.in @@ -27,12 +27,13 @@ epilogue_hook= backup_tar_options= backup_suffix= backup_archive_dir= backup_snapshot_dir= backup_verbose= backup_logfile="/var/log/backup" +backup_pidfile="/var/run/beam.pid" backup_tmp_dir=/tmp error() { echo >&2 $0: $* } @@ -44,12 +45,28 @@ abend() { ec=$1 shift error $@ exit $ec } +beam_lock() { + if [ -r $backup_pidfile ]; then + pid=$(head -n 1 $backup_pidfile) + if [ -z "$pid" ]; then + abend "pidfile $backup_pidfile exists but is unreadable or empty" + fi + abend "another beam process (pid $backup_pid) is still running; exiting" + fi + echo $$ > $backup_pidfile || exit 1 + epilogue_hook="$epilogue_hook beam_unlock" +} + +beam_unlock() { + 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));; diff --git a/lib/beam/s3.sh b/lib/beam/s3.sh index de71456..d2fcfe6 100644 --- a/lib/beam/s3.sh +++ b/lib/beam/s3.sh @@ -23,15 +23,22 @@ test -z "$backup_mp_s3backer" && backup_mp_s3backer=/mnt/s3backer # The actual file system is mounted to /mnt/s3 test -z "$backup_mp" && backup_mp_s3=/mnt/s3 s3_getmpoint() { case $1 in +# Sample mount output, split into several lines: +# a) With --vhost: +# http://BUCKETNAME.s3.amazonaws.com/ on /mnt/s3backer type fuse.s3backer +# (rw,nosuid,nodev,allow_other,default_permissions) +# 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 }';; + 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 @@ -47,15 +54,12 @@ 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 -# Sample mount output, split into several lines: -# http://finox-backup-fs.s3.amazonaws.com/ on /mnt/s3backer type fuse.s3backer -# (rw,nosuid,nodev,allow_other,default_permissions) 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" |