restic-scripts/backup.sh

28 lines
770 B
Bash
Raw Normal View History

2023-01-17 13:21:39 +01:00
#!/bin/bash
source 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-17 13:49:13 +01:00
BACKUP_CMD="$BACKUP_CMD --exclude-file $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
$(pwd)/$PRE_RUN_SCRIPT
2023-01-17 13:21:39 +01:00
$BACKUP_CMD
if [[ $? == 0 ]]; then
2023-01-17 13:49:13 +01:00
$POST_RUN_SCRIPT
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