Backup mysql with shell and cronjob

  Uncategorized
#!/bin/bash
BACKUPDIR='/backup'
SOURCENAME='backup'
DBHOST='localhost'
DBUSER='root'
DBPASSWORD='password'
PATHMYSQLDUMP='mysqldump'
DATESUB=10
DATENOW=`date +%Y-%m-%d`
DATEDEL=$(date --date="${DATENOW} -${DATESUB} day" +%Y_%m_%d)

curl "https://api.telegram.org/bot_id:token-c/sendMessage?chat_id=-chat_id&text=⚡️ STARTED BACKUP SERVER"

for DBNAME in 'rose'
do
    rm -f $BACKUPDIR/`echo $DATEDEL`_$SOURCENAME.zip
    DBOUT="$BACKUPDIR/$DBNAME.sql"
    mysqldump --force --opt -h $DBHOST -u $DBUSER --password=$DBPASSWORD $DBNAME > $DBOUT
    zip $BACKUPDIR/`date +%Y_%m_%d`_$SOURCENAME.zip $DBOUT
    rm -f $DBOUT
done

curl "https://api.telegram.org/bot_id:token-c/sendMessage?chat_id=-chat_id&text=✅️  BACKUP SUCCESS"