Last active
August 29, 2015 14:01
-
-
Save hihats/462ef37ccf5b7ee57353 to your computer and use it in GitHub Desktop.
store trends of database size in 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 | |
| DB_USER="admin_user" | |
| DB_PASS="***" | |
| DB_NAME="admin" | |
| DB_HOST="192.168.1.11" | |
| TODAY=`date "+%Y%m%d"` | |
| FILE=/var/tmp/dbsize_daily_$TODAY.tsv | |
| ADMIN_MAIL="hishats@gmail.com" | |
| QUERY1="SELECT round(sum(data_length)/1024/1024) as 'data_vol(MB)' FROM information_schema.tables where table_schema = '$DBNAME'" | |
| QUERY2="SELECT table_name,table_rows,round(data_length/1024) as 'data_size(KB)',round(index_length/1024) as 'index_size(KB)' FROM information_schema.tables where table_schema = '$DB_NAME' ORDER BY data_length DESC" | |
| mysql -B -u$DB_USER -h$DB_HOST -p$DB_PASS -D $DB_NAME -e $QUERY1 > $FILE | |
| mysql -B -u$DB_USER -h$DB_HOST -p$DB_PASS -D $DB_NAME -e $QUERY2 >> $FILE | |
| # send mail | |
| iconv -f=utf8 -t=sjis $FILE | mail -s "DBSIZE_CHECK SUCCEED" $ADMIN_MAIL | |
| exit |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
MySQL ver