Automatically add corresponding Veeam backup copy and replication jobs with Powershell
I had written just a few days ago about a PowerShell script to compare Veeam copy or replication jobs to the regular backup jobs you have setup and see which ones are missing. ย This is useful if you have single backup jobs created and want to create corresponding backup copy and replication jobs on your Veeam server. ย I wanted to take that a step further and actually create the backup copy and replication jobs that are missing from the configuration compared to backup jobs configured. ย Let’s take a look at how to Automatically add corresponding Veeam backup copy and replication jobs with PowerShell.
Automatically add corresponding Veeam backup copy and replication jobs with Powershell
Let’s look at theย copyย script that compares the names of VMs in backup jobs and copy jobs and then will use that compare to create the copy jobs for VMs who do now have corresponding copy jobs created. ย I explained the top part of the logic in the previous post, but again it assumes the names are the same besides <backupjobname> compared to <backupjobname_copy> and same for the replication jobs. ย It strips the appended copy or replication designation off, compares the list and comes up with the difference between the two. ย Then, we loop through and create the corresponding copy and replication jobs that we need.
#Set Variables - Filter out Job names you don't want, create matches, gather information, etc $backupjobs = get-vbrjob | where-object {$_.Name -notmatch "_copy|_repl"} | select -expandproperty Name $copy = get-vbrjob | where-object {$_.Name -like "*_copy*"} | select -expandproperty Name $copystrip= $copy -replace "_.*" $differencecopy = $backupjobs | where {$copystrip -notcontains $_} | out-file c:copyvms.txt $copyvms= get-content 'c:copyvms.txt' $Key = get-vbrencryptionkey #Start the loop for Creating Copy Jobs, create copy job, enable copy job $results = foreach ($copyvm in $copyvms){ Write-Host "Adding Copy job for $copyvm" Add-VBRViBackupCopyJob -DirectOperation -Name $copyvm"_copy" -Backup $copyvm -Repository 'MyRepo' Set-VBRJobAdvancedStorageOptions -Job $copyvm"_copy" -EnableEncryption $true -EncryptionKey $Key Enable-VBRJob -Job $copyvm"_copy" } $results | out-file c:copyjob.log -Append
Now, very similar script, but different with the requirements for setting up replication job in Veeam.
#Get Our Variables $backupjobs = get-vbrjob | where-object {$_.Name -notmatch "_copy|_repl"} | select -expandproperty Name $repl = get-vbrjob | where-object {$_.Name -like "*_repl*"} | select -expandproperty Name $replstrip = $repl -replace "_.*" $differencerepl = $backupjobs | where {$replstrip -notcontains $_} | out-file c:replvms.txt $replvms = get-content 'c:replvms.txt' $viserver =Get-VBRServer -Type VC -Name myvcenter.somewhere.com $cluster = $viserver | find-vbrvientity -Name "MyCluster" $folder = Find-VBRViFolder -Server $viserver -Name "My Folder" $sourcerepo = get-vbrbackuprepository -Name My_repo #Start the loop for Creating Repl Jobs, create replication jobs, enable the job $results = foreach ($replvm in $replvms){ Write-Host "Adding Repl job for $replvm" Find-VBRViEntity -Name $replvm | Add-VBRViReplicaJob -SourceRepository $sourcerepo -Server $cluster -Name $replvm"_repl" -Folder $folder -suffix "_replica" Get-VBRJob -Name $replvm"_repl" | Set-VBRJobSchedule -After -AfterJob $replvm | Enable-VBRJobSchedule } $results | out-file c:copyrepl.log -Append
Thoughts
Once again, PowerShell is a great tool here to quickly work with Veeam jobs. ย The PowerShell integration into Veeam makes it extremely powerful in automating, creating, and checking backup jobs. ย This makes it super easy to automatically add corresponding Veeam backup copy and replication jobs with Powershell. ย Hopefully, someone will find the above script useful if they are trying to accomplish something similar.