Add telegram bot functionality

This commit is contained in:
Kai Vogelgesang 2020-02-05 23:12:15 +01:00
parent 0a671b1a0a
commit 95ace5f95c
3 changed files with 24 additions and 1 deletions

View File

@ -1,6 +1,6 @@
FROM alpine FROM alpine
RUN apk update && apk add openssl openssh RUN apk update && apk add openssl openssh curl
COPY backup.sh . COPY backup.sh .

View File

@ -8,6 +8,8 @@ docker run \
-v /path/to/output:/output \ -v /path/to/output:/output \
-v /path/to/key1.pub:/keys/key1.pub:ro \ -v /path/to/key1.pub:/keys/key1.pub:ro \
-v /path/to/key2.pub:/keys/key2.pub:ro \ -v /path/to/key2.pub:/keys/key2.pub:ro \
-e TELEGRAM_BOT_TOKEN=verysecretbottoken \
-e TELEGRAM_CHAT_IDS=1337,42069,-12345 \
backupinator backupinator
``` ```

View File

@ -25,3 +25,24 @@ for keyfile in $(ls /keys); do
rm $tmpkey rm $tmpkey
done done
if [ ! -z ${TELEGRAM_BOT_TOKEN+x} ]; then
echo $TELEGRAM_CHAT_IDS | sed -n 1'p' | tr ',' '\n' | while read chat_id; do
echo "sending messages to $chat_id..."
curl -X POST "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage" \
-F chat_id="$chat_id" \
-F text="Backup time."
echo ""
curl -X POST "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendDocument" \
-F chat_id="$chat_id" \
-F document=@/out/backup.tar.gz.enc
echo ""
for keyfile in $(ls /out/key-*); do
curl -X POST "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendDocument" \
-F chat_id="$chat_id" \
-F document="@$keyfile"
echo ""
done
done
fi