0byt3m1n1
Path:
/
data
/
config
/
mysql
/
[
Home
]
File: generate_list_of_tables_per_db.sh
#!/bin/bash # @Nicolas.Marguglio # This script generates a text file with the list of tables on each db set -o errexit set -o pipefail OUTPUTDIR=/data/config/mysql [[ ! -d $OUTPUTDIR ]] && { echo "Unable to change dir to $OUTPUTDIR" exit 1 } mkdir -p "${OUTPUTDIR}"/locks # No user serviceable code below this line. # Hostname/Filename needed with this format by: # Provision/Modules/Unix/MySQL/DiskGenerate.pm:load_usage_mysql_five hostname="$(hostname -s)" hostname="$(egrep -o 'mysql[vc]?[0-9]+' <<< "${hostname}")" dbdirs=() mycnfs=() case $hostname in mysqlv*) source /etc/conf.d/mysqld [[ -z $DBDIR ]] && { echo "Unable to determine \$DBDIR from /etc/conf.d/mysqld" exit 1 } dbdirs=( "$DBDIR" ) ;; virt*|mysql*|vux) mycnfs=( /etc/my.*.cnf ) dbdirs=( $(egrep -h -m1 '^datadir' ${mycnfs[@]} | tr -d ' \t' | cut -f2 -d'=') ) ;; *) echo 'This is to be run only on mysql servers.' exit 1 ;; esac for dbdir in ${dbdirs[@]}; do [[ ! -d $dbdir ]] && { echo "Unable to change dir to $dbdir" exit 1 } # when we only have one datadir on the server, it is a mysqlV instance if [[ ${#dbdirs[@]} -eq 1 ]]; then suffix="${hostname}" else suffix=mysqlcluster"${dbdir//[[:alpha:]\/]}" fi ( [[ ${#dbdirs[@]} -eq 1 ]] || flock -x -n 9 || exit 1 cd "$dbdir" && { find . -mindepth 2 -maxdepth 2 -type f -name '*MYD' -o -name '*ibd' \ | sed -e 's/\.\///' \ | sed 's/....$//' > "${OUTPUTDIR}"/list_tables_"${suffix}" } ) 9>"${OUTPUTDIR}"/locks/list_tables_"${suffix}" done