Skip to content

Commit 8c0f4e9

Browse files
Merge pull request #74 from oracle-devrel/lift-mysl-discovery-script
lift-mysql-discovery-script
2 parents 3851657 + 3edd42c commit 8c0f4e9

File tree

4 files changed

+265
-0
lines changed

4 files changed

+265
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Copyright (c) 2023 Oracle and/or its affiliates.
2+
3+
The Universal Permissive License (UPL), Version 1.0
4+
5+
Subject to the condition set forth below, permission is hereby granted to any
6+
person obtaining a copy of this software, associated documentation and/or data
7+
(collectively the "Software"), free of charge and under any and all copyright
8+
rights in the Software, and any and all patent rights owned or freely
9+
licensable by each licensor hereunder covering either (i) the unmodified
10+
Software as contributed to or provided by such licensor, or (ii) the Larger
11+
Works (as defined below), to deal in both
12+
13+
(a) the Software, and
14+
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
15+
one is included with the Software (each a "Larger Work" to which the Software
16+
is contributed by such licensors),
17+
18+
without restriction, including without limitation the rights to copy, create
19+
derivative works of, display, perform, and distribute the Software and make,
20+
use, sell, offer for sale, import, export, have made, and have sold the
21+
Software and the Larger Work(s), and to sublicense the foregoing rights on
22+
either these or other terms.
23+
24+
This license is subject to the following condition:
25+
The above copyright notice and either this complete permission notice or at
26+
a minimum a reference to the UPL must be included in all copies or
27+
substantial portions of the Software.
28+
29+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35+
SOFTWARE.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# MySQL Database Discovery Utility
2+
3+
MySQL Database Discovery and Analysis Utility is a discovery utility to fetch the database information and the host details. In order to capture complete details of the source MySQL instance, the discovery script will help us fetch the necessary information. It is a shell script with HTML tags embedded to help connect to source instances and fetch the details. This script runs in any flavor of Linux version and any MySQL version 5.6 and above.
4+
5+
## When to use this asset?
6+
7+
This script is to be executed in the discovery phase if it is identified the MySQL on-premises database is to be migrated to OCI.
8+
9+
## How to use this asset?
10+
11+
- Copy ` MySQLdiscovery.sh ` file to the Linux server.
12+
13+
- To execute the script: ``` sh MySQLdiscovery.sh ``` .
14+
The script will generate a DB_REPORT.html file at ` /tmp` location of the server.
15+
16+
## License
17+
Copyright (c) 2023 Oracle and/or its affiliates.
18+
19+
Licensed under the Universal Permissive License (UPL), Version 1.0.
20+
21+
See [LICENSE](LICENSE) for more details.
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
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+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Copyright (c) 2023 Oracle and/or its affiliates.
2+
3+
The Universal Permissive License (UPL), Version 1.0
4+
5+
Subject to the condition set forth below, permission is hereby granted to any
6+
person obtaining a copy of this software, associated documentation and/or data
7+
(collectively the "Software"), free of charge and under any and all copyright
8+
rights in the Software, and any and all patent rights owned or freely
9+
licensable by each licensor hereunder covering either (i) the unmodified
10+
Software as contributed to or provided by such licensor, or (ii) the Larger
11+
Works (as defined below), to deal in both
12+
13+
(a) the Software, and
14+
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
15+
one is included with the Software (each a "Larger Work" to which the Software
16+
is contributed by such licensors),
17+
18+
without restriction, including without limitation the rights to copy, create
19+
derivative works of, display, perform, and distribute the Software and make,
20+
use, sell, offer for sale, import, export, have made, and have sold the
21+
Software and the Larger Work(s), and to sublicense the foregoing rights on
22+
either these or other terms.
23+
24+
This license is subject to the following condition:
25+
The above copyright notice and either this complete permission notice or at
26+
a minimum a reference to the UPL must be included in all copies or
27+
substantial portions of the Software.
28+
29+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35+
SOFTWARE.

0 commit comments

Comments
 (0)