#!/bin/bash # # Oracle DR Weekly Test with Proxmox PVE::Notify # Automated DR test with notifications via Proxmox notification system # # Location: /opt/scripts/weekly-dr-test-proxmox.sh (on Proxmox host) # Schedule: Add to cron for weekly execution (Saturdays) # # This script is SELF-SUFFICIENT: # - Automatically creates notification templates if they don't exist # - Uses Proxmox native notification system # - No email configuration needed - uses existing Proxmox setup # # Installation: # cp weekly-dr-test-proxmox.sh /opt/scripts/ # chmod +x /opt/scripts/weekly-dr-test-proxmox.sh # /opt/scripts/weekly-dr-test-proxmox.sh --install # Creates templates # crontab -e # Add: 0 6 * * 6 /opt/scripts/weekly-dr-test-proxmox.sh # # Author: Claude (based on ha-monitor.sh pattern) # Version: 1.0 set -euo pipefail # Configuration DR_VM_ID="109" DR_VM_IP="10.0.20.37" DR_VM_PORT="22122" DR_VM_USER="romfast" BACKUP_PATH="/mnt/pve/oracle-backups/ROA/autobackup" MAX_RESTORE_TIME_MIN=30 TEMPLATE_DIR="/usr/share/pve-manager/templates/default" LOG_DIR="/var/log/oracle-dr" LOG_FILE="$LOG_DIR/dr_test_$(date +%Y%m%d_%H%M%S).log" # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # Create log directory mkdir -p "$LOG_DIR" # Function to create notification templates create_templates() { echo -e "${GREEN}Creating Oracle DR test notification templates...${NC}" # Create templates directory if needed mkdir -p "$TEMPLATE_DIR" # Subject template cat > "$TEMPLATE_DIR/oracle-dr-test-subject.txt.hbs" <<'EOF' Oracle DR Test {{severity}} - {{test_result}} EOF # Text body template cat > "$TEMPLATE_DIR/oracle-dr-test-body.txt.hbs" <<'EOF' Oracle DR Test {{severity}} - {{test_result}} {{#if is_success}}TEST PASSED✓{{else}}TEST FAILED✗{{/if}} ======================================== SUMMARY: Duration {{total_duration}}min | Tables {{tables_restored}} | Backups {{backup_count}} TEST STEPS: {{#each test_steps}} - {{#if this.passed}}PASS{{else}}FAIL{{/if}}: {{this.name}} ({{this.duration}}s) {{#if this.details}} Details: {{this.details}} {{/each}} ======================================== COMPONENT STATUS: DR VM: ID {{vm_id}} ({{vm_ip}}) - {{vm_status}} NFS Mount: {{nfs_status}} - {{#if nfs_ok}}OK{{else}}FAILED{{/if}} Database: {{database_status}} - {{#if database_ok}}OK{{else}}FAILED{{/if}} Disk Space: {{disk_freed}}GB freed - OK {{#if errors}} ERRORS: {{#each errors}} - {{this}} {{/each}} {{/if}} ======================================== Log: {{log_file}} Next scheduled test: Next Saturday 06:00 Proxmox DR Monitoring System EOF # HTML body template (identical to text for compatibility) cat > "$TEMPLATE_DIR/oracle-dr-test-body.html.hbs" <<'EOF' Oracle DR Test {{severity}} - {{test_result}} {{#if is_success}}TEST PASSED✓{{else}}TEST FAILED✗{{/if}} ======================================== SUMMARY: Duration {{total_duration}}min | Tables {{tables_restored}} | Backups {{backup_count}} TEST STEPS: {{#each test_steps}} - {{#if this.passed}}PASS{{else}}FAIL{{/if}}: {{this.name}} ({{this.duration}}s) {{#if this.details}} Details: {{this.details}} {{/each}} ======================================== COMPONENT STATUS: DR VM: ID {{vm_id}} ({{vm_ip}}) - {{vm_status}} NFS Mount: {{nfs_status}} - {{#if nfs_ok}}OK{{else}}FAILED{{/if}} Database: {{database_status}} - {{#if database_ok}}OK{{else}}FAILED{{/if}} Disk Space: {{disk_freed}}GB freed - OK {{#if errors}} ERRORS: {{#each errors}} - {{this}} {{/each}} {{/if}} ======================================== Log: {{log_file}} Next scheduled test: Next Saturday 06:00 Proxmox DR Monitoring System EOF .section { margin: 20px 0; padding: 15px; background-color: #f8f9fa; border-radius: 5px; } .success { color: #28a745; font-weight: bold; } .error { color: #dc3545; font-weight: bold; } .warning { color: #ffc107; font-weight: bold; } .info { color: #17a2b8; } .test-steps { margin: 20px 0; } .step { padding: 10px; margin: 5px 0; border-left: 4px solid; background-color: white; } .step.passed { border-color: #28a745; } .step.failed { border-color: #dc3545; background-color: #f8d7da; } .metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 15px; margin: 20px 0; } .metric-card { background: white; padding: 15px; border-radius: 5px; text-align: center; box-shadow: 0 2px 4px rgba(0,0,0,0.1); } .metric-value { font-size: 24px; font-weight: bold; color: #495057; } .metric-label { font-size: 14px; color: #6c757d; margin-top: 5px; } .timeline { position: relative; padding: 20px 0; } .timeline-item { display: flex; margin-bottom: 20px; } .timeline-marker { width: 20px; height: 20px; border-radius: 50%; margin-right: 15px; flex-shrink: 0; } .timeline-marker.success { background-color: #28a745; } .timeline-marker.failed { background-color: #dc3545; } table { width: 100%; border-collapse: collapse; margin: 10px 0; } th, td { padding: 10px; text-align: left; border-bottom: 1px solid #dee2e6; } th { background-color: #e9ecef; font-weight: bold; }
{{date}} | Duration: {{total_duration}} minutes
| Component | Value | Status |
|---|---|---|
| DR VM | ID: {{vm_id}} ({{vm_ip}}) | {{vm_status}} |
| NFS Mount | F:\ drive | {{nfs_status}} |
| Database | ROA | {{database_status}} |
| Disk Space Freed | {{disk_freed}} GB | ✓ |
Log File: {{log_file}}
Next Scheduled Test: Next Saturday 06:00