mysql backup script

This commit is contained in:
Shihaam Abdul Rahman 2021-04-11 15:23:07 +00:00
commit ce28d7c574
2 changed files with 22 additions and 0 deletions

2
README.md Normal file
View File

@ -0,0 +1,2 @@
# sarmic
- I will be adding any useful scripts, oneliners, wikis and whatnot I find here.

20
backupdb.sh Executable file
View File

@ -0,0 +1,20 @@
#!/bin/bash
#import credentials
source .env
#
DATETIME="$(date +'%d-%m-%Y_%H:%M:%S')"
GZFILE=$DB_DATABASE-$DATETIME.sql.gz
#change working directory to temporary
cd /tmp/
#dump the database to compressed .sql.gz file
mysqldump --opt --user=$DB_USERNAME --password=$DB_PASSWORD $DB_DATABASE | gzip > $GZFILE
#send to gzip file to telegram
curl -s -F document=@$GZFILE https://api.telegram.org/bot$TG_BOT_TOKEN/sendDocument?chat_id=$TG_CHATID
#delete .gzip file
rm $GZFILE