How to Identify the Creation Timestamp of an Oracle ASM Disk
Recently, I needed to determine the?creation timestamp?of an?Oracle ASM disk?from the?operating system level. Since such data is typically stored in the?disk header, I decided to analyze it directly.
To achieve this, I used?kfed (Kernel Filesystem Editor)—an Oracle utility designed for?inspecting and modifying ASM disk headers. This tool provides?low-level access?to ASM metadata, making it invaluable for?troubleshooting, forensic analysis, and recovery operations.
During my investigation, one particular field caught my attention:?
...
kfdhdb.crestmp.hi: 33173612 ; 0x0a8: HOUR=0xc DAYS=0x3 MNTH=0xc YEAR=0x7e8
kfdhdb.crestmp.lo: 2326086656 ; 0x0ac: USEC=0x0 MSEC=0x151 SECS=0x2a MINS=0x22
...
Obviously crestmp is an "creation timestamp" and can be used for data extraction.
Since the timestamp values are stored in a structured form, they need to be?converted into a readable date and time format. Additionally, to get a comprehensive view, it's necessary to?iterate through all ASM disks?and inspect specific fields.
领英推è
Below is a?short script?I created to quickly display this information for all ASM disks for both cases AFD and ASMlib:
#!/bin/bash
#===========================================================================================================================
# Description: shell script for output of ASM disks creation timestamp
# Author: Mykola Jurko
# Execute under ASM binaries owner (normally 'oracle').
#===========================================================================================================================
. oraenv <<EOF
+ASM
EOF
lvASMCheck=$($ORACLE_HOME/bin/asmcmd afd_state 2>&1 | grep ASMCMD-9526 | wc -l);
lvASMLibCheck=$(oracleasm status 2>&1 | grep "Checking if ASM is loaded" | wc -l);
if [[ $lvASMCheck -eq 1 ]]; then
echo "[INFO] Oracle AFD was found to be loaded.";
lvASMDisksAll=$($ORACLE_HOME/bin/asmcmd afd_lsdsk | awk '{print $1}' | tail -n +4);
lvPrefix="AFD" ;
else
if [[ $lvASMLibCheck -eq 1 ]]; then
echo "[INFO] Oracle ASM lib was found to be loaded.";
if [[ $(oracleasm listdisks | wc -l) -gt 0 ]]; then
lvASMDisksAll=$(oracleasm listdisks;);
else
lvASMDisksAll="";
fi
lvPrefix="ORCL" ;
else
echo "[ERROR] Neither AFD, neither ASM lib were found to be loaded. Script will show no ASM disk info.";
fi
fi
printf -- '-%.0s' {1..62};printf '\n'
printf " %-30s | %-30s \n" "ASM DISK" "CREATION TIMESTAMP";
printf -- '-%.0s' {1..62};printf '\n'
while read -r lvDiskName; do
if [[ -z $lvDiskName ]]; then
continue;
fi
lvCreStmp=$($ORACLE_HOME/bin/kfed read $lvPrefix:$lvDiskName | grep crestmp);
# Extract individual values using grep & awk
lvYear=$(echo "$lvCreStmp" | grep 'YEAR' | awk -F'YEAR=0x' '{print $2}' | awk '{print $1}')
lvMonth=$(echo "$lvCreStmp" | grep 'MNTH' | awk -F'MNTH=0x' '{print $2}' | awk '{print $1}')
lvDay=$(echo "$lvCreStmp" | grep 'DAYS' | awk -F'DAYS=0x' '{print $2}' | awk '{print $1}')
lvHour=$(echo "$lvCreStmp" | grep 'HOUR' | awk -F'HOUR=0x' '{print $2}' | awk '{print $1}')
lvMinute=$(echo "$lvCreStmp" | grep 'MINS' | awk -F'MINS=0x' '{print $2}' | awk '{print $1}')
lvSecond=$(echo "$lvCreStmp" | grep 'SECS' | awk -F'SECS=0x' '{print $2}' | awk '{print $1}')
lvMillisecond=$(echo "$lvCreStmp" | grep 'MSEC' | awk -F'MSEC=0x' '{print $2}' | awk '{print $1}')
# Convert hex values to decimal
lvYear=$((16#$lvYear))
lvMonth=$((16#$lvMonth))
lvDay=$((16#$lvDay))
lvHour=$((16#$lvHour))
lvMinute=$((16#$lvMinute))
lvSecond=$((16#$lvSecond))
lvMillisecond=$((16#$lvMillisecond))
printf " %-30s | %04d-%02d-%02d %02d:%02d:%02d.%03d UTC \n" "$lvPrefix:$lvDiskName" "$lvYear" "$lvMonth" "$lvDay" "$lvHour" "$lvMinute" "$lvSecond" "$lvMillisecond";
done < <(echo "${lvASMDisksAll}");
Example of output:
Senior Principal Consultant at Oracle | Oracle DBCS | EXACS | EXADATA | ATP & ADW | Golden Gate | Oracle RAC | Weblogic Admin | Zero Downtime Migration (ZDM)
2 周Thank you very much for this script. Really helpful.
Digital platform Manager
1 个月Nice one buddy, this was always a challenge and never thought of it, good one indeed ??