Code: Select all
function Set-VeeamBackupOptions
{
param (
[Parameter(
Position=0,
Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$false)
]
[Veeam.Backup.Core.CBackupJob]$Job
)
#Set Job Options
$JobOptions = $Job | Get-VBRJobOptions
$JobOptions.BackupStorageOptions.RetainCycles = 99
$JobOptions.JobOptions.SourceProxyAutoDetect = $true
$JobOptions.JobOptions.RunManually = $false
$JobOptions.BackupStorageOptions.RetainDays = 99
$JobOptions.BackupStorageOptions.EnableDeduplication = $true
$JobOptions.BackupStorageOptions.StgBlockSize = "KbBlockSize512"
$JobOptions.BackupTargetOptions.Algorithm = "Increment"
$JobOptions.BackupTargetOptions.TransformToSyntethicDays = ((Get-Date).adddays((Get-Random -Minimum 0 -Maximum 6))).dayofweek
$JobOptions.BackupTargetOptions.TransformIncrementsToSyntethic = $true
$Job | Set-VBRJobOptions -Options $JobOptions
#Set schedule options
#Create random backup time between 6PM and 4AM
$Hours = (18,19,20,21,22,23,'00','01','02','03','04') | Get-Random | Out-String
$Minutes = "{0:D2}" -f (Get-Random -Minimum 0 -Maximum 59) | Out-String
$Time = ($Hours+':'+$Minutes+':00').replace("`n","")
$JobScheduleOptions = $Job | Get-VBRJobScheduleOptions
$JobScheduleOptions.OptionsDaily.Enabled = $true
$JobScheduleOptions.OptionsDaily.Kind = "Everyday"
$JobScheduleOptions.OptionsDaily.Time = $Time
$JobScheduleOptions.NextRun = $Time
$JobScheduleOptions.StartDateTime = $Time
$Job | Set-VBRJobScheduleOptions -Options $JobScheduleOptions
$Job.EnableScheduler()
#Set VSS Options
$JobVSSOptions = $Job | Get-VBRJobVSSOptions
$VSSUSername = 'DOMAIN\USERNAME'
$VSSPassword = 'PASSWORD'
$VSSCredentials = New-Object -TypeName Veeam.Backup.Common.CCredentials -ArgumentList $VSSUSername,$VSSPassword,0,0
$JobVSSOptions.Credentials = $VSSCredentials
$JobVSSOptions.Enabled = $true
#Change default behavior per job object
foreach ($JobObject in ($Job | Get-VBRJobObject))
{
$ObjectVSSOptions = Get-VBRJobObjectVssOptions -ObjectInJob $JobObject
$ObjectVSSOptions.IgnoreErrors = $true
Set-VBRJobObjectVssOptions -Object $JobObject -Options $ObjectVSSOptions
}
$Job | Set-VBRJobVssOptions -Options $JobVSSOptions
}
Code: Select all
$VMNames = @("VM1","VM2","VM3","VM4","VM5")
Add-VBRViBackupJob -Name "Job1" -BackupRepository (Get-VBRBackupRepository | get-random) -Entity (Find-VBRViEntity -Name $VMNames) | Set-VeeamBackupOptions