Created
March 9, 2016 21:17
-
-
Save uhlhosting/b969baccb85feb4fd4dc to your computer and use it in GitHub Desktop.
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 | |
# Purpose: Backup mysql | |
# Author: Vivek Gite; under GNU GPL v2.0+ | |
NOW=$(date +"%d-%m-%Y") | |
DEST="/.backup/mysql" | |
# set mysql login info | |
MUSER="root" # Username | |
MPASS='PASSWORD-HERE' # Password | |
MHOST="127.0.0.1" # Server Name | |
# guess binary names | |
MYSQL="$(which mysql)" | |
MYSQLDUMP="$(which mysqldump)" | |
GZIP="$(which gzip)" | |
[ ! -d "${DEST}" ] && mkdir -p "${DEST}" | |
# get all db names | |
DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')" | |
for db in $DBS | |
do | |
FILE=${DEST}/mysql-${db}.${NOW}-$(date +"%T").gz | |
# get around error | |
$MYSQLDUMP --single-transaction -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment