utilities/home_backup.sh

31 lines
858 B
Bash
Raw Normal View History

2025-02-22 14:04:01 +00:00
#!/bin/bash
# Run timed rsync backups using rsnapshot, executed via cron
# Parameters
# --- $1 = Time schedule ('hourly' | 'daily' | 'weekly' | 'monthly')
2025-04-06 16:06:10 +01:00
USER=thomas
export HOME=/home/thomas
export XDG_RUNTIME_DIR=/run/user/1000
source /home/thomas/.env
2025-02-22 14:04:01 +00:00
SCHEDULE=$1
2025-04-17 19:34:42 +01:00
# SLACK_NOTIFIER="${HOME}/repos/utilities/slack_notifier.sh"
RCHAT_NOTIFIER="${HOME}/repos/utilities/rocketchat_notifier.sh"
2025-02-22 14:04:01 +00:00
if mountpoint -q /media/samsung-T3; then
2025-04-06 16:06:10 +01:00
ERROR=$(sudo /usr/bin/rsnapshot -c /etc/rsnapshot.conf "$SCHEDULE" 2>&1)
2025-02-22 14:04:01 +00:00
STATUS=$?
if [ $STATUS -ne 0 ]; then
2025-04-17 19:34:42 +01:00
$RCHAT_NOTIFIER "backups" "error" "${SCHEDULE} /home backup failed: ${ERROR}"
2025-02-22 14:04:01 +00:00
else
if [ $SCHEDULE != "hourly" ]; then
$RCHAT_NOTIFIER "backups" "success" "${SCHEDULE} /home backup completed"
fi
2025-02-22 14:04:01 +00:00
fi
else
2025-04-17 19:34:42 +01:00
$RCHAT_NOTIFIER "backups" "error" \
"${SCHEDULE} /home backup failed: disk not mounted"
2025-02-22 14:04:01 +00:00
fi