Created
December 28, 2020 01:21
-
-
Save mstump/daa7d25496582b907599a8c626e6866c to your computer and use it in GitHub Desktop.
Revisions
-
Matt Stump created this gist
Dec 28, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ #!/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}"