restic-scripts/backup.sh

53 lines
1.6 KiB
Bash
Raw Normal View History

2023-01-17 13:21:39 +01:00
#!/bin/bash
2023-01-18 22:21:42 +01:00
dir=$(dirname "${BASH_SOURCE[0]}")
source $dir/env.sh
2023-01-17 13:49:13 +01:00
DATE=$(date +"%Y-%m-%d %H:%M:%S")
2023-01-17 13:21:39 +01:00
echo "Backup $NAME at $DATE"
2023-01-17 13:49:13 +01:00
BACKUP_CMD="restic backup $BACKUP_DIR"
2023-01-17 13:30:11 +01:00
if [[ $BACKUP_PARAMS ]]; then
2023-01-17 13:49:13 +01:00
BACKUP_CMD="$BACKUP_CMD $BACKUP_PARAMS"
2023-01-17 13:30:11 +01:00
fi
if [[ $BACKUP_EXCLUDE_FILE ]]; then
2023-01-18 22:48:01 +01:00
BACKUP_CMD="$BACKUP_CMD --exclude-file $dir/$BACKUP_EXCLUDE_FILE"
2023-01-17 13:30:11 +01:00
fi
2023-01-17 13:21:39 +01:00
running=$(pgrep -f "$BACKUP_CMD")
if [[ $running ]]; then
echo "Backup alreadying running : $running. Exiting..."
2023-11-10 14:52:52 +01:00
if [[ $HEALTHCHECK_UUID != "" ]]; then
curl "https://hc-ping.com/$HEALTHCHECK_UUID/fail"
fi
if [[ $KUMA_ID != "" ]]; then
curl "https://$KUMA_URL/api/push/$KUMA_ID?status=down&msg=Failed&ping="
fi
2023-01-17 13:21:39 +01:00
exit
fi
echo "Not currently running. Continuing..."
2023-11-10 14:52:52 +01:00
if [[ $HEALTHCHECK_UUID != "" ]]; then
curl "https://hc-ping.com/$HEALTHCHECK_UUID/start"
fi
if [[ $KUMA_ID != "" ]]; then
curl "https://$KUMA_URL/api/push/$KUMA_ID?status=up&msg=Running&ping="
fi
2023-01-17 13:58:16 +01:00
if [[ $PRE_RUN_SCRIPT ]]; then
2023-01-18 22:21:42 +01:00
$dir/$PRE_RUN_SCRIPT
2023-01-17 13:58:16 +01:00
fi
2023-01-17 13:21:39 +01:00
$BACKUP_CMD
if [[ $? == 0 ]]; then
2023-01-17 13:58:16 +01:00
if [[ $POST_RUN_SCRIPT ]]; then
2023-01-18 22:21:42 +01:00
$dir/$POST_RUN_SCRIPT
2023-01-17 13:58:16 +01:00
fi
2023-11-10 14:52:52 +01:00
if [[ $HEALTHCHECK_UUID != "" ]]; then
curl "https://hc-ping.com/$HEALTHCHECK_UUID"
fi
if [[ $KUMA_ID != "" ]]; then
curl "https://$KUMA_URL/api/push/$KUMA_ID?status=up&msg=Completed&ping="
fi
2023-01-17 13:21:39 +01:00
else
2023-11-10 14:52:52 +01:00
if [[ $HEALTHCHECK_UUID != "" ]]; then
curl "https://hc-ping.com/$HEALTHCHECK_UUID/fail"
fi
if [[ $KUMA_ID != "" ]]; then
curl "https://$KUMA_URL/api/push/$KUMA_ID?status=down&msg=Failed&ping="
fi
2023-01-17 13:21:39 +01:00
fi