Created
January 10, 2018 10:38
-
-
Save rosswintle/aa07de0bbf981d56b4401a1e288fd17c to your computer and use it in GitHub Desktop.
MySQL backup all database script
This file contains 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/sh | |
# | |
# This dumps all MySQL databases if you give it a root database login. You can specify the directory. | |
# It creates a date-and-timestamped sub-directory and individual files in there for each database. | |
# | |
HOSTNAME='localhost' | |
MYSQLUSER='root' | |
MYSQLPASS='password' | |
TIMESTAMP=`date +%F-%H%M%S` | |
BACKUPDIR=<directory> | |
mkdir ${BACKUPDIR}/${TIMESTAMP} | |
for DB in $(mysql -h $HOSTNAME -u $MYSQLUSER --password=${MYSQLPASS} --batch --skip-column-names --execute="show databases"); | |
do | |
FILENAME=${BACKUPDIR}/${TIMESTAMP}/${HOSTNAME}_Database_${DB}.sql.gz | |
mysqldump $DB -h $HOSTNAME -u $MYSQLUSER --password=${MYSQLPASS} --triggers --routines --events | gzip -c > $FILENAME | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment