diff --git a/files/swh-dar-backup b/files/swh-dar-backup index b78eeb6..b6dd820 100755 --- a/files/swh-dar-backup +++ b/files/swh-dar-backup @@ -1,63 +1,74 @@ #!/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" ] && 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 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[@]}" +echo "[$(date -R)] Starting up backup ($BACKUP_CONFIG)" +rc=0 +/usr/bin/dar "${DAR_OPTIONS[@]}" || rc="$?" +# Exit code 11 means a file changed during backup. Don't abort in that +# case. +if [ "$rc" -ne 0 -a "$rc" -ne 11 ] ; then + echo "[$(date -R)] dar failed (exit code=$rc). Abort." + exit 1 +fi # Touch the flag file touch "$BACKUP_DONE" +echo "[$(date -R)] dar successful. Removing old backups." # Prune old backups count=0 ls -1t "$BACKUP_BASENAME"* | while read f; do ((count=count+1)) if (( "$count" > $BACKUP_KEEP )); then - rm "$f"; + rm "$f" fi done + +echo "[$(date -R)] All done."