restic-scripts/backup.sh

33 lines
903 B
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..."
curl https://hc-ping.com/$HEALTHCHECK_UUID/fail
exit
fi
echo "Not currently running. Continuing..."
2023-01-17 13:49:13 +01:00
curl https://hc-ping.com/$HEALTHCHECK_UUID/start
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-01-17 13:49:13 +01:00
curl https://hc-ping.com/$HEALTHCHECK_UUID
2023-01-17 13:21:39 +01:00
else
2023-01-17 13:49:13 +01:00
curl https://hc-ping.com/$HEALTHCHECK_UUID/fail
2023-01-17 13:21:39 +01:00
fi