Compare commits
No commits in common. "master" and "0.1" have entirely different histories.
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +0,0 @@
|
|||||||
.vscode/
|
|
15
README.md
15
README.md
@ -12,21 +12,6 @@ Run this:
|
|||||||
debuild -i -us -uc
|
debuild -i -us -uc
|
||||||
```
|
```
|
||||||
|
|
||||||
## New release
|
|
||||||
|
|
||||||
Add comments:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
dch -v 0.2 "comment 1"
|
|
||||||
dch -v 0.2 "comment 2"
|
|
||||||
```
|
|
||||||
|
|
||||||
Release:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
dch --release --distribution stable
|
|
||||||
```
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Just install the package as usual.
|
Just install the package as usual.
|
||||||
|
65
btrbk-cron
65
btrbk-cron
@ -1,21 +1,11 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
CONF=/etc/btrbk/btrbk-cron.conf
|
CONF=/etc/btrbk/btrbk-cron.conf
|
||||||
LOCKFILE=/run/btrbk/btrbk.lock
|
|
||||||
LOGFILE=$(mktemp)
|
LOGFILE=$(mktemp)
|
||||||
trap 'rm -f -- "${LOGFILE}"' EXIT
|
trap 'rm -f -- "${LOGFILE}"' EXIT
|
||||||
|
|
||||||
# check for superpowers
|
|
||||||
if [[ "${EUID}" -ne 0 ]] ; then
|
|
||||||
echo "Please run me as root"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "---" | tee -a "${LOGFILE}"
|
|
||||||
echo "Start btrbk-cron: $(date||true)" | tee -a "${LOGFILE}"
|
|
||||||
|
|
||||||
if [[ ! -f "${CONF}" ]] ; then
|
if [[ ! -f "${CONF}" ]] ; then
|
||||||
echo "Warning: Can't read config file (${CONF}), healthchecks disabled." | tee -a "${LOGFILE}"
|
echo "Warning: Can't read config file (${CONF}), healthchecks disabled."
|
||||||
else
|
else
|
||||||
# shellcheck disable=SC1090,SC1091
|
# shellcheck disable=SC1090,SC1091
|
||||||
source "${CONF}"
|
source "${CONF}"
|
||||||
@ -23,69 +13,20 @@ fi
|
|||||||
|
|
||||||
HEALTHCHECK_URL=${HEALTHCHECK_URL:-http://127.0.0.1}
|
HEALTHCHECK_URL=${HEALTHCHECK_URL:-http://127.0.0.1}
|
||||||
HEALTHCHECK_ENABLE=${HEALTHCHECK_ENABLE:-false}
|
HEALTHCHECK_ENABLE=${HEALTHCHECK_ENABLE:-false}
|
||||||
FAIL_IF_TARGET_UNREACHABLE=${FAIL_IF_TARGET_UNREACHABLE:-true}
|
|
||||||
CURLOPTS=(-fsS -m 10 --retry 5)
|
CURLOPTS=(-fsS -m 10 --retry 5)
|
||||||
|
|
||||||
if [[ ! -d /run/btrbk ]] ; then
|
if [[ ! -d /run/btrbk ]] ; then
|
||||||
echo "Warning: Creating missing directory: /run/btrbk " | tee -a "${LOGFILE}"
|
|
||||||
mkdir -p /run/btrbk
|
mkdir -p /run/btrbk
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "${HEALTHCHECK_ENABLE}" = "true" ]] ; then
|
echo "---" | tee -a "${LOGFILE}"
|
||||||
echo "Info: Healthchecks enabled with URL: ${HEALTHCHECK_URL}"
|
|
||||||
else
|
|
||||||
echo "Info: Healthchecks disabled"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# lockfile check
|
|
||||||
if [[ -f "${LOCKFILE}" ]] ; then
|
|
||||||
# check if stale lockfile
|
|
||||||
if [[ $(pgrep --exact --count btrbk || true) -eq 0 ]] ; then
|
|
||||||
echo "Removing stale lock file: ${LOCKFILE}"
|
|
||||||
rm "${LOCKFILE}"
|
|
||||||
else
|
|
||||||
# another instance is really running, we exit
|
|
||||||
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
|
|
||||||
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' )
|
|
||||||
|
|
||||||
IDENTITYFILE=$(grep -E '^[\ \t]*ssh_identity[\ \t].*' /etc/btrbk/btrbk.conf )
|
|
||||||
IDENTITYFILE=$(echo "${IDENTITYFILE}" | sed -r 's/.*ssh_identity[\ \t]+//g')
|
|
||||||
|
|
||||||
SSHUSER=$(grep -E '^[\ \t]*ssh_user[\ \t].*' /etc/btrbk/btrbk.conf )
|
|
||||||
SSHUSER=$(echo "${SSHUSER}" | sed -r 's/.*ssh_user[\ \t]+//g')
|
|
||||||
|
|
||||||
SSH_OK=$(ssh -i "${IDENTITYFILE}" "${SSHUSER}@${HOST}" "which btrfs")
|
|
||||||
|
|
||||||
if [[ "${SSH_OK}" = "" ]] ; then
|
|
||||||
echo "Warning: exiting because of backup destination unreachable" | tee -a "${LOGFILE}"
|
|
||||||
if [[ "${HEALTHCHECK_ENABLE}" = "true" ]] ; then
|
|
||||||
curl "${CURLOPTS[@]}" --data-binary "@${LOGFILE}" "${HEALTHCHECK_URL}/log"
|
|
||||||
fi
|
|
||||||
rm -f -- "${LOGFILE}"
|
|
||||||
if [[ "${FAIL_IF_TARGET_UNREACHABLE}" = "true" ]] ; then
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Start backup: $(date||true)" | tee -a "${LOGFILE}"
|
echo "Start backup: $(date||true)" | tee -a "${LOGFILE}"
|
||||||
if [[ "${HEALTHCHECK_ENABLE}" = "true" ]] ; then
|
if [[ "${HEALTHCHECK_ENABLE}" = "true" ]] ; then
|
||||||
curl "${CURLOPTS[@]}" "${HEALTHCHECK_URL}/start"
|
curl "${CURLOPTS[@]}" "${HEALTHCHECK_URL}/start"
|
||||||
fi
|
fi
|
||||||
echo
|
echo
|
||||||
echo "healthcheck notified! (start)" | tee -a "${LOGFILE}"
|
echo "healthcheck notified! (start)" | tee -a "${LOGFILE}"
|
||||||
(nice -n 19 /usr/bin/ionice -c idle /usr/bin/btrbk -v --progress run 2>&1 || true) | tee -a "${LOGFILE}" 2>&1
|
(nice -n 19 /usr/bin/ionice -c idle /usr/bin/btrbk -v --progress run >> "${LOGFILE}" ; ) 2>&1
|
||||||
ret=$?
|
ret=$?
|
||||||
if [[ "${ret}" -eq "0" ]]; then
|
if [[ "${ret}" -eq "0" ]]; then
|
||||||
if [[ "${HEALTHCHECK_ENABLE}" = "true" ]] ; then
|
if [[ "${HEALTHCHECK_ENABLE}" = "true" ]] ; then
|
||||||
|
@ -1,3 +1,2 @@
|
|||||||
HEALTHCHECK_ENABLE=true
|
HEALTHCHECK_ENABLE=true
|
||||||
HEALTHCHECK_URL=https://my.selfhosted.healthcheck.com/ping/e48e4add-c17c-467c-9a91-7b245ad57fe8
|
HEALTHCHECK_URL=https://my.selfhosted.healthcheck.com/ping/e48e4add-c17c-467c-9a91-7b245ad57fe8
|
||||||
FAIL_IF_TARGET_UNREACHABLE=true
|
|
||||||
|
34
debian/changelog
vendored
34
debian/changelog
vendored
@ -1,36 +1,4 @@
|
|||||||
btrbk-cron (0.4.2) stable; urgency=medium
|
btrbk-cron (0.1) UNRELEASED; urgency=medium
|
||||||
|
|
||||||
* gather all logs
|
|
||||||
|
|
||||||
-- Paolo Asperti <paolo@asperti.com> Tue, 22 Oct 2024 11:21:43 +0200
|
|
||||||
|
|
||||||
btrbk-cron (0.4.1) stable; urgency=medium
|
|
||||||
|
|
||||||
* fix error redir
|
|
||||||
|
|
||||||
-- Paolo Asperti <paolo@asperti.com> Wed, 16 Oct 2024 11:56:39 +0200
|
|
||||||
|
|
||||||
btrbk-cron (0.4) stable; urgency=medium
|
|
||||||
|
|
||||||
* stale lockfile check
|
|
||||||
* require to run as root
|
|
||||||
|
|
||||||
-- Paolo Asperti <paolo@asperti.com> Tue, 15 Oct 2024 09:23:11 +0200
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
-- Paolo Asperti <paolo@asperti.com> Tue, 24 Sep 2024 16:08:04 +0200
|
|
||||||
|
|
||||||
btrbk-cron (0.1) stable; urgency=medium
|
|
||||||
|
|
||||||
* Initial release.
|
* Initial release.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user