Last active
June 17, 2022 07:39
-
-
Save psujit775/0338ecea5ceb9e1d7eb291e087cfa40e to your computer and use it in GitHub Desktop.
take schema dump of mysql
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/bash | |
HOST="some-database.rds.amazonaws.com" | |
USER="admin" | |
PASSWORD_FILE="/root/.rds.cnf" | |
OUTPUT="/data/schema" | |
databases=`mysql --defaults-extra-file=$PASSWORD_FILE -u $USER -h $HOST -NBe "select group_concat(schema_name separator ' ') from information_schema.schemata where schema_name not in ('sys','mysql', 'information_schema', 'performance_schema')"` | |
# GET Total number of databases. | |
db_count=0 | |
for db in $databases; do | |
let "db_count++" | |
done | |
# Start taking dump | |
COUNTER=1 | |
echo "Removing old SQL files." | |
rm -rf *.sql | |
for db in $databases; do | |
echo "Dumping database: $db [ $COUNTER of $db_count]" | |
mysqldump --defaults-extra-file=$PASSWORD_FILE --user=$USER -h $HOST --no-data --triggers --routines --events --databases $db > $OUTPUT/$db.sql | |
let "COUNTER++" | |
sleep 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment