From b7320fc9ee5e875302f4a0d39dc51ce4dad562d8 Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Wed, 11 Dec 2013 20:40:57 -0800 Subject: [PATCH] Remove mysqldump prompt, add --all-databases, and make --databases or --all-databases required to do mysqldump (Schema section). --- bin/pt-mysql-summary | 57 ++++++++++++---------------------- lib/bash/collect_mysql_info.sh | 2 +- lib/bash/report_mysql_info.sh | 34 ++++++-------------- 3 files changed, 31 insertions(+), 62 deletions(-) diff --git a/bin/pt-mysql-summary b/bin/pt-mysql-summary index 8939c227..60676c80 100755 --- a/bin/pt-mysql-summary +++ b/bin/pt-mysql-summary @@ -963,7 +963,7 @@ get_mysqldump_for () { $CMD_MYSQLDUMP $EXT_ARGV --no-data --skip-comments \ --skip-add-locks --skip-add-drop-table --compact \ --skip-lock-all-tables --skip-lock-tables --skip-set-charset \ - ${args} --databases $( local IFS=,; echo ${dbtodump}) + ${args} --databases $(local IFS=,; echo ${dbtodump}) } get_mysqldump_args () { @@ -2243,24 +2243,14 @@ report_mysql_summary () { fi section "Schema" - local reply="n" - if [ "${OPT_DATABASES}" ] || [ "${OPT_READ_SAMPLES}" ] \ - || [ -e "$dir/mysqldump" -a -s "$dir/mysqldump" ]; then - reply="y" - elif [ -t 0 -a -t 1 ]; then - echo -n "Would you like to mysqldump -d the schema and analyze it? y/n " - read reply - reply=${reply:-n} - fi - if echo "${reply:-n}" | grep -i '^y' > /dev/null ; then - if [ -z "${OPT_DATABASES}" ] && [ -z "$OPT_READ_SAMPLES" ] \ - && [ ! -e "$dir/mysqldump" ]; then - echo "There are ${num_dbs} databases. Would you like to dump all, or just one?" - echo -n "Type the name of the database, or press Enter to dump all of them. " - local dbtodump="" - read dbtodump - local trg_arg="$( get_mysqldump_args "$dir/mysql-variables" )" - get_mysqldump_for "${trg_arg}" "${dbtodump}" > "$dir/mysqldump" + if [ "${OPT_DATABASES}" ] \ + || [ "${OPT_ALL_DATABASES}" ] \ + || [ "${OPT_READ_SAMPLES}" ]; then + + if [ -z "$OPT_READ_SAMPLES" ]; then + local trg_arg="$(get_mysqldump_args "$dir/mysql-variables")" + local dbstodump="${OPT_DATABASES:-""}" + get_mysqldump_for "${trg_arg}" "${OPT_DATABASES}" > "$dir/mysqldump" fi if [ -e "$dir/mysqldump" -a -s "$dir/mysqldump" ] \ @@ -2273,7 +2263,7 @@ report_mysql_summary () { echo "Skipping schema analysis due to apparent error in dump file" fi else - echo "Skipping schema analysis" + echo "Specify --databases or --all-databases to dump and summarize schemas" fi section "Noteworthy Technologies" @@ -2731,10 +2721,6 @@ the percentage of the cache in use and the hit-to-insert ratio. The latter two are fuzzy-rounded. # Schema ##################################################### - Would you like to mysqldump -d the schema and analyze it? y/n y - There are 4 databases. Would you like to dump all, or just one? - Type the name of the database, or press Enter to dump all of them. - Database Tables Views SPs Trigs Funcs FKs Partn mysql 24 performance_schema 17 @@ -2765,16 +2751,10 @@ are fuzzy-rounded. performance_schema 5 16 33 sakila 1 15 1 3 4 3 19 42 26 -If you select to dump the schema and analyze it, the tool will print the above -section. This summarizes the number and type of objects in the database. It is -generated by running C, not by querying the -INFORMATION_SCHEMA, which can freeze a busy server. You can use the -L<"--databases"> option to specify which databases to examine. If you do not, -and you run the tool interactively, it will prompt you as shown. - -You can choose not to dump the schema, to dump all of the databases, or to dump -only a single named one, by specifying the appropriate options. In the example -above, we are dumping all databases. +If you specify L<"--databases"> or L<"--all-databases">, the tool will print +the above section. This summarizes the number and type of objects in the +databases. It is generated by running C, not by querying +the INFORMATION_SCHEMA, which can freeze a busy server. The first sub-report in the section is the count of objects by type in each database: tables, views, and so on. The second one shows how many tables use @@ -2949,6 +2929,10 @@ All options after -- are passed to C. =over +=item --all-databases + +C and summarize all L<"--databases">. + =item --config type: string @@ -2960,9 +2944,8 @@ first option on the command line. type: string -Names of databases to summarize. If you want all of them, you can use the value -C<--all-databases>; you can also pass in a comma-separated list of database -names. If not provided, the program will ask you for manual input. +C and summarize this comma-separated list of databases. Specify +L<"--all-databases"> instead if you want to dump and summary all databases. =item --defaults-file diff --git a/lib/bash/collect_mysql_info.sh b/lib/bash/collect_mysql_info.sh index e99295f4..0be0d352 100644 --- a/lib/bash/collect_mysql_info.sh +++ b/lib/bash/collect_mysql_info.sh @@ -168,7 +168,7 @@ get_mysqldump_for () { $CMD_MYSQLDUMP $EXT_ARGV --no-data --skip-comments \ --skip-add-locks --skip-add-drop-table --compact \ --skip-lock-all-tables --skip-lock-tables --skip-set-charset \ - ${args} --databases $( local IFS=,; echo ${dbtodump}) + ${args} --databases $(local IFS=,; echo ${dbtodump}) } # Returns a string with arguments to pass to mysqldump. diff --git a/lib/bash/report_mysql_info.sh b/lib/bash/report_mysql_info.sh index 09fee8db..6c7664eb 100644 --- a/lib/bash/report_mysql_info.sh +++ b/lib/bash/report_mysql_info.sh @@ -1318,29 +1318,15 @@ report_mysql_summary () { # Schema, databases, data type, other analysis. # ######################################################################## section "Schema" - # Assume "no" if stdin or stdout is not a terminal, so this can be run and - # put into a file, or piped into a pager, or something else like that. - local reply="n" - # But dump no matter what if they passed in something through --databases, - # OR if --read-samples was set - if [ "${OPT_DATABASES}" ] || [ "${OPT_READ_SAMPLES}" ] \ - || [ -e "$dir/mysqldump" -a -s "$dir/mysqldump" ]; then - reply="y" - elif [ -t 0 -a -t 1 ]; then - echo -n "Would you like to mysqldump -d the schema and analyze it? y/n " - read reply - reply=${reply:-n} - fi - if echo "${reply:-n}" | grep -i '^y' > /dev/null ; then - if [ -z "${OPT_DATABASES}" ] && [ -z "$OPT_READ_SAMPLES" ] \ - && [ ! -e "$dir/mysqldump" ]; then - # If --dump-schemas wasn't used, ask what they want to dump - echo "There are ${num_dbs} databases. Would you like to dump all, or just one?" - echo -n "Type the name of the database, or press Enter to dump all of them. " - local dbtodump="" - read dbtodump - local trg_arg="$( get_mysqldump_args "$dir/mysql-variables" )" - get_mysqldump_for "${trg_arg}" "${dbtodump}" > "$dir/mysqldump" + if [ "${OPT_DATABASES}" ] \ + || [ "${OPT_ALL_DATABASES}" ] \ + || [ "${OPT_READ_SAMPLES}" ]; then + + if [ -z "$OPT_READ_SAMPLES" ]; then + # --databases or --all-databases was specified + local trg_arg="$(get_mysqldump_args "$dir/mysql-variables")" + local dbstodump="${OPT_DATABASES:-""}" + get_mysqldump_for "${trg_arg}" "${OPT_DATABASES}" > "$dir/mysqldump" fi # Test the result by checking the file, not by the exit status, because we @@ -1356,7 +1342,7 @@ report_mysql_summary () { echo "Skipping schema analysis due to apparent error in dump file" fi else - echo "Skipping schema analysis" + echo "Specify --databases or --all-databases to dump and summarize schemas" fi # ########################################################################