# Randomize Veeam Backups, a Veeam PowerShell script (Version 2) # This script will add randomness to Veeam backup jobs by configuring them to use different periodic backup intervals # Run this on a Veeam Backup and Replication version 8 update 1 server # You could even copy and paste it into Veeam Backup and Replication > Menu > PowerShell # Written by Jason Pearce of www.jasonpearce.com in March 2015 # Use at your own risk, freely share, and comment on improvements # BEGIN Random variables ##################### # RandomFullPeriod: Variable for Schedule > Run the job automatically > Periodically every XX minutes. Must be a value between 0 and 999. # Key: 1-8 hours 1h=60min, 2h=120min, 3h=180min, 4h=240min, 5h=300min, 6h=360min, 7h=420min, 8h=480min # Key: 9-16 hours 9h=540min, 10h=600min, 11h=660min, 12h=720min, 13h=780min, 14h=840min, 15h=900min, 16h=960min $RandomFullPeriodMinimum = 540 $RandomFullPeriodMaximum = 960 # RandomHourlyOffset: Variable for Schedule > Run the job automatically > Periodically every > Schedule > Start time within an hour. Must be a value between 0 and 59. $RandomHourlyOffsetMinimum = 0 $RandomHourlyOffsetMaximum = 59 # RandomRetryTimeout: Variable for Schedule > Automatic Retry > Wait before each retry attempt for. Must be a value between 0 and 59. $RandomRetryTimeoutMinimum = 10 $RandomRetryTimeoutMaximum = 50 # END Random variables ####################### # BEGIN Other variables ###################### # BackupRetention: Variables for RetainDays (amount of restore points) and RetainCycles (amount of days for Deleted VMs retention period). $RetainDays = 14 $RetainCycles = 14 # Get All, Some, or One backup jobs. # You MUST uncomment and modify one of these lines to target one or more backup jobs. # Only one line should begin with "$jobs =". These are just four helpful examples. #By-All# $jobs = Get-VBRJob | Where-Object { $_.IsBackup -eq $true -and $_.IsScheduleEnabled -eq $true } | Sort Name #By-PREFIX# $jobs = Get-VBRJob -Name "Test-*" | Where-Object { $_.IsBackup -eq $true -and $_.IsScheduleEnabled -eq $true } | Sort Name #By-LIST# $jobs = Get-VBRJob -Name "Test-1","Test-2" | Where-Object { $_.IsBackup -eq $true -and $_.IsScheduleEnabled -eq $true } | Sort Name #By-NAME# $jobs = Get-VBRJob -Name "Test-Job" | Where-Object { $_.IsBackup -eq $true -and $_.IsScheduleEnabled -eq $true } | Sort Name # END Other variables ######################## # BEGIN foreach loop ######################### # Make the following changes to all backup jobs foreach ($job in $jobs) { # BEGIN Job Options ###################### # Read current job settings $jobOptions = Get-VBRJobOptions -Job $job # Set more Job Advanced Storage Options $jobOptions.BackupStorageOptions.RetainCycles = $RetainCycles $jobOptions.BackupStorageOptions.RetainDays = $RetainDays # Apply these additional Backup Mode settings $jobOptions = Set-VBRJobOptions -Job $job -Options $jobOptions # END Job Options ######################## # BEGIN Job Schedule Options ############# # Create a new job schedule $jobScheduleOptions = New-VBRJobScheduleOptions # Enable Periodically Schedule $jobScheduleOptions.OptionsPeriodically.Enabled = $true # Configure Periodic Schedule in Minutes (0 = Hours, 1 = Minutes) $jobScheduleOptions.OptionsPeriodically.Kind = 1 # Disable Other Schedules $jobScheduleOptions.OptionsDaily.Enabled = $false $jobScheduleOptions.OptionsMonthly.Enabled = $false $jobScheduleOptions.OptionsContinuous.Enabled = $false # Generate random number for FullPeriod (Minimum and Maximum variables are defined above) $RandomFullPeriod = Get-Random -Minimum $RandomFullPeriodMinimum -Maximum $RandomFullPeriodMaximum # Create a random FullPeriod offset $jobScheduleOptions.OptionsPeriodically.FullPeriod = $RandomFullPeriod # Generate random number for HourlyOffset (Minimum and Maximum variables are defined above) $RandomHourlyOffset = Get-Random -Minimum $RandomHourlyOffsetMinimum -Maximum $RandomHourlyOffsetMaximum # Create a random HourlyOffset $jobScheduleOptions.OptionsPeriodically.HourlyOffset = $RandomHourlyOffset # Generate random number for RetryTimeout (Minimum and Maximum variables are defined above) $RandomRetryTimeout = Get-Random -Minimum $RandomRetryTimeoutMinimum -Maximum $RandomRetryTimeoutMaximum # Create a random RetryTimeout $jobScheduleOptions.RetryTimeout = $RandomRetryTimeout # Do some math to randomly stagger LatestRun (past) and NextRun (future), while correctly calculating the FullPeriod difference $RandomlyStagger = Get-Random -Minimum 1 -Maximum 9 $jobScheduleOptions.LatestRun = (Get-Date).AddMinutes(-([math]::Round($RandomFullPeriod * $RandomlyStagger * .1))) $jobScheduleOptions.NextRun = (Get-Date).AddMinutes([math]::Round($RandomFullPeriod * (10 - $RandomlyStagger) * .1)) # Apply the new job schedule Set-VBRJobScheduleOptions -Job $job -Options $jobScheduleOptions # END Job Schedule Options ############### # Report which jobs received these changes Write-Host "Changed settings for" $job.Name } # END foreach loop ########################### # END Randomize Veeam Backups script ######### # BEGIN REPORT ############################### # Optionally Report New Job Schedule Options # # Safe to delete this report ################# # Get all enabled backup jobs. $jobs = Get-VBRJob -Name "*" | Where-Object { $_.IsBackup -eq $true -and $_.IsScheduleEnabled -eq $true } | Sort Name # BEGIN foreach loop ######################### foreach ($job in $jobs) { # Report which jobs have what schedules Write-Host "------------------------------------" Write-Host "Job Schedule settings for" $job.Name # Get job schedule $ReportJobScheduleOptions = Get-VBRJobScheduleOptions -Job $job # Report on a few values Write-Host "FullPer: " $ReportJobScheduleOptions.OptionsPeriodically.FullPeriod Write-Host "HourOff: " $ReportJobScheduleOptions.OptionsPeriodically.HourlyOffset Write-Host "LateRun: " $ReportJobScheduleOptions.LatestRun Write-Host "NextRun: " $ReportJobScheduleOptions.NextRun Write-Host "" } # END foreach loop ########################### # Write current date and time Get-Date # END REPORT #################################