diff --git a/src/borgwrapper.sh b/src/borgwrapper.sh index b3b9c8d..1633115 100755 --- a/src/borgwrapper.sh +++ b/src/borgwrapper.sh @@ -171,8 +171,8 @@ exit_clean () { # Default parameters CONFIG="/etc/borgwrapper/config.sh" -LOCKFILE="/var/lock/borgwrapper.lock" BORG="/usr/bin/borg" +LOCKDIR="/run/lock/borgwrapper" PRE_BACKUP_CMD=() POST_BACKUP_CMD=() POST_VERIFY_CMD=() @@ -198,6 +198,9 @@ echo "Loading config from ${CONFIG}" source "${CONFIG}" || exit 1 export BORG_PASSPHRASE +LOCKFILE="${LOCKDIR}/$(echo -n "${BORG_REPO}" | md5sum | cut -d ' ' -f 1).lock" +mkdir -p "${LOCKDIR}" + ( # Ensure this is the only instance running flock -n 9 || lock_failed @@ -237,4 +240,4 @@ export BORG_PASSPHRASE fi exit_clean 0 -) 9>${LOCKFILE} +) 9>"${LOCKFILE}" diff --git a/src/config.sh.example b/src/config.sh.example index 31e8825..d722144 100644 --- a/src/config.sh.example +++ b/src/config.sh.example @@ -27,9 +27,8 @@ KEEP_YEARLY=5 # You can use K, M, G or T binary prefixes (power of 1024), e.g., 5M = 5MiB/s = 5242880 bytes/s. #BWLIMIT=0 -# Change this if you need to have multiple borgwrapper instances running -# using different configs. -#LOCKFILE="/var/lock/borgwrapper.lock" +# Location of borgwrapper lock files +#LOCKDIR="/run/lock/borgwrapper" # Command to execute before backup, e.g., taking a ZFS snapshot. Must return successfully # for backup to start. POST_BACKUP_CMD is executed even if this fails.