Post check 1
#!/bin/bash
export ORACLE_SID=<your_cdb_sid>
export ORAENV_ASK=NO
. oraenv > /dev/null
LOG_DIR=/tmp/post_migration_check
mkdir -p "$LOG_DIR"
LOGFILE="$LOG_DIR/post_migration_check_$(date +%Y%m%d_%H%M%S).log"
exec_sql() {
sqlplus -s "/ as sysdba" <<EOF
set pages 100
set lines 200
set feedback off
set heading on
set echo off
col name for a20
col open_mode for a20
col restricted for a15
col object_type for a20
col object_name for a40
col owner for a20
col comp_name for a35
col status for a15
col wallet_status for a20
col tablespace_name for a30
col encrypted for a10
col activating_pdbname for a25
$1
exit
EOF
}
check_flag() {
if grep -iq "$2" <<< "$1"; then
echo "$3 : PASSED" | tee -a $LOGFILE
else
echo "$3 : NOT PASSED" | tee -a $LOGFILE
fi
}
echo "=== Post Migration Certification Checks ===" | tee -a $LOGFILE
# Step 1: PDB Open Status
echo -e "\n--- Step 1: CDB/PDB Open Modes ---" | tee -a $LOGFILE
pdb_open_status=$(exec_sql "SELECT name, open_mode, restricted FROM v\$pdbs;")
echo "$pdb_open_status" | tee -a $LOGFILE
check_flag "$pdb_open_status" "READ WRITE" "Step 1: CDB/PDB Open Status"
# Step 2: PDB Plug-in Violations
echo -e "\n--- Step 2: PDB Plug-in Violations ---" | tee -a $LOGFILE
pdb_violation_check=$(exec_sql "SELECT name, message_type, status, cause FROM pdb_plug_in_violations WHERE status='PENDING';")
echo "$pdb_violation_check" | tee -a $LOGFILE
check_flag "$pdb_violation_check" "no rows selected" "Step 2: PDB Plug-in Violations"
# Step 3: Listener Parameter
echo -e "\n--- Step 3: Listener Parameter ---" | tee -a $LOGFILE
listener_param=$(exec_sql "show parameter listener;")
echo "$listener_param" | tee -a $LOGFILE
check_flag "$listener_param" "listener" "Step 3: Listener Parameter"
# Step 4: SGA Parameters
echo -e "\n--- Step 4: SGA Parameters ---" | tee -a $LOGFILE
sga_params=$(exec_sql "show parameter sga;")
echo "$sga_params" | tee -a $LOGFILE
check_flag "$sga_params" "sga_target" "Step 4: SGA Parameters"
# Step 5: PGA Parameters
echo -e "\n--- Step 5: PGA Parameters ---" | tee -a $LOGFILE
pga_params=$(exec_sql "show parameter pga;")
echo "$pga_params" | tee -a $LOGFILE
check_flag "$pga_params" "pga_aggregate_target" "Step 5: PGA Parameters"
# Step 6: INVALID Objects in All PDBs
echo -e "\n--- Step 6: INVALID Objects in All PDBs ---" | tee -a $LOGFILE
invalid_objects_found=0
pdb_list=$(exec_sql "set heading off; SELECT name FROM v\$pdbs WHERE open_mode='READ WRITE';")
for pdb in $pdb_list; do
echo -e "\nChecking INVALID objects in $pdb..." | tee -a $LOGFILE
invalid_objects_in_pdb=$(sqlplus -s "/ as sysdba" <<EOF
ALTER SESSION SET CONTAINER=$pdb;
set pages 100 lines 200
col object_name for a40
col object_type for a20
col owner for a20
SELECT owner, object_type, object_name FROM dba_objects WHERE status='INVALID';
exit
EOF
)
echo "$invalid_objects_in_pdb" | tee -a $LOGFILE
if echo "$invalid_objects_in_pdb" | grep -iq "no rows selected"; then
echo "Step 6: INVALID objects in $pdb : PASSED" | tee -a $LOGFILE
else
echo "Step 6: INVALID objects in $pdb : NOT PASSED" | tee -a $LOGFILE
invalid_objects_found=1
fi
done
# Step 7: Component Status
echo -e "\n--- Step 7: Component Status ---" | tee -a $LOGFILE
component_status=$(exec_sql "SELECT comp_name, version, status FROM dba_registry;")
echo "$component_status" | tee -a $LOGFILE
check_flag "$component_status" "VALID" "Step 7: Component Status"
# Step 8: TDE Wallet Status
echo -e "\n--- Step 8: TDE Wallet Status ---" | tee -a $LOGFILE
tde_wallet_status=$(exec_sql "SELECT inst_id, wallet_type, wallet_status FROM gv\$encryption_wallet;")
echo "$tde_wallet_status" | tee -a $LOGFILE
check_flag "$tde_wallet_status" "OPEN" "Step 8: TDE Wallet Status"
# Step 9: TDE Keys Registered in PDBs
echo -e "\n--- Step 9: TDE Keys in PDBs ---" | tee -a $LOGFILE
tde_keys_registered=$(exec_sql "SELECT key_id, activating_pdbname FROM v\$encryption_keys;")
echo "$tde_keys_registered" | tee -a $LOGFILE
check_flag "$tde_keys_registered" "KEY_ID" "Step 9: TDE Keys Registered"
# Step 10: SSL Connection Check
echo -e "\n--- Step 10: SSL Connections ---" | tee -a $LOGFILE
ssl_connection_status=$(exec_sql "SELECT sid, serial#, network_service_banner FROM v\$session_connect_info WHERE network_service_banner LIKE '%SSL%';")
echo "$ssl_connection_status" | tee -a $LOGFILE
check_flag "$ssl_connection_status" "SSL" "Step 10: SSL Connection Enabled"
# Step 11: Encrypted Tablespaces
echo -e "\n--- Step 11: Encrypted Tablespaces ---" | tee -a $LOGFILE
encrypted_tablespaces=$(exec_sql "SELECT tablespace_name, encrypted FROM dba_tablespaces WHERE contents='PERMANENT';")
echo "$encrypted_tablespaces" | tee -a $LOGFILE
check_flag "$encrypted_tablespaces" "YES" "Step 11: Encrypted Tablespaces"
# Step 12: RMAN Controlfile Autobackup
echo -e "\n--- Step 12: RMAN Controlfile Autobackup ---" | tee -a $LOGFILE
rman_autobackup_status=$(rman target / <<EOF
show all;
exit
EOF
)
echo "$rman_autobackup_status" | tee -a $LOGFILE
check_flag "$rman_autobackup_status" "CONFIGURE CONTROLFILE AUTOBACKUP ON" "Step 12: RMAN Controlfile Autobackup"
# Step 13: Autosys Jobs
echo -e "\n--- Step 13: Autosys Jobs ---" | tee -a $LOGFILE
if command -v autorep >/dev/null; then
autosys_job_output=$(autorep -J % -q)
echo "$autosys_job_output" | tee -a $LOGFILE
check_flag "$autosys_job_output" "job" "Step 13: Autosys Jobs Found"
else
echo "Step 13: Autosys not installed or not in PATH. Please validate manually." | tee -a $LOGFILE
fi
# Step 14: OEM Monitoring (Outstanding Alerts)
echo -e "\n--- Step 14: OEM Outstanding Alerts ---" | tee -a $LOGFILE
oem_alerts_output=$(exec_sql "SELECT object_type, reason FROM dba_outstanding_alerts;")
echo "$oem_alerts_output" | tee -a $LOGFILE
check_flag "$oem_alerts_output" "no rows selected" "Step 14: OEM Alert Status"
# Step 15: SNOW Entry Check (custom table)
echo -e "\n--- Step 15: SNOW Entries (Custom Table) ---" | tee -a $LOGFILE
snow_entry_output=$(exec_sql "SELECT * FROM pdb_snow_entries;")
echo "$snow_entry_output" | tee -a $LOGFILE
check_flag "$snow_entry_output" "INC" "Step 15: SNOW Entry Presence"
# Step 16: Cloakware Users Onboarded
echo -e "\n--- Step 16: Cloakware Standard Users ---" | tee -a $LOGFILE
cloakware_user_check=$(exec_sql "SELECT username FROM dba_users WHERE username IN ('OPS_USER', 'APP_USER', 'SERVICE_ACCT');")
echo "$cloakware_user_check" | tee -a $LOGFILE
check_flag "$cloakware_user_check" "OPS_USER" "Step 16: Cloakware User Presence"
echo -e "\n=== ✅ All Post-Migration Checks Completed. Log: $LOGFILE ==="
Comments
Post a Comment