diff --git a/backupdir-to-telgram/backupdir-to-telgram.sh b/backupdir-to-telgram/backupdir-to-telgram.sh new file mode 100755 index 0000000..9a2dc49 --- /dev/null +++ b/backupdir-to-telgram/backupdir-to-telgram.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +source .env +cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 +WORKINGDIR=$(basename $(pwd)) +DATETIME="$(date +'%d-%m-%Y_%H-%M-%S')" +FILENAME=$(echo $WORKINGDIR-$DATETIME.tar.gz) + +mkdir /tmp/$WORKINGDIR +TMPDIR=$(echo /tmp/$WORKINGDIR) + +tar czf $TMPDIR/$FILENAME . +cd /tmp/$WORKINGDIR + +#check if file size over 1.9GB, Split by 1.8GB if so +FILESIZE=$(ls -s $TMPDIR/$FILENAME | awk '{print $1}') +if [ "$FILESIZE" -gt "1991680" ] +then + split --bytes=1800M $FILENAME $FILENAME-split- + rm $FILENAME +fi + +#Upload files one by one +i=0; +for FILE in `ls` +do + idkwhythisisneededbutitworkswhenthisishere[$i]=$FILE; + i=$(($i+1)); + curl -s -F document=@$FILE $TG_BOTAPI$TG_BOT_TOKEN/sendDocument?chat_id=$TG_CHATID +done + +rm -r $TMPDIR diff --git a/backupdir-to-telgram/env.example b/backupdir-to-telgram/env.example new file mode 100644 index 0000000..0e532cd --- /dev/null +++ b/backupdir-to-telgram/env.example @@ -0,0 +1,9 @@ +# Telegram Config +### Your Telegram Bot API Token, Contact @BotFather on Telegram to obtain token +TG_BOT_TOKEN='' +### Your Telegram chat ID, This could be your user, group, supergroup or channel ID, add "-100" first if supergroup or channel +TG_CHATID='' +### Change to a private hosted Telegram Bot API if compressed dir is over 50MB +TG_BOTAPI='https://api.telegram.org/bot' + +# Compression