Decommission pre check
#!/bin/bash
# Function to log messages with timestamp
LOG_FILE="decommission_precheck_${ORACLE_SID}.log"
log() {
local message=$1
echo "$(date +'%Y-%m-%d %H:%M:%S') $message" | tee -a $LOG_FILE
}
# Check if correct arguments are provided
if [ $# -ne 2 ]; then
echo "Usage: $0 <ORACLE_SID> <frame>"
exit 1
fi
# Export environment variables
export ORAENV_ASK=NO
export ORACLE_SID=$1
export frame=$2
db_name=${ORACLE_SID%?}
# Load Oracle environment
. oraenv
# Start logging
log "Precheck gather information process started for ORACLE_SID: $ORACLE_SID"
# Generate report file
report_file="pre_check_report_$(date +%F).log"
# Execute SQL script
log "Executing queries.sql to gather database information."
sqlplus -s / as sysdba <<EOF >> $report_file
@queries.sql
exit;
EOF
# Retrieve DB unique name
log "Retrieving DB unique name from the database."
db_unique_name=$(sqlplus -s / as sysdba <<EOF | tr -d '[:space:]'
set heading off
set feedback off
set pagesize 0
select db_unique_name from v\$database;
exit;
EOF
)
if [ -z "$db_unique_name" ]; then
log "Failed to retrieve DB unique name."
exit 1
fi
log "DB unique name: $db_unique_name"
# Execute autosys.ksh script
log "Running autosys.ksh with parameters."
./autosys.ksh h "$frame-d" "$db_unique_name" -c delete
# Data Guard information logging
dr_info="dr_info_$(date +%F).log"
log "Checking Data Guard configuration."
dgmgrl / <<EOF > $dr_info
show configuration;
EOF
if grep -qE "ORA-16525|ORA-16596" "$dr_info"; then
log "Data Guard not available for $db_unique_name."
fi
# Switch to ASM instance
export ORACLE_SID=$(ps -ef | grep "[a]sm_smon.*+ASM" | awk '{print $NF}' | cut -d '_' -f3)
if [ -z "$ORACLE_SID" ]; then
log "Failed to switch to ASM instance."
exit 1
fi
log "Switched to ASM instance: $ORACLE_SID"
. oraenv <<< "$ORACLE_SID"
# Check Goldengate status
log "Checking Goldengate status."
agctl status goldengate > goldengate_status_log.log
srvctl status database -d "$db_unique_name" -v >> $report_file
running_instances_with_manager=$(grep "is running" goldengate_status_log.log | awk '{gsub(/^\**|\**$/, "", $0); print $NF":"$3}')
if [ -z "$running_instances_with_manager" ]; then
log "No running instances with Goldengate manager found."
else
log "Running instances with Goldengate manager: $running_instances_with_manager"
echo "$running_instances_with_manager" >> $report_file
# Loop through each instance and check Goldengate status
for instance_with_manager in $running_instances_with_manager; do
node_name=$(echo $instance_with_manager | cut -d':' -f1)
manager_name=$(echo $instance_with_manager | cut -d':' -f2)
log "Logging into $node_name to check Goldengate status for $manager_name"
ssh $node_name <<EOF >> $report_file
export ORACLE_SID=$(ps -ef | grep [a]sm_smon.*+ASM | awk '{print \$NF}' | cut -d'+' -f3)
. oraenv <<< "\$ORACLE_SID"
/auto/data.misc/oracle/ogg_distribution/automation_scripts/gg_processes.sh
/auto/data.misc/oracle/ogg_distribution/automation_scripts/gg_pumps.sh
EOF
done
fi
log "Precheck gather information process completed."
Comments
Post a Comment