#!/bin/bash # Quick Backup Verification - Verificare zilnică că backup-urile sunt OK # Rulează acest script ZILNIC (automat via cron) pentru monitoring BACKUP_DIR="/opt/oracle/backups/primary" LOG_FILE="/opt/oracle/logs/dr/verify_$(date +%Y%m%d).log" # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' log() { local message="$1" local level="${2:-INFO}" local timestamp=$(date '+%Y-%m-%d %H:%M:%S') case "$level" in "ERROR") color="$RED" ;; "SUCCESS") color="$GREEN" ;; "WARNING") color="$YELLOW" ;; *) color="$NC" ;; esac echo -e "${color}[$timestamp] [$level] $message${NC}" | tee -a "$LOG_FILE" } alert_email() { # TODO: Configure email alerts # echo "$1" | mail -s "Oracle DR Alert" admin@company.com log "ALERT: $1" "ERROR" } # ==================== CHECKS ==================== log "=== DR Backup Verification Started ===" "INFO" # Check 1: Backup directory exists if [ ! -d "$BACKUP_DIR" ]; then alert_email "Backup directory not found: $BACKUP_DIR" exit 1 fi log "✅ Backup directory exists" # Check 2: Backup files present backup_count=$(find "$BACKUP_DIR" -name "*.BKP" -o -name "*.bkp" 2>/dev/null | wc -l) if [ "$backup_count" -eq 0 ]; then alert_email "No backup files found in $BACKUP_DIR" exit 1 fi log "✅ Found $backup_count backup file(s)" # Check 3: Latest backup age latest_backup=$(find "$BACKUP_DIR" -name "*.BKP" -o -name "*.bkp" 2>/dev/null | head -1) if [ -z "$latest_backup" ]; then alert_email "No backup files found!" exit 1 fi latest_backup_age=$(( ($(date +%s) - $(stat -c %Y "$latest_backup")) / 3600 )) log "Latest backup: $(basename $latest_backup)" log "Backup age: $latest_backup_age hours" if [ $latest_backup_age -gt 30 ]; then alert_email "Latest backup is too old: $latest_backup_age hours (expected <30h)" log "❌ Backup TOO OLD!" "ERROR" exit 1 elif [ $latest_backup_age -gt 26 ]; then log "⚠️ Backup is getting old (>26h)" "WARNING" else log "✅ Backup age is good (<26h)" "SUCCESS" fi # Check 4: Backup size reasonable backup_size=$(du -sh "$BACKUP_DIR" 2>/dev/null | awk '{print $1}') log "Total backup size: $backup_size" # Check 5: Disk space available free_space=$(df -h "$BACKUP_DIR" | tail -1 | awk '{print $4}') free_space_gb=$(df -BG "$BACKUP_DIR" | tail -1 | awk '{print $4}' | sed 's/G//') log "Free disk space: $free_space ($free_space_gb GB)" if [ "$free_space_gb" -lt 10 ]; then alert_email "Low disk space on DR: only ${free_space_gb}GB free!" log "❌ DISK SPACE LOW!" "ERROR" elif [ "$free_space_gb" -lt 20 ]; then log "⚠️ Disk space getting low (<20GB)" "WARNING" else log "✅ Disk space OK (>20GB free)" "SUCCESS" fi # Check 6: File integrity (quick check - just read first and last block) log "Running quick file integrity check..." if head -c 1024 "$latest_backup" > /dev/null 2>&1 && tail -c 1024 "$latest_backup" > /dev/null 2>&1; then log "✅ Backup file is readable" "SUCCESS" else alert_email "Backup file appears corrupted: $latest_backup" log "❌ BACKUP FILE CORRUPTED!" "ERROR" exit 1 fi # Check 7: List all backup files with details log "" log "=== Backup Files Inventory ===" "INFO" find "$BACKUP_DIR" -name "*.BKP" -o -name "*.bkp" 2>/dev/null | while read file; do size=$(du -h "$file" | awk '{print $1}') age=$(( ($(date +%s) - $(stat -c %Y "$file")) / 3600 )) log " - $(basename $file): $size (${age}h old)" done # Summary log "" log "=== Verification Summary ===" "INFO" log "✅ Backup directory: OK" log "✅ Backup files: $backup_count present" log "✅ Latest backup age: ${latest_backup_age}h (threshold: 30h)" log "✅ Disk space: ${free_space_gb}GB free" log "✅ File integrity: OK" log "" log "=== DR Backup Verification COMPLETED ===" "SUCCESS" exit 0