diff --git a/files/swh-dar-backup b/files/swh-dar-backup index 3c04937..b78eeb6 100755 --- a/files/swh-dar-backup +++ b/files/swh-dar-backup @@ -1,63 +1,63 @@ #!/bin/bash # # swh-dar-backup: run a local backup with dar # # Copyright (c) 2015 Nicolas Dandrimont # # This file is part of the swh-dar puppet module # set -e if [ $# -ne 1 ]; then echo "Usage: $0 " exit 2 fi BACKUP_CONFIG="$1" . "$BACKUP_CONFIG" . "$BACKUP_INCLUDE" . "$BACKUP_EXCLUDE" -if [ -f "$BACKUP_LOCK" ]; then - echo "Lockfile \`$BACKUP_LOCK' present, exiting" +if [ -f "$BACKUP_LOCK" ] && kill -0 "$(cat "$BACKUP_LOCK")" 2>/dev/null; then + echo "Lockfile \`$BACKUP_LOCK' present and process still exists, exiting" exit 2 fi trap "rm -f '$BACKUP_LOCK'" EXIT -touch "$BACKUP_LOCK" +echo $$ > "$BACKUP_LOCK" # Don't let people believe that they can fetch the current backup rm -f "$BACKUP_DONE" BACKUP_BASENAME="$BACKUP_STORAGE/$BACKUP_TITLE." BACKUP_PATH="$BACKUP_BASENAME$(TZ=UTC date +"%Y-%m-%dT%H:%M:%SZ")" DAR_OPTIONS=( -c "$BACKUP_PATH" -R "$BACKUP_BASE" "${BACKUP_INCLUDE_OPTIONS[@]}" # Include empty directories -D "${BACKUP_EXCLUDE_OPTIONS[@]}" "${BACKUP_OPTIONS[@]}" ) # Do the backup /usr/bin/dar "${DAR_OPTIONS[@]}" # Touch the flag file touch "$BACKUP_DONE" # Prune old backups count=0 ls -1t "$BACKUP_BASENAME"* | while read f; do ((count=count+1)) if (( "$count" > $BACKUP_KEEP )); then rm "$f"; fi done