feat: add initial setup for pearl server

This commit is contained in:
Jef Roosens 2025-04-24 18:05:28 +02:00
parent 2ae759025c
commit 824d7b8a12
Signed by: Jef Roosens
GPG key ID: 21FD3D77D56BAF49
14 changed files with 329 additions and 34 deletions

View file

@ -0,0 +1,43 @@
#!/usr/bin/env bash
# This script sequentially executes all shell scripts matching
# /etc/backups/*.backup.sh, with environment variables configured to publish
# backups to the local Restic REST server.
# Get passed along to subcalls to bash
export RESTIC_REPOSITORY='rest:http://{{ groups['nas'][0] }}:8000/backups'
export RESTIC_PASSWORD_FILE='/etc/backups/restic_backups_passwd'
log_file='/tmp/backup-all.sh.log'
rm -f "$log_file"
for script in $(find /etc/backups -name '*.backup.sh'); do
T="$(date +%s)"
/usr/bin/bash "$script"
res="$?"
T="$(($(date +%s)-T))"
if [[ $res == 0 ]]; then
header='OK'
else
header="FAIL ($res)"
fi
printf \
"%s: %s in %02dh%02dm%02ds\n" \
"$(basename "$script")" "$header" \
"$((T/3600%24))" "$((T/60%60))" "$((T%60))" \
>> "$log_file"
done
# Prune older backups
/usr/local/bin/restic forget --keep-last 7 && \
/usr/local/bin/restic prune
# Send status notification
ntfy publish \
--title "Backups ($(hostname))" \
homelab "$(cat "$log_file")"