Use flock correctly. Use $0 not $BASH_SOURCE.
This commit is contained in:
parent
7e1bd8c9ae
commit
d0cf34c101
1 changed files with 14 additions and 8 deletions
22
do-backup
22
do-backup
|
|
@ -1,5 +1,5 @@
|
|||
#!/bin/bash
|
||||
# Version: 0.1.0
|
||||
# Version: 0.1.1
|
||||
# Copyright (c) 2023:
|
||||
# Darren 'Tadgy' Austin <darren (at) afterdark.org.uk>
|
||||
# Licensed under the terms of the GNU General Public License version 3.
|
||||
|
|
@ -10,11 +10,11 @@
|
|||
BACKUP_MOUNTPOINT="/localdata"
|
||||
RSYNC_OPTIONS=( '-a' '-H' '-A' '--timeout=300' '--partial' '--partial-dir=.rsync-tmp' '--delete-delay' '--delay-updates' )
|
||||
RSYNC_OPTIONS_VERBOSE=( '--verbose' '--stats' '--human-readable' )
|
||||
RSYNC_LOG="/tmp/${BASH_SOURCE[0]##*/}-$$.log"
|
||||
RSYNC_LOG="/tmp/${0##*/}-$$.log"
|
||||
|
||||
# Sanity checks.
|
||||
(( $# != 1 )) || [[ -z "$1" ]] || [[ "$1" =~ ^(-h|-help|--help)$ ]] && {
|
||||
printf "%s: %s <%s>\\n" "Usage" "${BASH_SOURCE[0]}" "backup definition" >&2
|
||||
printf "%s: %s <%s>\\n" "Usage" "$0" "backup definition" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
|
@ -52,7 +52,7 @@ case "$1" in
|
|||
RSYNC_OPTIONS+=( '--contimeout=30' )
|
||||
;;
|
||||
*)
|
||||
printf "%s: %s: %s\\n" "${BASH_SOURCE[0]##*/}" "$1" "unknown backup definition" >&2
|
||||
printf "%s: %s: %s\\n" "${0##*/}" "$1" "unknown backup definition" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
|
@ -60,15 +60,21 @@ esac
|
|||
# Only allow one copy of the script to run at any time.
|
||||
# shellcheck disable=SC2154
|
||||
if [[ "$FLOCK" != "$0" ]]; then
|
||||
exec env FLOCK="$0" flock -e -n "$0" "$0" "$@" || {
|
||||
printf "%s: %s\\n" "${BASH_SOURCE[0]##*/}" "flock execution error" >&2
|
||||
# shellcheck disable=SC2093
|
||||
exec env FLOCK="$0" flock -E 10 -e -n "$0" "$0" "$@"
|
||||
ERR="$?"
|
||||
if (( ERR == 10 )); then
|
||||
# File is locked, exit now.
|
||||
exit 0
|
||||
elif (( ERR > 0 )); then
|
||||
printf "%s: %s\\n" "${0##*/}" "flock execution error" >&2
|
||||
exit 1
|
||||
}
|
||||
fi
|
||||
fi
|
||||
|
||||
# Source the mail configuration.
|
||||
source /etc/mail.conf "backups" 2>/dev/null || {
|
||||
printf "%s: %s\\n" "${BASH_SOURCE[0]##*/}" "Failed to source /etc/mail.conf" >&2
|
||||
printf "%s: %s\\n" "${0##*/}" "Failed to source /etc/mail.conf" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue