#!/bin/bash
### MySQL Server Login Info ###
MUSER="root"
MPASS="bersiapsiagalah2024"
MHOST="localhost"
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
GZIP="$(which gzip)"
### FTP SERVER Login info ###
FTPU="FTP-SERVER-USER-NAME"
FTPP="FTP-SERVER-PASSWORD"
FTPS="FTP-SERVER-IP-ADDRESS"
NOW=$(date +"%Y%m%d")
BAK="/mnt/nfs-synology/data/$NOW"
 
### See comments below ###
### [ ! -d $BAK ] && mkdir -p $BAK || /bin/rm -f $BAK/* ###
[ ! -d "$BAK" ] && mkdir -p "$BAK"
 
DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
for db in $DBS
do
if [ $db != 'information_schema' ]
 then
if [ $db != 'mysql' ]
 then
if [ $db != 'test' ]
 then
 FILE=$BAK/$db.sql.gz
 $MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db --routines | $GZIP -9 > $FILE
fi
fi
fi
done

#lftp -u $FTPU,$FTPP -e "mkdir /mysql/$NOW;cd /mysql/$NOW; mput /backup/mysql/*; quit" $FTPS