Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save erwinowak/fb7fe12ce5f2006790fb224325b2ce15 to your computer and use it in GitHub Desktop.

Select an option

Save erwinowak/fb7fe12ce5f2006790fb224325b2ce15 to your computer and use it in GitHub Desktop.
MySQL Backup
#!/bin/bash### MySQL Server Login Info ###
MUSER="USERNAME"
MPASS="PASSWORD"
MHOST="localhost"
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
# get the day of week, 1 = Monday
DOW=`date "+%u"`
BAK="/home/user/backup/mysql/${DOW}"
GZIP="$(which gzip)"
### FTP SERVER Login info ###
FTPU="USERNAME"
FTPP="PASSWORD"
FTPS="FTP-HOST"
NOW=$(date +"%d-%m-%Y")
[ ! -d $BAK ] && mkdir -p $BAK || /bin/rm -f $BAK/*
DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
for db in $DBS
do
FILE=$BAK/$db.$NOW-$(date +"%T").gz
$MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE
done
#lftp -u $FTPU,$FTPP -e "mkdir /mysql/$NOW;cd /mysql/$NOW; mput /home/user/backup/mysql/*; quit" $FTPS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment