restic-scripts/backup.sh
2023-11-10 13:52:52 +00:00

52 lines
1.6 KiB
Bash
Executable file

#!/bin/bash
dir=$(dirname "${BASH_SOURCE[0]}")
source $dir/env.sh
DATE=$(date +"%Y-%m-%d %H:%M:%S")
echo "Backup $NAME at $DATE"
BACKUP_CMD="restic backup $BACKUP_DIR"
if [[ $BACKUP_PARAMS ]]; then
BACKUP_CMD="$BACKUP_CMD $BACKUP_PARAMS"
fi
if [[ $BACKUP_EXCLUDE_FILE ]]; then
BACKUP_CMD="$BACKUP_CMD --exclude-file $dir/$BACKUP_EXCLUDE_FILE"
fi
running=$(pgrep -f "$BACKUP_CMD")
if [[ $running ]]; then
echo "Backup alreadying running : $running. Exiting..."
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
exit
fi
echo "Not currently running. Continuing..."
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
if [[ $PRE_RUN_SCRIPT ]]; then
$dir/$PRE_RUN_SCRIPT
fi
$BACKUP_CMD
if [[ $? == 0 ]]; then
if [[ $POST_RUN_SCRIPT ]]; then
$dir/$POST_RUN_SCRIPT
fi
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
else
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
fi