restic-scripts/backup.sh

31 lines
862 B
Bash
Executable file

#!/bin/bash
source 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 $BACKUP_EXCLUDE_FILE"
fi
running=$(pgrep -f "$BACKUP_CMD")
if [[ $running ]]; then
echo "Backup alreadying running : $running. Exiting..."
curl https://hc-ping.com/$HEALTHCHECK_UUID/fail
exit
fi
echo "Not currently running. Continuing..."
curl https://hc-ping.com/$HEALTHCHECK_UUID/start
if [[ $PRE_RUN_SCRIPT ]]; then
$(pwd)/$PRE_RUN_SCRIPT
fi
$BACKUP_CMD
if [[ $? == 0 ]]; then
if [[ $POST_RUN_SCRIPT ]]; then
$(pwd)/$POST_RUN_SCRIPT
fi
curl https://hc-ping.com/$HEALTHCHECK_UUID
else
curl https://hc-ping.com/$HEALTHCHECK_UUID/fail
fi