Files
ROMFASTSQL/oracle/standby-server-scripts/03b_setup_incremental_tasks.ps1
Marius d5bfc6b5c7 Add Oracle DR standby server scripts and Proxmox troubleshooting docs
- Add comprehensive Oracle backup and DR strategy documentation
- Add RMAN backup scripts (full and incremental)
- Add PowerShell transfer scripts for DR site
- Add bash restore and verification scripts
- Reorganize Oracle documentation structure
- Add Proxmox troubleshooting guide for VM 201 HA errors and NFS storage issues

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-08 13:37:33 +03:00

159 lines
6.0 KiB
PowerShell

# Setup Windows Task Scheduler pentru Incremental Backup și Transfer
# Rulează ca Administrator!
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Error "This script must be run as Administrator!"
exit 1
}
Write-Host "Setting up Oracle INCREMENTAL backup tasks..." -ForegroundColor Cyan
# ==================== TASK 1: Incremental RMAN Backup ====================
$taskName1 = "Oracle_IncrementalBackup"
$rmanScriptPath = "D:\rman_backup\rman_backup_incremental.bat"
# Creează BAT wrapper pentru RMAN incremental
$batContent = @"
@echo off
REM Incremental RMAN Backup - Midday
echo [%DATE% %TIME%] Starting incremental backup...
rman target sys/romfastsoft@roa @'D:\RMAN_BACKUP\rman_backup_incremental.txt'
echo [%DATE% %TIME%] Incremental backup completed
"@
New-Item -ItemType Directory -Force -Path "D:\rman_backup" | Out-Null
$batContent | Out-File -FilePath $rmanScriptPath -Encoding ASCII -Force
# Verificare că scriptul RMAN incremental există
$rmanIncrScript = "D:\rman_backup\rman_backup_incremental.txt"
if (-not (Test-Path $rmanIncrScript)) {
Write-Host "⚠️ RMAN incremental script not found at: $rmanIncrScript" -ForegroundColor Yellow
Write-Host "Please copy 01b_rman_backup_incremental.txt to D:\rman_backup\rman_backup_incremental.txt" -ForegroundColor Yellow
Write-Host "Continuing with task creation..." -ForegroundColor Yellow
}
# Task action pentru incremental backup
$action1 = New-ScheduledTaskAction `
-Execute "cmd.exe" `
-Argument "/c `"$rmanScriptPath`""
# Trigger: zilnic la 14:00 (mijlocul zilei - după pauza de masă)
$trigger1 = New-ScheduledTaskTrigger -Daily -At "14:00"
# Principal: SYSTEM account
$principal = New-ScheduledTaskPrincipal `
-UserId "SYSTEM" `
-LogonType ServiceAccount `
-RunLevel Highest
# Settings
$settings = New-ScheduledTaskSettingsSet `
-AllowStartIfOnBatteries `
-DontStopIfGoingOnBatteries `
-StartWhenAvailable `
-RestartCount 3 `
-RestartInterval (New-TimeSpan -Minutes 5)
# Șterge task vechi dacă există
$existingTask1 = Get-ScheduledTask -TaskName $taskName1 -ErrorAction SilentlyContinue
if ($existingTask1) {
Write-Host "Removing existing task: $taskName1" -ForegroundColor Yellow
Unregister-ScheduledTask -TaskName $taskName1 -Confirm:$false
}
# Creare task incremental backup
try {
Register-ScheduledTask `
-TaskName $taskName1 `
-Action $action1 `
-Trigger $trigger1 `
-Principal $principal `
-Settings $settings `
-Description "Oracle - Incremental RMAN backup daily at 14:00 (midday)" `
-ErrorAction Stop
Write-Host "✅ Task created: $taskName1" -ForegroundColor Green
} catch {
Write-Error "Failed to create task $taskName1 : $_"
exit 1
}
# ==================== TASK 2: Transfer Incremental to DR ====================
$taskName2 = "Oracle_DR_TransferIncremental"
$transferScriptPath = "D:\rman_backup\transfer_incremental_to_dr.ps1"
# Verificare că scriptul de transfer există
if (-not (Test-Path $transferScriptPath)) {
Write-Host "⚠️ Transfer script not found at: $transferScriptPath" -ForegroundColor Yellow
Write-Host "Please copy 02b_transfer_incremental_to_dr.ps1 to D:\rman_backup\" -ForegroundColor Yellow
}
# Task action pentru transfer incremental
$action2 = New-ScheduledTaskAction `
-Execute "PowerShell.exe" `
-Argument "-ExecutionPolicy Bypass -NoProfile -File `"$transferScriptPath`""
# Trigger: zilnic la 14:30 (30 min după incremental backup)
$trigger2 = New-ScheduledTaskTrigger -Daily -At "14:30"
# Șterge task vechi
$existingTask2 = Get-ScheduledTask -TaskName $taskName2 -ErrorAction SilentlyContinue
if ($existingTask2) {
Write-Host "Removing existing task: $taskName2" -ForegroundColor Yellow
Unregister-ScheduledTask -TaskName $taskName2 -Confirm:$false
}
# Creare task transfer incremental
try {
Register-ScheduledTask `
-TaskName $taskName2 `
-Action $action2 `
-Trigger $trigger2 `
-Principal $principal `
-Settings $settings `
-Description "Oracle DR - Transfer incremental backups to DR server daily at 14:30" `
-ErrorAction Stop
Write-Host "✅ Task created: $taskName2" -ForegroundColor Green
} catch {
Write-Error "Failed to create task $taskName2 : $_"
exit 1
}
# ==================== SUMMARY ====================
Write-Host "`n=========================================" -ForegroundColor Green
Write-Host "Incremental Backup Tasks Setup Complete!" -ForegroundColor Green
Write-Host "=========================================" -ForegroundColor Green
Write-Host "`nTasks created:"
Write-Host " 1. $taskName1"
Write-Host " Schedule: Daily at 14:00"
Write-Host " Action: RMAN incremental backup"
Write-Host ""
Write-Host " 2. $taskName2"
Write-Host " Schedule: Daily at 14:30"
Write-Host " Action: Transfer to DR server"
Write-Host "`nDaily timeline:"
Write-Host " 02:00 → Full backup (existent)"
Write-Host " 03:00 → Transfer full to DR (existent)"
Write-Host " 14:00 → Incremental backup (NOU!)"
Write-Host " 14:30 → Transfer incremental to DR (NOU!)"
Write-Host " 21:00 → Copy to E:\ external HDD (existent)"
Write-Host "`n⚠️ IMPORTANT - Files needed:" -ForegroundColor Yellow
Write-Host " 1. Copy 01b_rman_backup_incremental.txt → D:\rman_backup\rman_backup_incremental.txt"
Write-Host " 2. Copy 02b_transfer_incremental_to_dr.ps1 → D:\rman_backup\transfer_incremental_to_dr.ps1"
Write-Host "`nVerify tasks:"
Write-Host " Get-ScheduledTask | Where-Object { `$_.TaskName -like 'Oracle*' }"
Write-Host "`nTest manual:"
Write-Host " Start-ScheduledTask -TaskName '$taskName1'"
Write-Host " Start-ScheduledTask -TaskName '$taskName2'"
Write-Host "`n=========================================" -ForegroundColor Green