Saturday, March 15, 2025

1) drop #!/bin/bash # Oracle Schema Migration Script # Description: Exports a schema from Source DB (A) and imports into Target DB (B) # Pre-requisites: # - Oracle Data Pump directories must be configured on both databases # - User must have necessary privileges (EXP_FULL_DATABASE, IMP_FULL_DATABASE) # - Target schema user must exist in Database B # Configuration SOURCE_DB="SOURCE_USER/SOURCE_PASSWORD@DATABASE_A" TARGET_DB="TARGET_USER/TARGET_PASSWORD@DATABASE_B" SCHEMA_NAME="YOUR_SCHEMA_NAME" DATA_PUMP_DIR="DATA_PUMP_DIR_NAME" # Oracle directory object name DUMPFILE="${SCHEMA_NAME}_export.dmp" LOGFILE_EXPORT="${SCHEMA_NAME}_export.log" LOGFILE_IMPORT="${SCHEMA_NAME}_import.log" # Function to drop all objects in target schema drop_target_objects() { echo "Dropping all objects in target schema: ${SCHEMA_NAME}" sqlplus -S /nolog <" > $REPORT_FILE echo "Schema Comparison Report" >> $REPORT_FILE echo "" >> $REPORT_FILE echo "

Schema Comparison Report

" >> $REPORT_FILE # Step 3: Compare missing objects (tables, views, indexes, sequences, procedures) echo "

Missing Objects

" >> $REPORT_FILE echo "" >> $REPORT_FILE sqlplus -s $ORACLE_USER/$ORACLE_PASSWORD@$TARGET_DB_B < temp_missing_objects.txt SET PAGESIZE 500 SET LINESIZE 200 SET HEADING OFF SELECT 'Table', table_name FROM all_tables@${DBLINK_NAME} WHERE table_name NOT IN (SELECT table_name FROM all_tables WHERE owner = UPPER('$SCHEMA_NAME')); SELECT 'View', view_name FROM all_views@${DBLINK_NAME} WHERE view_name NOT IN (SELECT view_name FROM all_views WHERE owner = UPPER('$SCHEMA_NAME')); SELECT 'Index', index_name FROM all_indexes@${DBLINK_NAME} WHERE index_name NOT IN (SELECT index_name FROM all_indexes WHERE owner = UPPER('$SCHEMA_NAME')); SELECT 'Sequence', sequence_name FROM all_sequences@${DBLINK_NAME} WHERE sequence_name NOT IN (SELECT sequence_name FROM all_sequences WHERE owner = UPPER('$SCHEMA_NAME')); SELECT 'Procedure', object_name FROM all_procedures@${DBLINK_NAME} WHERE object_name NOT IN (SELECT object_name FROM all_procedures WHERE owner = UPPER('$SCHEMA_NAME')); EXIT; EOF while read line; do object_type=$(echo $line | awk '{print $1}') object_name=$(echo $line | awk '{$1=""; print $0}' | sed 's/^ *//g') if [ ! -z "$object_name" ]; then echo "" >> $REPORT_FILE fi done < temp_missing_objects.txt echo "
Object TypeObject Name
$object_type$object_name
" >> $REPORT_FILE rm temp_missing_objects.txt # Step 4: Compare row counts for all tables echo "

Row Count Differences

" >> $REPORT_FILE echo "" >> $REPORT_FILE sqlplus -s $ORACLE_USER/$ORACLE_PASSWORD@$TARGET_DB_B < temp_row_counts.txt SET PAGESIZE 500 SET LINESIZE 200 SET HEADING OFF SELECT table_name, (SELECT COUNT(*) FROM ${SCHEMA_NAME}."||table_name||"@$DBLINK_NAME) AS SRC_COUNT, (SELECT COUNT(*) FROM ${SCHEMA_NAME}."||table_name||") AS TGT_COUNT FROM all_tables WHERE owner = UPPER('$SCHEMA_NAME'); EXIT; EOF while read line; do table_name=$(echo $line | awk '{print $1}') src_count=$(echo $line | awk '{print $2}') tgt_count=$(echo $line | awk '{print $3}') if [ "$src_count" == "$tgt_count" ]; then status="MATCH" else status="MISMATCH" fi echo "" >> $REPORT_FILE done < temp_row_counts.txt echo "
Table NameSource CountTarget CountStatus
$table_name$src_count$tgt_count$status
" >> $REPORT_FILE rm temp_row_counts.txt # Step 5: Finish HTML Report echo "" >> $REPORT_FILE echo "Comparison report saved in: $REPORT_FILE" # Step 6: Display report in terminal cat $REPORT_FILE ############# ################## redo log ################## #!/bin/bash # Define Variables STANDBY_LIST_FILE="database_list.txt" # User-provided file containing one SCAN host and DB service ORA_USER="oracle" ORA_PASS="your_password" # Replace with secure password management method DGB_ADMIN_USER="sys" DGB_ADMIN_PASS="your_password" # Replace with actual password SLEEP_INTERVAL=10 # Time in seconds to wait before retrying MAX_RETRIES=3 # Maximum number of retries for log drops export ORACLE_SID="orcl" # Check if the input file exists if [[ ! -f "$STANDBY_LIST_FILE" ]]; then echo "Error: Standby list file ($STANDBY_LIST_FILE) not found!" exit 1 fi # Read primary SCAN and DB service from file read -r INPUT_SCAN INPUT_DB < "$STANDBY_LIST_FILE" echo "User-Provided SCAN: $INPUT_SCAN" echo "User-Provided DB Service: $INPUT_DB" # Prompt user for new redo log file size read -p "Enter the new redo log file size in MB: " NEW_LOG_SIZE_MB echo "### Step 1: Identify Primary & All Standby Databases Using Data Guard Broker ###" DGMGRL_OUTPUT=$(dgmgrl sys/$DGB_ADMIN_PASS@$INPUT_SCAN <