Skip to content
Luca Dell'Oca Principal Cloud Architect @Veeam
Virtual To The Core Virtual To The Core

Virtualization blog, the italian way.

  • Media
  • About me
Virtual To The Core
Virtual To The Core

Virtualization blog, the italian way.

Create new backup jobs in Veeam via powershell

Luca Dell'Oca, October 6, 2015December 4, 2016

When you have to deal with a large environment and several jobs in Veeam, automation via powershell is the only possible solution.

The interface is nice…

.. yet is an interface. Which means that for any new job you have to create, you need to go through the job creation wizard, fill in any required field, select the different options, and wait for the job to be reigstered before creating the next one. At least the advanced options for the storage can be stored as default in Veeam Backup & Replication, but this is only a part of the different settings available in a job. And if one of the jobs requires a different set of options, you need again to open the advanced options and change them.

This scenario is not a problem for users with few jobs, or jobs that do not change frequently because the protected environment doesn’t change often. But if you have like in the case I was following 50 different jobs, each mapped to a vSphere datastore, things starts to become a little bit more complicated

Create jobs using Powershell

The two major limits in creating jobs using the interface is the total bore of repeating the same process multiple times, but even more the risk to commit some errors in the wizard, exactly because the bore makes it all appear even more, well, boring…

To solve this issue, and guarantee a consistent configuration across all the 50 jobs I had to create, I developed two powershell scripts. They are both to be executed in the powershell console of the Veeam server.

The first one retrieves all the datastores as Veeam sees them when browsing the connected vCenter:

asnp “VeeamPSSnapIn” -ErrorAction SilentlyContinue
Find-VBRViEntity -DatastoresAndVMs | where {$_.Type -eq “Datastore”} | select {$_.Name} -Unique | Sort-Object Name

The list can then be used to create the different jobs. Because there are several jobs moving a lot of data, you want to optimise the day when the full backup is executed during the week, instead of having all of them running in the same day. This would cause issues in the environment and the schedule will last too long. Then, you also want to send different backup jobs into different repositories to balance the storage consumption. Because of these requirements, the script asks 4 parameters as input: the name of the datastore to be used as a backup entity, the repository where we want to store the backup chain, the day the active full will be used, the time of the day to schedule the backup. The datastore name will also be the job name.

This script is also a good opportunity to learn how the different job options can be configured via Powershell in Veeam.

asnp “VeeamPSSnapIn” -ErrorAction SilentlyContinue

# Ask for parameters and build the job

$datastorename = Read-Host ‘Which datastore you want to use?’
$repositoryname = Read-Host ‘Which repository you want to use?’
$fullday = Read-Host ‘Which day you want to run the active full? Options are Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday’
$time = Read-Host “At what time of the day you want to run the job? Format is hh:mm”

$VBRName = “This server”
$VBR = Get-VBRServer -Name $VBRName
$VC = Get-VBRServer -Type “VC”

$datastore = Find-VBRViDatastore -Server $VC -Name $datastorename
$repository = Get-VBRBackupRepository -Name $repositoryname

# Create the job
Add-VBRViBackupJob -Name $datastorename -Entity $datastore -BackupRepository $repository

# Job is created with default parameters
# After creation, edit job options to have the final result
#
# Set retention points 

$job = Get-VBRJob -Name $datastorename
$options = $job.GetOptions()
$options.BackupStorageOptions.RetainCycles = 7
$job.SetOptions($options)

# for compression levels and block size = http://helpcenter.veeam.com/backup/80/powershell/set-vbrjobadvancedstorageoptions.html

Get-VBRJob -Name $datastorename | Set-VBRJobAdvancedStorageOptions -CompressionLevel 4 -EnableDeduplication $True -StorageBlockSize 6

# Disable default synthetic and set active full on the desired day

Get-VBRJob -Name $datastorename | Set-VBRJobAdvancedBackupOptions -Algorithm Incremental -TransformFullToSyntethic $False -EnableFullBackup $True -FullBackupDays $fullday

# Set the schedule, daily execution with date as input, and enable it

Get-VBRJob -Name $datastorename | Set-VBRJobSchedule -Daily -At $time
Get-VBRJob -Name $datastorename | Enable-VBRJobSchedule

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to email a link to a friend (Opens in new window) Email
  • Click to share on Tumblr (Opens in new window) Tumblr
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to share on WhatsApp (Opens in new window) WhatsApp
  • Click to share on Pocket (Opens in new window) Pocket
Tech backupcreationjoboptionspowershellretentionveeam

Post navigation

Previous post
Next post

Search

Sponsors

Latest Posts

  • Migrate WSL (Windows Subsystem for Linux) to a new computer
  • Pass keystrokes to a pfSense virtual machine to install it automatically
  • Automatically deploy pfSense with Terraform and Ansible
  • My Automated Lab project: #6 Create a S3 Bucket with Terraform
  • My Automated Lab project: #5 Deploy a Linux vSphere VM with Terraform and custom disks
©2025 Virtual To The Core | WordPress Theme by SuperbThemes
We use cookies to ensure that we give you the best experience on our website, and to collect anonymous data regarding navigations stats using 3rd party plugins; they all adhere to the EU Privacy Laws. If you continue to use this site we will assume that you are ok with it.OkNoPrivacy Policy