Compare commits
16 Commits
0b93a91b59
...
0.4.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
9725a09c06
|
|||
|
bd300718e7
|
|||
|
cfd15aca3b
|
|||
|
4b541698df
|
|||
|
d5886da0a4
|
|||
|
784cda10eb
|
|||
|
2adcac027b
|
|||
|
4cb2c5caee
|
|||
|
fc953c1bdd
|
|||
|
359d346c33
|
|||
|
1e3638d474
|
|||
|
7b84ca86f4
|
|||
|
d856635747
|
|||
|
693ded862c
|
|||
|
3f4c9fc6f4
|
|||
|
4dd17557a1
|
44
.drone.yml
Normal file
44
.drone.yml
Normal file
@@ -0,0 +1,44 @@
|
||||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: docker.asperti.com/paspo/docker-deb-builder:debian_bullseye
|
||||
commands:
|
||||
- debuild -i -us -uc
|
||||
- mkdir debs
|
||||
- mv ../*.deb debs/
|
||||
|
||||
- name: gitea release
|
||||
image: plugins/gitea-release
|
||||
settings:
|
||||
checksum:
|
||||
- md5
|
||||
- sha256
|
||||
api_key:
|
||||
from_secret: gitea_token
|
||||
base_url: https://git.asperti.com
|
||||
files:
|
||||
- debs/*.deb
|
||||
title: server01-crowdsec-whitelist
|
||||
|
||||
- name: push to repo
|
||||
image: docker.asperti.com/paspo/docker-aptly-pusher
|
||||
settings:
|
||||
api_url: https://deb.server01.it/api
|
||||
repo: server01
|
||||
distribution: server01
|
||||
http_user:
|
||||
from_secret: repo_http_user
|
||||
http_pass:
|
||||
from_secret: repo_http_pass
|
||||
passphrase:
|
||||
from_secret: repo_passphrase
|
||||
files:
|
||||
- debs/*.deb
|
||||
|
||||
trigger:
|
||||
event:
|
||||
- tag
|
||||
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
.vscode/
|
||||
4
LICENSE
4
LICENSE
@@ -208,7 +208,7 @@ If you develop a new program, and you want it to be of the greatest possible use
|
||||
|
||||
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found.
|
||||
|
||||
btrkbk-cron
|
||||
btrbk-cron
|
||||
Copyright (C) 2024 paspo
|
||||
|
||||
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 3 of the License, or (at your option) any later version.
|
||||
@@ -221,7 +221,7 @@ Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode:
|
||||
|
||||
btrkbk-cron Copyright (C) 2024 paspo
|
||||
btrbk-cron Copyright (C) 2024 paspo
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details.
|
||||
|
||||
|
||||
37
README.md
37
README.md
@@ -1,3 +1,36 @@
|
||||
# btrkbk-cron
|
||||
# btrbk-cron
|
||||
|
||||
btrbk cron wrapper
|
||||
btrbk cron wrapper with healthchecks support.
|
||||
|
||||
[](https://drone.asperti.com/paspo/btrbk-cron)
|
||||
|
||||
## Build
|
||||
|
||||
Run this:
|
||||
|
||||
```bash
|
||||
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
|
||||
|
||||
Just install the package as usual.
|
||||
|
||||
```bash
|
||||
sudo dpkg -i btrbk-cron_*.deb
|
||||
```
|
||||
|
||||
112
btrbk-cron
Executable file
112
btrbk-cron
Executable file
@@ -0,0 +1,112 @@
|
||||
#!/bin/bash
|
||||
|
||||
CONF=/etc/btrbk/btrbk-cron.conf
|
||||
LOCKFILE=/run/btrbk/btrbk.lock
|
||||
LOGFILE=$(mktemp)
|
||||
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
|
||||
echo "Warning: Can't read config file (${CONF}), healthchecks disabled." | tee -a "${LOGFILE}"
|
||||
else
|
||||
# shellcheck disable=SC1090,SC1091
|
||||
source "${CONF}"
|
||||
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
|
||||
echo "Warning: Creating missing directory: /run/btrbk " | tee -a "${LOGFILE}"
|
||||
mkdir -p /run/btrbk
|
||||
fi
|
||||
|
||||
if [[ "${HEALTHCHECK_ENABLE}" = "true" ]] ; then
|
||||
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}"
|
||||
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"
|
||||
3
btrbk-cron.conf.example
Normal file
3
btrbk-cron.conf.example
Normal file
@@ -0,0 +1,3 @@
|
||||
HEALTHCHECK_ENABLE=true
|
||||
HEALTHCHECK_URL=https://my.selfhosted.healthcheck.com/ping/e48e4add-c17c-467c-9a91-7b245ad57fe8
|
||||
FAIL_IF_TARGET_UNREACHABLE=true
|
||||
6
debian/.gitignore
vendored
Normal file
6
debian/.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
debhelper-build-stamp
|
||||
*.debhelper.log
|
||||
*.substvars
|
||||
files
|
||||
.debhelper
|
||||
btrbk-cron
|
||||
1
debian/btrbk-cron.cron.d
vendored
Normal file
1
debian/btrbk-cron.cron.d
vendored
Normal file
@@ -0,0 +1 @@
|
||||
25 * * * * root /usr/bin/btrbk-cron
|
||||
1
debian/btrbk-cron.example
vendored
Normal file
1
debian/btrbk-cron.example
vendored
Normal file
@@ -0,0 +1 @@
|
||||
btrbk-cron.conf.example etc/btrbk/btrbk-cron.conf.example
|
||||
1
debian/btrbk-cron.install
vendored
Normal file
1
debian/btrbk-cron.install
vendored
Normal file
@@ -0,0 +1 @@
|
||||
btrbk-cron usr/bin
|
||||
31
debian/changelog
vendored
Normal file
31
debian/changelog
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
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.
|
||||
|
||||
-- Paolo Asperti <paolo@asperti.com> Wed, 18 Sep 2024 09:14:20 +0200
|
||||
1
debian/compat
vendored
Normal file
1
debian/compat
vendored
Normal file
@@ -0,0 +1 @@
|
||||
12
|
||||
15
debian/control
vendored
Normal file
15
debian/control
vendored
Normal 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
27
debian/copyright
vendored
Normal 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
4
debian/rules
vendored
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/make -f
|
||||
|
||||
%:
|
||||
dh $@
|
||||
1
debian/source/format
vendored
Normal file
1
debian/source/format
vendored
Normal file
@@ -0,0 +1 @@
|
||||
3.0 (native)
|
||||
Reference in New Issue
Block a user