Fix backup script

This commit is contained in:
Tobias Reisinger 2023-12-17 15:45:36 +01:00
parent e8b1b05ba9
commit 4f78590e8a
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE

View file

@ -9,7 +9,7 @@ set +a
duration_start=$(date +%s)
_duration_get () {
duration_end=$(date +%s)
duration=$((duration_end - duration_start))
echo "$((duration_end - duration_start))"
}
hc_url="https://hc-ping.com/$HC_UID"
@ -18,7 +18,7 @@ _hc_ping () {
curl -fsSL --retry 3 "$hc_url$1" >/dev/null
}
_uptime_kuma_ping () {
duration=_duration_get
duration=$(_duration_get)
curl -fsSL --retry 3 \
--url-query "status=$1" \
--url-query "msg=$2" \
@ -29,6 +29,7 @@ _uptime_kuma_ping () {
_fail () {
_hc_ping "/fail"
_uptime_kuma_ping "down" "$1"
rm -rf "$BACKUP_LOCATION"
exit 1
}
_success () {
@ -38,20 +39,21 @@ _success () {
_hc_ping "/start"
BACKUP_LOCATION="$(mktemp -d)"
BACKUP_LOCATION="$(mktemp -d --suffix=-backup)"
export BACKUP_LOCATION
cd "$BACKUP_LOCATION" || exit
cd "$BACKUP_LOCATION" || _fail "failed to cd to $BACKUP_LOCATION"
shopt -s nullglob
for file in "{{ service_path }}/backup.d/"*
do
file_name="$(basename "$file")"
echo ""
echo "running $file"
time "$file" || _fail "fail while running $file"
echo "running $file_name"
time "$file" >"/tmp/$file_name.log" || _fail "error while running $file_name"
done || true
cd "{{ service_path }}"
docker compose run --rm -v "$BACKUP_LOCATION:/backup/misc" app backup /backup || _fail "fail during restic backup"
docker compose run --rm -v "$BACKUP_LOCATION:/backup/misc" app backup /backup || _fail "error during restic backup"
_success