Last active
October 13, 2016 11:35
-
-
Save dreamingechoes/14b063bc5b6602aae4c62a92de984235 to your computer and use it in GitHub Desktop.
Script to generate dumps of all our local databases on MySQL.
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 | |
# Suffix added at the end of the filename | |
NOW=$(date +"%d%m%Y") | |
# Destination folder of all the dumps | |
DEST="backups" | |
# Set mysql login info | |
MUSER="root" | |
MPASS="" | |
MHOST="127.0.0.1" | |
# 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}/${db}_${NOW}.gz | |
$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