Function for setting backup job options

PowerShell script exchange

Function for setting backup job options

Veeam Logoby pizzim13 » Fri Sep 07, 2012 9:55 pm

This function to quickly set a lot of the parameters needed for a new backup job. This function will pick a random time to run the job and a random day of the week for the synthetic full. Thanks to Andy and Seth for some of the examples

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
   }


The following will create a job named Job1, pick a random repo, add vms from the $VMNames array, then set the options for that job.
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
pizzim13
Enthusiast
 
Posts: 86
Liked: 6 times
Joined: Thu Apr 21, 2011 7:37 pm

Re: Function for setting backup job options

Veeam Logoby pizzim13 » Thu Nov 01, 2012 1:54 pm

Be aware, with the last few patches setting the password has been problematic.
pizzim13
Enthusiast
 
Posts: 86
Liked: 6 times
Joined: Thu Apr 21, 2011 7:37 pm

Re: Function for setting backup job options

Veeam Logoby Phill Rogers » Thu Nov 01, 2012 4:34 pm

Thanks for the code. It worked but I couldn't see where mine was different. So I gradually cut yours down to the absolute minimum to still work then compared line by line. I was missing this ..
$vbrjoboptions.JobOptions.RunManually = $false
.. but had it in an earlier version. Must have lost it somewhere in the editing and not noticed!

Phew!
Thanks.
Phill Rogers
Novice
 
Posts: 3
Liked: never
Joined: Thu Nov 01, 2012 12:07 pm
Full Name: Phill Rogers


Return to PowerShell



Who is online

Users browsing this forum: Yahoo [Bot] and 7 guests