echo'The file already exists. This is likely a permissions issue.' | mail -s"Unable to write to backup lock $LOCK_PATH"$MAIL_TO
return 0
fi
touch$LOCK_PATH
if[$?-ne 0 ];then
echo'The file did not already exist. This is likely a permissions issue, or a parent directory may be missing.' | mail -s"Could not create backup lock $LOCK_PATH"$MAIL_TO
return 0
fi
return 1
}
# If we can't write to or create the lock file, then exit.
[$DEBUG-eq 1 ]&&echo'Making lock file'
make_lock
make_lock_result=$?
[$DEBUG-eq 1 ]&&echo"Result is $make_lock_result"
[$make_lock_result-eq 0 ]&&exit 1
# Connect to our log file, and then try for a lock
# We'll wait up to 5 minutes to grab it
[$DEBUG-eq 1 ]&&echo'Taking lock'
exec 3>> $LOCK_PATH
flock --exclusive--timeout 300 3
if[$?-ne 0 ];then
echo'Lock failed or timed out!'
echo'Tried waiting 5 minutes' | mail -s"Gave up waiting for backup lock on $LOCK_PATH"$MAIL_TO
exit 1
fi
[$DEBUG-eq 1 ]&&echo'Got the lock!'
# Create the destination directory (if needed), and do the backup!