|
| 1 | +#!/bin/bash |
| 2 | +############################################################# |
| 3 | +--# Copyright (c) 2023, Oracle and/or its affiliates. |
| 4 | +--# Licensed under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl. |
| 5 | +--# Purpose: Discovery Script for MySQL Databases. |
| 6 | +--# This script is to be executed at the discovery phase before planning for migration/upgrade. |
| 7 | +--# Version : 1.1 |
| 8 | +--# USAGE : sh <filename.sh> . |
| 9 | +--# @author: Ajay Rao. |
| 10 | +############################################################## |
| 11 | + |
| 12 | +NOW=$(date +"%m") |
| 13 | +TIMESTAMP=$(date +"%F") |
| 14 | + |
| 15 | +#. ./setmy.env |
| 16 | + |
| 17 | +cd /tmp |
| 18 | +cat /dev/null > DB_REPORT.html |
| 19 | + |
| 20 | +printf '<b><u><font size="9" color="RED"><center>' >> DB_REPORT.html |
| 21 | +printf 'MySQL POC DATABASE SERVER AND INSTANCE DETAILS</center></b></u></font>' >> DB_REPORT.html |
| 22 | +printf '<br>' >> DB_REPORT.html |
| 23 | + |
| 24 | + |
| 25 | +printf '<b><p align="right"><font color="MidnightBlue"> ' >>DB_REPORT.html |
| 26 | +date >> DB_REPORT.html |
| 27 | +printf '</p></font></b>' >> DB_REPORT.html |
| 28 | + |
| 29 | + |
| 30 | +printf '<b><p><font size="6" color="Orange"><b><p align="left"> Server Details :- </p></font></b> ' >> DB_REPORT.html |
| 31 | +printf '<font color="MidnightBlue"><b><p align="left"> HOSTNAME NAME ' >> DB_REPORT.html |
| 32 | +hostname >> DB_REPORT.html |
| 33 | + |
| 34 | + |
| 35 | +printf '<br>' >> DB_REPORT.html |
| 36 | +printf ' IP ADDRESS ' >>DB_REPORT.html |
| 37 | +hostname -i >> DB_REPORT.html |
| 38 | +printf '</b></font></p>' >> DB_REPORT.html |
| 39 | + |
| 40 | +printf '<font color="MidnightBlue"><b><p align="left"> Source Operating System and Version details </p></b></font>' >>DB_REPORT.html |
| 41 | +printf '<pre>' >> DB_REPORT.html |
| 42 | +cat /etc/os-release | grep CPE_NAME >> DB_REPORT.html |
| 43 | +printf '</b></font></pre></p>' >> DB_REPORT.html |
| 44 | + |
| 45 | +printf '<font color="MidnightBlue"><b><p align="left"> Source Kernel version details </p></b></font>' >>DB_REPORT.html |
| 46 | +printf '<pre>' >> DB_REPORT.html |
| 47 | +uname -a >> DB_REPORT.html |
| 48 | +printf '</b></font></pre></p>' >> DB_REPORT.html |
| 49 | + |
| 50 | +printf '<font color="MidnightBlue"><b><p align="left"> CPU DETAILS </p></b></font>' >>DB_REPORT.html |
| 51 | +printf '<pre>' >> DB_REPORT.html |
| 52 | +lscpu | grep -i Architecture >> DB_REPORT.html |
| 53 | +lscpu | grep -i mode >> DB_REPORT.html |
| 54 | +lscpu | grep -i list >> DB_REPORT.html |
| 55 | +lscpu | grep -i family >> DB_REPORT.html |
| 56 | +lscpu | grep -i MHz >> DB_REPORT.html |
| 57 | +lscpu | grep -i Thread >> DB_REPORT.html |
| 58 | +lscpu | grep -i Socket >> DB_REPORT.html |
| 59 | +printf '</b></font></pre></p>' >> DB_REPORT.html |
| 60 | + |
| 61 | +printf '<font color="MidnightBlue"><b><p align="left"> CPU USAGE </p></b></font>' >>DB_REPORT.html |
| 62 | +printf '<pre>' >> DB_REPORT.html |
| 63 | +mpstat 2 2 >> DB_REPORT.html |
| 64 | +printf '</b></font></pre></p>' >> DB_REPORT.html |
| 65 | + |
| 66 | +printf '<font color="MidnightBlue"><b><p align="left"> MEMORY DETAILS </p></b></font>' >>DB_REPORT.html |
| 67 | +printf '<pre>' >> DB_REPORT.html |
| 68 | +free -m >> DB_REPORT.html |
| 69 | +printf '</b></font></pre></p>' >> DB_REPORT.html |
| 70 | + |
| 71 | +printf '<font color="MidnightBlue"><b><p align="left"> FILE SYSTEM DETAILS </p></b></font>' >>DB_REPORT.html |
| 72 | +printf '<pre>' >> DB_REPORT.html |
| 73 | +df -h /usr >> DB_REPORT.html |
| 74 | +#For Data Directory and binlogs |
| 75 | +df -h /var/lib/mysql>> DB_REPORT.html |
| 76 | +df -h / >> DB_REPORT.html |
| 77 | +printf '</b></font></pre></p>' >> DB_REPORT.html |
| 78 | + |
| 79 | + |
| 80 | +printf '<font color="MidnightBlue"><b><p align="left"> CRON DETAILS </p></b></font>' >>DB_REPORT.html |
| 81 | +printf '<pre>' >> DB_REPORT.html |
| 82 | +service crond status >> DB_REPORT.html |
| 83 | +crontab -l >> DB_REPORT.html |
| 84 | +printf '</b></font></pre></p>' >> DB_REPORT.html |
| 85 | + |
| 86 | +#MySQL DB details |
| 87 | + |
| 88 | +dbuser=$1 |
| 89 | +dbpwd=$2 |
| 90 | + |
| 91 | +printf '<b><p><font size="6" color="Orange"><b><p align="left"> MYSQL Database Details :- </p></font><b> ' >> DB_REPORT.html |
| 92 | +printf '<font color="MidnightBlue"><b><p align="left"> DATABASES </p></b></font>' >>DB_REPORT.html |
| 93 | +printf '<pre>' >> DB_REPORT.html |
| 94 | +mysql -u$dbuser -p$dbpwd -N -e "show databases;" >> DB_REPORT.html |
| 95 | +printf '</b></font>' >> DB_REPORT.html |
| 96 | +printf '</pre></p>' >> DB_REPORT.html |
| 97 | +printf '<br>' >> DB_REPORT.html |
| 98 | + |
| 99 | +printf '<font color="MidnightBlue"><b><p align="left"> MYSQL SERVER STATUS </p></b></font>' >> DB_REPORT.html |
| 100 | +printf '<pre>' >> DB_REPORT.html |
| 101 | +mysql -u$dbuser -p$dbpwd -N -e "\s\G" >> DB_REPORT.html |
| 102 | +printf '</b></font></pre></p>' >> DB_REPORT.html |
| 103 | +printf '<br>' >> DB_REPORT.html |
| 104 | + |
| 105 | + |
| 106 | +printf '<font color="MidnightBlue"><b><p align="left"> TOTAL SIZE OF ALL DATABASES </p></b></font>' >> DB_REPORT.html |
| 107 | +#printf '<br>' >> DB_REPORT.html |
| 108 | +mysql -u$dbuser -p$dbpwd -H -e "SELECT table_schema, ROUND(SUM(data_length+index_length)/1024/1024) AS total_mb, ROUND(SUM(data_length)/1024/1024) AS data_mb, ROUND(SUM(index_length)/1024/1024) AS index_mb, COUNT(*) AS tables, CURDATE() AS today FROM information_schema.tables where table_schema not in ('information_schema','sys','mysql','performance_schema') GROUP BY table_schema ORDER BY 2 DESC;" >> DB_REPORT.html |
| 109 | +printf '<br>' >> DB_REPORT.html |
| 110 | + |
| 111 | +printf '<font color="MidnightBlue"><b><p align="left"> CHARACTER SET OF POC DATABASE </p></b></font>' >> DB_REPORT.html |
| 112 | +#printf '<br>' >> DB_REPORT.html |
| 113 | +mysql -u$dbuser -p$dbpwd -H -e "SELECT SCHEMA_NAME,DEFAULT_CHARACTER_SET_NAME,DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA where SCHEMA_NAME not in ('information_schema','sys','mysql','performance_schema');" >> DB_REPORT.html |
| 114 | +printf '<br>' >> DB_REPORT.html |
| 115 | + |
| 116 | +printf '<font color="MidnightBlue"><b><p align="left"> DEFAULT STORAGE ENGINE OF POC DATABASE </p></b></font>' >> DB_REPORT.html |
| 117 | +mysql -u$dbuser -p$dbpwd -H -e "select ENGINE,SUPPORT,COMMENT,TRANSACTIONS, SAVEPOINTS from information_schema.engines where SUPPORT='DEFAULT';" >> DB_REPORT.html |
| 118 | +printf '<br>' >> DB_REPORT.html |
| 119 | + |
| 120 | +printf '<font color="MidnightBlue"><b><p align="left"> REPLICATION STATUS OF POC DATABASE </p></b></font>' >> DB_REPORT.html |
| 121 | +mysql -u$dbuser -p$dbpwd -H -e "SELECT SERVICE_STATE FROM performance_schema.replication_connection_status;" >> DB_REPORT.html |
| 122 | +mysql -u$dbuser -p$dbpwd -H -e "SELECT SERVICE_STATE FROM performance_schema.replication_applier_status;" >> DB_REPORT.html |
| 123 | +printf '<br>' >> DB_REPORT.html |
| 124 | + |
| 125 | +printf '<font color="MidnightBlue"><b><p align="left"> VIEW DETAILS OF POC MySQL INSTANCE </p></b></font>' >> DB_REPORT.html |
| 126 | +mysql -u$dbuser -p$dbpwd -H -e " select * from information_schema.tables where table_type='VIEW' and TABLE_SCHEMA != 'sys';" >> DB_REPORT.html |
| 127 | +printf '<br>' >> DB_REPORT.html |
| 128 | + |
| 129 | +printf '<font color="MidnightBlue"><b><p align="left"> PARTITIONING DETAILS OF POC MySQL INSTANCE </p></b></font>' >> DB_REPORT.html |
| 130 | +mysql -u$dbuser -p$dbpwd -H -e " select TABLE_SCHEMA,TABLE_NAME,PARTITION_NAME from information_schema.PARTITIONS where TABLE_SCHEMA not in ('information_schema','sys','mysql','performance_schema') ;" >> DB_REPORT.html |
| 131 | +printf '<br>' >> DB_REPORT.html |
| 132 | + |
| 133 | +printf '<font color="MidnightBlue"><b><p align="left"> BACKUP DETAILS OF BASH2 MySQL DATABASE INSTANCE </p></b></font>' >> DB_REPORT.html |
| 134 | +#printf '<pre>' >> DB_REPORT.html |
| 135 | +ls -lrth /root/Ajay/backups/*.sql | tail >>DB_REPORT.html |
| 136 | + |
| 137 | +#ls -lrth $BACKUP_DIR/mysql*.gz >>DB_REPORT.html |
| 138 | +printf '</pre><br>' >> DB_REPORT.html |
| 139 | +printf '<br>' >> DB_REPORT.html |
| 140 | + |
| 141 | +#printf '<font color="MidnightBlue"><b><p align="left"> MYSQL INSTANCE GLOBAL VARIABLES </p></b></font>' >> DB_REPORT.html |
| 142 | +#printf '<pre>' >> DB_REPORT.html |
| 143 | +mysql -u$dbuser -p$dbpwd -N -e "show global variables" | sed 's/\t/","/g;s/^/"/;s/$/"/' > /tmp/globalvariables.csv |
| 144 | +sed -i -e '1i"Variable","Value"' /tmp/globalvariables.csv |
| 145 | +#printf '</b></font></pre></p>' >> DB_REPORT.html |
| 146 | +#printf '<br>' >> DB_REPORT.html |
| 147 | + |
| 148 | +printf '<font color="MidnightBlue"><b><p align="left"> CLUSTER STATUS OF POC DATABASE </p></b></font>' >> DB_REPORT.html |
| 149 | +grep -e address -e cluster /etc/my.cnf >> DB_REPORT.html |
| 150 | +#mysql -u$dbuser -p$dbpwd -H -e "show status --cluster" >> DB_REPORT.html |
| 151 | +#mysql -u$dbuser -p$dbpwd -H -e "show status --operation" >> DB_REPORT.html |
| 152 | +#mysql -u$dbuser -p$dbpwd -H -e "show status --process" >> DB_REPORT.html |
| 153 | +#mysql -u$dbuser -p$dbpwd -H -e "show status --progress" >> DB_REPORT.html |
| 154 | +mysql -u$dbuser -p$dbpwd -H -e "show status \G" >> DB_REPORT.html |
| 155 | +printf '<br>' >> DB_REPORT.html |
| 156 | + |
| 157 | +printf '<font color="MidnightBlue"><b><p align="left"> GALERA CLUSTER STATUS OF MySQL Instance </p></b></font>' >> DB_REPORT.html |
| 158 | +mysql -u$dbuser -p$dbpwd -H -e "SHOW GLOBAL STATUS LIKE 'wsrep_%';" >> DB_REPORT.html |
| 159 | +printf '<br>' >> DB_REPORT.html |
| 160 | + |
| 161 | +printf '<font color="MidnightBlue"><b><p align="left"> MASTER_SLAVE Information OF MySQL Instance </p></b></font>' >> DB_REPORT.html |
| 162 | +mysql -u$dbuser -p$dbpwd -H -e "show master status\G;" >> DB_REPORT.html |
| 163 | +mysql -u$dbuser -p$dbpwd -H -e "show slave status \G;" >> DB_REPORT.html |
| 164 | +mysql -u$dbuser -p$dbpwd -H -e "show slave hosts;" >> DB_REPORT.html |
| 165 | +printf '<br>' >> DB_REPORT.html |
| 166 | + |
| 167 | +printf '<font color="MidnightBlue"><b><p align="left"> Table Repairs check Information OF MySQL Instance </p></b></font>' >> DB_REPORT.html |
| 168 | +mysqlcheck -c -u$dbuser -p$dbpwd --all-databases >> DB_REPORT.html |
| 169 | +printf '<br>' >> DB_REPORT.html |
| 170 | + |
| 171 | +printf '<br>' >> DB_REPORT.html |
| 172 | + |
| 173 | +printf '<b><font size="6" color="RED"><center> ------------End Health Check Report------------ </center></b></font>' >> DB_REPORT.html |
| 174 | + |
0 commit comments