#!/bin/bash source /root/.restic_keys telegramSend() { message=$1 telegramStatus=$? if [[ "$telegramStatus" != 0 ]]; then echo "Telegram failed to send message: $message" fi curl -q -X POST \ -H 'Content-Type: application/json' \ -d "{\"chat_id\": \"${TELEGRAM_CHAT_ID}\", \"text\": \"${message}\"}" \ https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage telegramStatus=$? if [[ "$telegramStatus" != 0 ]]; then echo "Telegram failed to send message: $message" fi } checkOutput() { output=$($@ 2>&1) exitCode=$? if [[ $exitCode != 0 ]]; then telegramSend "RESTIC BACKUP ERROR:\n${output}" exit 1 else echo -e "${output}" fi } echo "$(date) - Starting backup..." checkOutput restic \ backup \ --verbose \ --files-from=/root/.restic_files \ --exclude-file=/root/.restic_exclude \ --tag automated_cron echo "$(date) - Running forget and prune..." checkOutput restic forget --prune --keep-daily 7 --keep-weekly 4 --keep-monthly 12 success="$(date) - Backup finished" telegramSend "${success}" echo -e "\n${success}"