Skip to content

Commit c1ee48c

Browse files
committed
Add spinner
1 parent 3ee0777 commit c1ee48c

File tree

4 files changed

+45
-10
lines changed

4 files changed

+45
-10
lines changed

warehouse-discovery-scripts/oracle/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Run the script from your terminal, passing the Oracle connection string as the f
3737
The script's behavior can be customized by modifying the variables within the script itself:
3838

3939
- `ORACLE_CONN`: The Oracle connection string. This is passed as a command-line argument, as shown in the usage example.
40-
- `DURATION_DAYS`: The number of days of historical data to collect for AWR-based queries. Defaults to 30.
40+
- `DURATION_DAYS`: The number of days of historical data to collect for AWR-based queries. Defaults to 7.
4141
- `OUTPUT_DIR`: The directory where the generated CSV files will be stored. The script will create this directory if it doesn't already exist. Defaults to ./out.
4242
- `DISCOVERY_SQLS`: An array of SQL script filenames to be executed. You can easily add or remove scripts from this list to customize your data collection.
4343

warehouse-discovery-scripts/oracle/export.sql

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ WHENEVER SQLERROR EXIT 1;
22

33
-- Set SQL*Plus environment options for CSV output
44
SET HEADING ON
5+
SET FEEDBACK OFF
56
SET TERMOUT OFF
67
SET PAGESIZE 0
78
SET LINESIZE 32767
@@ -11,20 +12,22 @@ set UNDERLINE OFF
1112
SET MARKUP CSV ON
1213

1314
-- Accept the input file name and output file name as arguments
14-
DEFINE INPUT_FILE = &1
15+
DEFINE INPUT_SCRIPT = &1
1516
DEFINE OUTPUT_FILE = &2
17+
DEFINE DURATION_DAYS = &3
1618

1719
-- Spool the output to the specified CSV file
1820
SPOOL &OUTPUT_FILE
1921

2022
-- Execute the SQL statement from the input file
21-
@&INPUT_FILE;
23+
@&INPUT_SCRIPT &DURATION_DAYS;
2224
/
2325

2426
-- Stop spooling
2527
SPOOL OFF;
2628

2729
-- Reset SQL*Plus environment options
30+
SET FEEDBACK ON
2831
SET TERMOUT ON;
2932
SET PAGESIZE 50;
3033
SET LINESIZE 80;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
# Function to show the spinner animation
4+
show_spinner() {
5+
local -a chars=('/' '-' '\' '|')
6+
local i=0
7+
while true; do
8+
printf "\r${chars[$i]} "
9+
i=$(( (i+1) % ${#chars[@]} ))
10+
sleep 0.1
11+
done
12+
}
13+
14+
# Function to stop the spinner
15+
stop_spinner() {
16+
SPINNER_PID=$1
17+
kill $SPINNER_PID &>/dev/null
18+
wait $SPINNER_PID &>/dev/null
19+
printf "\r" # Clears the spinner line
20+
}

warehouse-discovery-scripts/oracle/tco_discovery.sh

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
#!/bin/bash
22

3+
source spinner.sh
4+
35
ORACLE_CONN="$1"
4-
DURATION_DAYS=30
6+
DURATION_DAYS=7
57
OUTPUT_DIR="./out"
68
DISCOVERY_SQLS=(
7-
"awr/sys-metric-history.sql" # CDB_HIST_SYSMETRIC_HISTORY - historical system statistics like CPU usage
8-
"awr/segment-stats.sql" # CDB_HIST_SEG_STAT - historical segment statistics
99
"native/used-space-details.sql" # CDB_SEGMENTS - used space
1010
"native/osstat.sql" # GV$OSSTAT - System statistics like NUM_CPUS
1111
"native/cell-config.sql" # GV$CELL - exadata cell configuration
1212
"native/db-info.sql" # V$DATABASE - Database info
1313
"native/app-schemas-pdbs.sql" # CDB_PDBS - Pluggable databases info
14+
"awr/sys-metric-history.sql" # CDB_HIST_SYSMETRIC_HISTORY - historical system statistics like CPU usage
15+
"awr/segment-stats.sql" # CDB_HIST_SEG_STAT - historical segment statistics
1416
)
1517
DISCOVERY_SQL_DIR="$(dirname "$0")/../../dumper/app/src/main/resources/oracle-stats/cdb"
18+
TMP_QUERY_FILE=".query.sql"
19+
EXPORT_SCRIPT="export.sql"
1620
mkdir -p "$OUTPUT_DIR"
1721

1822
# Run each SQL query and export result to CSV file
@@ -23,12 +27,19 @@ for sql_file in "${DISCOVERY_SQLS[@]}"; do
2327

2428
if [ -f "$file_path" ]; then
2529
echo "[INFO]: Executing $base_name.sql"
26-
SQL_OUTPUT=$(sqlplus -s "$ORACLE_CONN" @export.sql "$file_path" "$output_csv" "$DURATION_DAYS" 2>&1)
30+
31+
# Replace JDBC variable placeholder '?' with SQL*Plus substitution
32+
sed 's/?/\&1/' "$file_path" > "$TMP_QUERY_FILE"
33+
34+
# Show spinner
35+
show_spinner &
36+
SPINNER_PID=$!
37+
38+
# Run SQL*Plus
39+
sqlplus -s "$ORACLE_CONN" "@$EXPORT_SCRIPT" "$TMP_QUERY_FILE" "$output_csv" "$DURATION_DAYS"
40+
stop_spinner "$SPINNER_PID"
2741
if [ $? -ne 0 ]; then
2842
echo "[ERROR]: $base_name extraction failed."
29-
echo "--- Error Output ---"
30-
echo "$SQL_OUTPUT"
31-
echo "--------------------"
3243
else
3344
echo "[SUCCESS]: $base_name.sql extraction ran without errors."
3445
fi
@@ -47,3 +58,4 @@ EOL
4758

4859
# Build final ZIP artifact that can be used with BigQuery Migration Assessment.
4960
zip -j "oracle_assessment_tco.zip" $OUTPUT_DIR/*.csv $OUTPUT_DIR/*.yaml
61+
rm -rf "$TMP_QUERY_FILE"

0 commit comments

Comments
 (0)