-
-
Save erwinowak/fb7fe12ce5f2006790fb224325b2ce15 to your computer and use it in GitHub Desktop.
MySQL Backup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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