backupdir-tg script
This commit is contained in:
parent
f3caa2885a
commit
ab05330e40
32
backupdir-to-telgram/backupdir-to-telgram.sh
Executable file
32
backupdir-to-telgram/backupdir-to-telgram.sh
Executable file
@ -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
|
9
backupdir-to-telgram/env.example
Normal file
9
backupdir-to-telgram/env.example
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user