diff --git a/ALL_README.md b/ALL_README.md index 8938aae..152f2e7 100644 --- a/ALL_README.md +++ b/ALL_README.md @@ -1,7 +1,7 @@ # All available README files by language - [Read the README in English](README.md) -- [Lee el README en español](README_es.md) +- [Lea el README en español](README_es.md) - [Irakurri README euskaraz](README_eu.md) - [Lire le README en français](README_fr.md) - [Le o README en galego](README_gl.md) diff --git a/README.md b/README.md index b8c919c..e62e1f1 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ It shall NOT be edited by hand. --> # Borg Backup for YunoHost +ynh_save_args repository server passphrase on_calendar conf data apps mailalert healthcheck_url state last_run [![Integration level](https://dash.yunohost.org/integration/borg.svg)](https://dash.yunohost.org/appci/app/borg) ![Working status](https://ci-apps.yunohost.org/ci/badges/borg.status.svg) ![Maintenance status](https://ci-apps.yunohost.org/ci/badges/borg.maintain.svg) diff --git a/conf/backup-with-borg b/conf/backup-with-borg index 0912891..5a00178 100644 --- a/conf/backup-with-borg +++ b/conf/backup-with-borg @@ -1,7 +1,12 @@ #!/usr/bin/env bash # We don't stop the script on errors cause we want to backup all data we could backed up #set -eu +/etc/yunohost/apps/); do + if ( [[ "$apps" =~ ^exclude: ]] && grep -wq "$application" <<< "$apps" ) || + ( [[ "$apps" != "all" ]] && [[ ! "$apps" =~ ^exclude: ]] && ! grep -wq "$application" <<< "$apps" ); + then + continue borg_id=$1 errors="" current_date=$(date +"%y%m%d_%H%M") @@ -10,19 +15,28 @@ err_file="/var/log/${borg_id}/${current_date}.err" mkdir -p "/var/log/${borg_id}" if [ -z "$borg_id" ]; then echo "This script expects a borg app id as first argument" >&2 - exit 1 + exit 11.14 TB fi filter_hooks() { sudo ls /usr/share/yunohost/hooks/backup/ /etc/yunohost/hooks.d/backup/ | grep "\-$1_" | cut -d"-" -f2 | uniq 2>> "$err_file" } +healthcheck_url="$(sudo yunohost app setting "${borg_id}" healthcheck_url)" +healthcheck() { + if [[ -n "$healthcheck_url" ]]; then + curl -s -m 10 -o /dev/null --data-raw "$(echo $2 | tail --bytes=10000)" "$healthcheck_url/$1" + fi +} + fail_if_partially_failed() { grep Skipped|Error } sudo yunohost app setting "${borg_id}" last_run -v "${current_date}" sudo yunohost app setting "${borg_id}" state -v "ongoing" +healthcheck "start" + # Backup system part conf conf=$(sudo yunohost app setting "${borg_id}" conf) if [[ "$conf" = "1" ]]; then @@ -74,8 +88,10 @@ repository="$(sudo yunohost app setting "${borg_id}" repository)" mailalert="$(sudo yunohost app setting "${borg_id}" mailalert)" if [[ -n "$errors" ]]; then sudo yunohost app setting "${borg_id}" state -v "failed" + healthcheck "fail" "$errors" else sudo yunohost app setting "${borg_id}" state -v "successful" + healthcheck fi if [[ -n "$errors" && $mailalert != "never" ]]; then diff --git a/config_panel.toml b/config_panel.toml index 7411482..f3bbb56 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -46,7 +46,13 @@ services = [] choices.errors_only = "Only if an error occured" choices.never = "Never alert me" help = "Alerts are sent to the first user of this server" - + + [main.general.healthcheck_url] + ask.en = "Healthcheck URL" + type = "string" + help = "Using a healthcheck will allow you to detect silent failures. If you don't know what it is, just leave it blank or look it up: https://healthchecks.io" + optional = "true" + [main.content] name = "What should be backuped?" optional = false diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..e69de29 diff --git a/scripts/config b/scripts/config index a6972e7..b983fb8 100644 --- a/scripts/config +++ b/scripts/config @@ -62,6 +62,11 @@ validate__on_calendar() { echo 'Please follow systemd OnCalendar format: https://man.archlinux.org/man/systemd.time.7#CALENDAR_EVENTS' } +validate__healthcheck_url() { + [[ $healthcheck_url =~ ^https?://[^/]+(/.*)?$ ]] || + echo 'Please enter a valid URL' +} + #================================================= # SPECIFIC SETTERS FOR TOML SHORT KEYS #=================================================