# Randomize Veeam Backups, a Veeam PowerShell script # 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 XXX 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 = 780 $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 # RandomNextRun: Next Run is calculated from LatestRun (delayed calculation). This will randomly stagger when your backups will next run. $RandomNextRunMinimum = 5 $RandomNextRunMaximum = 500 $RandomLatestRunMinimum = 5 $RandomLatestRunMaximum = 500 # 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 } #By-PREFIX# $jobs = Get-VBRJob -Name "Test-*" | Where-Object { $_.IsBackup -eq $true } #By-LIST# $jobs = Get-VBRJob -Name "Test-1","Test-2" | Where-Object { $_.IsBackup -eq $true } #By-NAME# $jobs = Get-VBRJob -Name "Test-Job" | Where-Object { $_.IsBackup -eq $true } # 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 # 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 # Generate random number for NextRun (Minimum and Maximum variables are defined above) $RandomNextRun = Get-Random -Minimum $RandomNextRunMinimum -Maximum $RandomNextRunMaximum # Create a random NextRun (future) $jobScheduleOptions.NextRun = (Get-Date).AddMinutes($RandomNextRun) # Generate random number for LatestRun (Minimum and Maximum variables are defined above) $RandomLatestRun = Get-Random -Minimum $RandomLatestRunMinimum -Maximum $RandomLatestRunMaximum # Create a random LatestRun (past) $jobScheduleOptions.LatestRun = (Get-Date).AddMinutes(-($RandomLatestRun)) # Enable Periodically Schedule $jobScheduleOptions.OptionsPeriodically.Enabled = $true # Configure Periodic Schedule in Minutes (0 = Hours, 1 = Minutes) $jobScheduleOptions.OptionsPeriodically.Kind = 1 # Disable Daily Schedule $jobScheduleOptions.OptionsDaily.Enabled = $false # Disable Monthly Schedule $jobScheduleOptions.OptionsMonthly.Enabled = $false # Disable Continuous Schedule $jobScheduleOptions.OptionsContinuous.Enabled = $false # 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 ###########################