diff --git a/Dockerfile b/Dockerfile index faf2986..13597c6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM alpine -RUN apk update && apk add openssl openssh +RUN apk update && apk add openssl openssh curl COPY backup.sh . diff --git a/README.md b/README.md index 00d9e7d..5f07fc5 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ docker run \ -v /path/to/output:/output \ -v /path/to/key1.pub:/keys/key1.pub:ro \ -v /path/to/key2.pub:/keys/key2.pub:ro \ + -e TELEGRAM_BOT_TOKEN=verysecretbottoken \ + -e TELEGRAM_CHAT_IDS=1337,42069,-12345 \ backupinator ``` diff --git a/backup.sh b/backup.sh index be57028..6c90089 100755 --- a/backup.sh +++ b/backup.sh @@ -25,3 +25,24 @@ for keyfile in $(ls /keys); do rm $tmpkey 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