Created
May 12, 2019 02:50
-
-
Save marioy47/cb7a4e7e7ae2251a51860ce4f265f41a to your computer and use it in GitHub Desktop.
Script to backup all databases from a MySQL server, except from mysql and *_shcemas, in one single file.
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 | |
# Script to dump all databases from a MySQL server | |
if [ "$2" -eq "" ]; then | |
echo "Usage: $0 <mysql_root_user> <mysql_root_pass>" | |
exit | |
fi | |
MYSQL_USER=$1 | |
MYSQL_PASS=$2 | |
MYSQL_CONN="-u${MYSQL_USER} -p${MYSQL_PASS}" | |
# Collect all database names except for | |
# mysql, information_schema, and performance_schema | |
SQL="SELECT schema_name FROM information_schema.schemata WHERE schema_name NOT IN" | |
SQL="${SQL} ('mysql','information_schema','performance_schema')" | |
DBLISTFILE=/tmp/DatabasesToDump.txt | |
mysql ${MYSQL_CONN} -ANe"${SQL}" > ${DBLISTFILE} | |
DBLIST="" | |
for DB in `cat ${DBLISTFILE}` ; do DBLIST="${DBLIST} ${DB}" ; done | |
# Do the dump | |
MYSQLDUMP_OPTIONS="--routines --triggers --single-transaction" | |
mysqldump ${MYSQL_CONN} ${MYSQLDUMP_OPTIONS} --databases ${DBLIST} > all-dbs.sql | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment