Yesterday, during the VEEAM User Group Germany someone was missing a Maintenance Mode for VEEAM. The main problem was to keep which job was enabled and which was disabled. I wrote a script some times ago which stopped all jobs and disable them but before the state is dumped into a JSON File. On leaving maintenence the JSON-File will be read and required jobs are set to enabled again and failed jobs are triggered to restart.
The scripts (and more) can be found on our github repository: https://github.com/claranet/VeeamHub/
Here are these scripts:
Enter-Maintenance.ps1
param(
switch]$DryRun=$False
)
Import-Module Veeam.Backup.PowerShell
Function log($message) {
$timestamp = Get-Date -Format "yyyy-MM-ss hh:mm:ss"
Write-Host "$($timestamp) - $($message)"
}
if($DryRun) { log "DRY RUN - NOTHING WILL CHANGE" }
$_FILE = "$PSScriptRoot/job_states.json"
if( (System.IO.File]::Exists($_FILE) ) {
log "State File already exists - remove it first!!"
pause
Exit 1
}
# Create new, empty state file
New-Item -Path $_FILE -Force | Out-Null
log "Load Jobs"
$JOBS = Get-VBRJob
# Save list of current jobs state (enabled/disabled)
log "Dump Job states to file"
$STATES = ( $JOBS | SELECT Id, Name, @{N="IsScheduleEnabled";E={$_.info.IsScheduleEnabled}} )
$STATES | ConvertTo-Json | Out-File -FilePath $_FILE
# Stop All running jobs
log "Stop all Jobs"
if(-not $DryRun) { $JOBS | Stop-VBRJob -RunAsync }
# Disable all Jobs
log "Disable all jobs"
if(-not $DryRun) { $JOBS | Disable-VBRJob | Out-Null }
log "Finish"
pause
Leave-Maintenance.ps1
param(
switch]$DryRun=$False
)
Import-Module Veeam.Backup.PowerShell
Function log($message) {
$timestamp = Get-Date -Format "yyyy-MM-ss hh:mm:ss"
Write-Host "$($timestamp) - $($message)"
}
if($DryRun) { log "DRY RUN - NOTHING WILL CHANGE" }
$_FILE = "$PSScriptRoot/job_states.json"
if( -not tSystem.IO.File]::Exists($_FILE) ) {
log "Missing state file... Cancle"
pause
Exit 1
}
log "Load list of Last Job States"
$STATES = Get-Content $_FILE | ConvertFrom-Json
log "Enable all needed Jobs"
$JOBS = Get-VBRJob -Name ($STATES|?{-not $_.Proxy -and $_.IsScheduleEnabled}).Name
if(-not $DryRun) { $JOBS | Enable-VBRJob | Out-Null }
log "Retry Failed Backup jobs"
if(-not $DryRun) { $JOBS | ?{ $_.GetLastResult() -eq "Failed" } | Start-VBRJob -RunAsync -RetryBackup }
Remove-Item -Path $_FILE
log "Finish"
pause