Skip to content

Instantly share code, notes, and snippets.

@hihats
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save hihats/462ef37ccf5b7ee57353 to your computer and use it in GitHub Desktop.

Select an option

Save hihats/462ef37ccf5b7ee57353 to your computer and use it in GitHub Desktop.
store trends of database size in file
#!/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
@hihats
Copy link
Copy Markdown
Author

hihats commented Jul 1, 2014

MySQL ver

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment