[oracle@srv1 ~]$ cat rman_backup_report_enhanced.sh
#!/bin/bash
# ===== CONFIGURATION =====
REPORT_DIR="/tmp"
DATE_TAG=$(date +%Y%m%d_%H%M%S)
TEXT_REPORT="$REPORT_DIR/rman_report_$DATE_TAG.log"
HTML_REPORT="$REPORT_DIR/rman_report_$DATE_TAG.html"
# Email (optional)
EMAIL_TO="your_email@example.com"
SEND_EMAIL=false # change to true if mailx configured
# ===== INIT =====
echo "RMAN Backup Report - $(date)" > $TEXT_REPORT
# HTML Header
cat <<EOF > $HTML_REPORT
<html>
<head>
<style>
body { font-family: Arial; }
table { border-collapse: collapse; width: 100%; }
th, td { border: 1px solid black; padding: 6px; text-align: center; }
th { background-color: #333; color: white; }
.success { background-color: #c6efce; }
.failed { background-color: #ffc7ce; }
</style>
</head>
<body>
<h2>RMAN Backup Report</h2>
<p>Generated on: $(date)</p>
<table>
<tr>
<th>DB Name</th>
<th>Input Type</th>
<th>Status</th>
<th>Start Time</th>
<th>End Time</th>
<th>Duration (Min)</th>
<th>Size (MB)</th>
</tr>
EOF
TOTAL_DB=0
FAILED_COUNT=0
# ===== LOOP DATABASES =====
grep -v '^#' /etc/oratab | grep -v '^$' | while IFS=: read ORACLE_SID ORACLE_HOME REST
do
export ORACLE_SID
export ORACLE_HOME
export PATH=$ORACLE_HOME/bin:$PATH
TOTAL_DB=$((TOTAL_DB+1))
echo "Checking DB: $ORACLE_SID" >> $TEXT_REPORT
RESULT=$(sqlplus -s / as sysdba <<EOF
SET HEADING OFF FEEDBACK OFF PAGESIZE 0 LINESIZE 300
SELECT
'$ORACLE_SID' || '|' ||
INPUT_TYPE || '|' ||
STATUS || '|' ||
TO_CHAR(START_TIME,'DD-MON-YYYY HH24:MI') || '|' ||
TO_CHAR(END_TIME,'DD-MON-YYYY HH24:MI') || '|' ||
ROUND((END_TIME - START_TIME)*24*60) || '|' ||
ROUND(OUTPUT_BYTES/1024/1024)
FROM
V\$RMAN_BACKUP_JOB_DETAILS
WHERE
START_TIME > SYSDATE - 1
ORDER BY START_TIME DESC;
EXIT;
EOF
)
echo "$RESULT" | while IFS="|" read DB INPUT STATUS START END DURATION SIZE
do
[[ -z "$DB" ]] && continue
# Failure detection
CLASS="success"
if [[ "$STATUS" != "COMPLETED" ]]; then
CLASS="failed"
FAILED_COUNT=$((FAILED_COUNT+1))
fi
# Text report
printf "%-10s %-12s %-10s %-18s %-18s %-8s %-8s\n" \
"$DB" "$INPUT" "$STATUS" "$START" "$END" "$DURATION" "$SIZE" >> $TEXT_REPORT
# HTML report
cat <<ROW >> $HTML_REPORT
<tr class="$CLASS">
<td>$DB</td>
<td>$INPUT</td>
<td>$STATUS</td>
<td>$START</td>
<td>$END</td>
<td>$DURATION</td>
<td>$SIZE</td>
</tr>
ROW
done
done
# ===== SUMMARY =====
cat <<EOF >> $HTML_REPORT
</table>
<h3>Summary</h3>
<p>Total Databases Checked: $TOTAL_DB</p>
<p>Failed Jobs: $FAILED_COUNT</p>
</body>
</html>
EOF
echo "====================================" >> $TEXT_REPORT
echo "Total DB Checked: $TOTAL_DB" >> $TEXT_REPORT
echo "Failed Jobs: $FAILED_COUNT" >> $TEXT_REPORT
# ===== EMAIL =====
if [ "$SEND_EMAIL" = true ]; then
mailx -s "RMAN Backup Report" -a "$HTML_REPORT" "$EMAIL_TO" < $TEXT_REPORT
fi
# ===== OUTPUT =====
echo "Text Report : $TEXT_REPORT"
echo "HTML Report : $HTML_REPORT"