initial release

This commit is contained in:
Paolo Asperti 2024-09-18 18:39:31 +02:00
parent 0b93a91b59
commit 4dd17557a1
Signed by: paspo
GPG Key ID: 06D46905D19D5182
13 changed files with 136 additions and 1 deletions

View File

@ -1,3 +1,21 @@
# btrkbk-cron # btrkbk-cron
btrbk cron wrapper btrbk cron wrapper with healthchecks support.
[![Build Status](https://drone.asperti.com/api/badges/paspo/btrbk-cron/status.svg)](https://drone.asperti.com/paspo/btrbk-cron)
## Build
Run this:
```bash
debuild -i -us -uc
```
## Installation
Just install the package as usual.
```bash
sudo dpkg -i btrbk-cron_*.deb
```

53
btrbk-cron Executable file
View File

@ -0,0 +1,53 @@
#!/bin/bash
CONF=/etc/btrbk/btrbk-cron.conf
LOGFILE=$(mktemp)
trap 'rm -f -- "${LOGFILE}"' EXIT
if [[ ! -f "${CONF}" ]] ; then
echo "Warning: Can't read config file (${CONF}), healthchecks disabled."
else
# shellcheck disable=SC1090,SC1091
source "${CONF}"
fi
HEALTHCHECK_URL=${HEALTHCHECK_URL:-http://127.0.0.1}
HEALTHCHECK_ENABLE=${HEALTHCHECK_ENABLE:-false}
CURLOPTS=(-fsS -m 10 --retry 5)
if [[ ! -d /run/btrbk ]] ; then
mkdir -p /run/btrbk
fi
echo "---" | tee -a "${LOGFILE}"
echo "Start backup: $(date||true)" | tee -a "${LOGFILE}"
if [[ "${HEALTHCHECK_ENABLE}" = "true" ]] ; then
curl "${CURLOPTS[@]}" "${HEALTHCHECK_URL}/start"
fi
echo
echo "healthcheck notified! (start)" | tee -a "${LOGFILE}"
(nice -n 19 /usr/bin/ionice -c idle /usr/bin/btrbk -v --progress run >> "${LOGFILE}" ; ) 2>&1
ret=$?
if [[ "${ret}" -eq "0" ]]; then
if [[ "${HEALTHCHECK_ENABLE}" = "true" ]] ; then
curl "${CURLOPTS[@]}" "${HEALTHCHECK_URL}"
fi
echo
echo "healthcheck notified! (ok)" | tee -a "${LOGFILE}"
else
if [[ "${HEALTHCHECK_ENABLE}" = "true" ]] ; then
curl "${CURLOPTS[@]}" "${HEALTHCHECK_URL}/fail"
fi
echo
echo "healthcheck notified! (fail)" | tee -a "${LOGFILE}"
fi
echo "starting cleanup" | tee -a "${LOGFILE}"
(nice -n 19 /usr/bin/ionice -c idle /usr/bin/btrbk clean >> "${LOGFILE}" ; ) 2>&1
echo "backup finished, sending logs" | tee -a "${LOGFILE}"
if [[ "${HEALTHCHECK_ENABLE}" = "true" ]] ; then
curl "${CURLOPTS[@]}" --data-binary "@${LOGFILE}" "${HEALTHCHECK_URL}/log"
fi
echo
rm -f -- "${LOGFILE}"
echo "backup finished"

2
btrbk-cron.conf.example Normal file
View File

@ -0,0 +1,2 @@
HEALTHCHECK_ENABLE=true
HEALTHCHECK_URL=https://my.selfhosted.healthcheck.com/ping/e48e4add-c17c-467c-9a91-7b245ad57fe8

6
debian/.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
debhelper-build-stamp
*.debhelper.log
*.substvars
files
.debhelper
btrbk-cron

1
debian/btrbk-cron.cron.d vendored Normal file
View File

@ -0,0 +1 @@
25 * * * * root /usr/bin/btrbk-cron

1
debian/btrbk-cron.example vendored Normal file
View File

@ -0,0 +1 @@
btrbk-cron.conf.example etc/btrbk/btrbk-cron.conf.example

1
debian/btrbk-cron.install vendored Normal file
View File

@ -0,0 +1 @@
btrbk-cron usr/bin

5
debian/changelog vendored Normal file
View File

@ -0,0 +1,5 @@
btrbk-cron (0.1) UNRELEASED; urgency=medium
* Initial release.
-- Paolo Asperti <paolo@asperti.com> Wed, 18 Sep 2024 09:14:20 +0200

1
debian/compat vendored Normal file
View File

@ -0,0 +1 @@
12

15
debian/control vendored Normal file
View File

@ -0,0 +1,15 @@
Source: btrbk-cron
Section: admin
Priority: optional
Maintainer: Paolo Asperti <paolo@asperti.com>
Build-Depends: debhelper (>= 12)
Standards-Version: 4.5.0
Homepage: https://asperti.com/
Package: btrbk-cron
Architecture: all
Depends: ${misc:Depends}, bash (>= 5), curl, btrbk
Description: btrbk wrapper script for cron and healthchecks
This packages automates btrbk and adds support for healthchecks notifications.
Healthchecks pings are sent at start and at success/failure.
Logs are also sent.

27
debian/copyright vendored Normal file
View File

@ -0,0 +1,27 @@
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: btrbk wrapper script for cron and healthchecks
Source: https://asperti.com
Files: *
Copyright: Copyright 2024 Paolo Asperti <paolo@asperti.com>
License: GPL-2+
This program is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later
version.
.
This program is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU General Public License for more
details.
.
You should have received a copy of the GNU General Public
License along with this package; if not, write to the Free
Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Boston, MA 02110-1301 USA
.
On Debian systems, the full text of the GNU General Public
License version 2 can be found in the file
`/usr/share/common-licenses/GPL-2'.

4
debian/rules vendored Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/make -f
%:
dh $@

1
debian/source/format vendored Normal file
View File

@ -0,0 +1 @@
3.0 (native)