Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
4cb2c5caee
|
|||
|
fc953c1bdd
|
|||
|
359d346c33
|
17
btrbk-cron
17
btrbk-cron
@@ -1,6 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
CONF=/etc/btrbk/btrbk-cron.conf
|
||||
LOCKFILE=/run/btrbk/btrbk.lock
|
||||
LOGFILE=$(mktemp)
|
||||
trap 'rm -f -- "${LOGFILE}"' EXIT
|
||||
|
||||
@@ -16,6 +17,7 @@ fi
|
||||
|
||||
HEALTHCHECK_URL=${HEALTHCHECK_URL:-http://127.0.0.1}
|
||||
HEALTHCHECK_ENABLE=${HEALTHCHECK_ENABLE:-false}
|
||||
FAIL_IF_TARGET_UNREACHABLE=${FAIL_IF_TARGET_UNREACHABLE:-true}
|
||||
CURLOPTS=(-fsS -m 10 --retry 5)
|
||||
|
||||
if [[ ! -d /run/btrbk ]] ; then
|
||||
@@ -29,6 +31,15 @@ else
|
||||
echo "Info: Healthchecks disabled"
|
||||
fi
|
||||
|
||||
if [[ -f "${LOCKFILE}" ]] ; then
|
||||
echo "Another instance is still running" | tee -a "${LOGFILE}"
|
||||
if [[ "${HEALTHCHECK_ENABLE}" = "true" ]] ; then
|
||||
curl "${CURLOPTS[@]}" --data-binary "@${LOGFILE}" "${HEALTHCHECK_URL}/log"
|
||||
fi
|
||||
rm -f -- "${LOGFILE}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
HOST=$(grep -E '^[\ \t]*target[\ \t]+send-receive' /etc/btrbk/btrbk.conf)
|
||||
# TODO: support for dashes in hostname and IPv6 ("[2001:db8::7]")
|
||||
HOST=$(echo "${HOST}" | sed -r 's/.*ssh:\/\/([0-9\.a-zA-Z]+).*/\1/g' )
|
||||
@@ -47,7 +58,11 @@ if [[ "${SSH_OK}" = "" ]] ; then
|
||||
curl "${CURLOPTS[@]}" --data-binary "@${LOGFILE}" "${HEALTHCHECK_URL}/log"
|
||||
fi
|
||||
rm -f -- "${LOGFILE}"
|
||||
exit 1
|
||||
if [[ "${FAIL_IF_TARGET_UNREACHABLE}" = "true" ]] ; then
|
||||
exit 1
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Start backup: $(date||true)" | tee -a "${LOGFILE}"
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
HEALTHCHECK_ENABLE=true
|
||||
HEALTHCHECK_URL=https://my.selfhosted.healthcheck.com/ping/e48e4add-c17c-467c-9a91-7b245ad57fe8
|
||||
FAIL_IF_TARGET_UNREACHABLE=true
|
||||
|
||||
7
debian/changelog
vendored
7
debian/changelog
vendored
@@ -1,3 +1,10 @@
|
||||
btrbk-cron (0.3) stable; urgency=medium
|
||||
|
||||
* clean exit if lockfile present
|
||||
* added FAIL_IF_TARGET_UNREACHABLE setting
|
||||
|
||||
-- Paolo Asperti <paolo@asperti.com> Mon, 14 Oct 2024 17:33:58 +0200
|
||||
|
||||
btrbk-cron (0.2) stable; urgency=medium
|
||||
|
||||
* Added destination aliveness check
|
||||
|
||||
Reference in New Issue
Block a user