Skip to main content

Create VM Backup jobs by script


Creating many backup jobs for new environment or new project which has many VMs, it’s boring in addition you may make a mistake because of repeating.
To avoid that you can use scripts to create them simultaneously and only change the value for some variables.
Below script is for creating VMware VM backup job with almost all required options (VM selection, repo, proxy, retention , GFS, schedule , retries ….etc) moreover the recommended Advanced settings for Dell Data Domain repository.
You can also use part of script to edit or modify existing backup jobs simultaneously.

{{
#Specify the name you want to assign to the backup job

$JobName = "backup job name"

 

#Specify the array of VMware VMs you want to add to the job.

#If you want to search by part of VM name use *

$VMsNames = Find-VBRViEntity -Name "VM1", "VM2", "VM3"

 

#Specify the backup repository where the created backup will be stored. Default: default backup repository

#If you want to search by part of repo name use *

$BackupRepo = Get-VBRBackupRepository -Name "name of repo"

 

#specify the VMware backup proxy for this job

$ProxyName = "name of the proxy"

 

# Which day you want to run the synthetic full? Options are Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday. type the day between ' '

$syntheticday = 'Day'

 

# specify the retention for daily jobs and weekly

$DailyRetention = "number of days"

$WeeklyRetention = "number of weeks"

 

#specify the time of the day you want to run the job? Format is hh:mm. type the time between ' '

$StartTime = 'hh:mm'

 

#Enter the number of attempts to run the job after failing and define time intervals between them in minutes. type them between ' '

$RetriesNumber = 'number'

$WaitingTime = 'minutes'

 

Add-VBRViBackupJob -Name $JobName -Entity $VMsNames -BackupRepository $BackupRepo

# Job is created with default parameters

 

$BackupJob = Get-VBRJob -Name $JobName

 

# assign VMware proxy to the Backup Job

$proxy = Get-VBRViProxy -Name $ProxyName

$BackupJob | Set-VBRJobProxy -Proxy $proxy

 

# Set retention for backup

$retention = Get-VBRJobOptions -Job $BackupJob

$retention.BackupStorageOptions.RetentionType = 'Days'

$retention.BackupStorageOptions.RetainDaysToKeep = $DailyRetention

Set-VBRJobOptions -Job $BackupJob -Options $retention

 

$retention.GfsPolicy.IsEnabled = $true

$retention.GfsPolicy.Weekly.IsEnabled = $true

$retention.GfsPolicy.Weekly.KeepBackupsForNumberOfWeeks = $WeeklyRetention

$retention.GfsPolicy.Weekly.DesiredTime = $syntheticday

Set-VBRJobOptions -Job $BackupJob -Options $retention

 

# set full synthetic backup

$BackupJob | Set-VBRJobAdvancedBackupOptions -Algorithm Incremental -TransformFullToSyntethic $True -EnableFullBackup $False -FullBackupDays $syntheticday

 

# Advanced options (for Dell Data Domain)

$BackupJob | Set-VBRJobAdvancedStorageOptions -CompressionLevel 0 -EnableDeduplication $False -StorageBlockSize 5

 

#enable daily schedule and set the start time

$BackupJob | Enable-VBRJobSchedule

$BackupJob | Set-VBRJobSchedule -Daily -At $StartTime

 

# set number of reties and waiting time

$ScheduleOptions = $BackupJob | Get-VBRJobScheduleOptions

$ScheduleOptions.Retrytimes = $RetriesNumber

$ScheduleOptions.Retrytimeout = $WaitingTime

Set-VBRJobScheduleOptions -Job $BackupJob -Options $ScheduleOptions

 

}}

10 comments

Chris.Childerhose
Forum|alt.badge.img+21

Great script thanks for sharing it. 👍


Moustafa_Hindawi
Forum|alt.badge.img+6

Amazing, thank you @Ahmed Shakran for sharing!

 

Could you please share how to run the script??


victorwu
Forum|alt.badge.img+7
  • Veeam Vanguard
  • 375 comments
  • August 9, 2023

Thank you, I will test it in my lab!


dips
Forum|alt.badge.img+7
  • Veeam Legend
  • 808 comments
  • August 11, 2023

Great script!

When running it, do any modules need to be imported into?


Scott
Forum|alt.badge.img+8
  • Veeam Legend
  • 993 comments
  • August 12, 2023

Great script. Thanks for sharing with us


  • Author
  • Not a newbie anymore
  • 3 comments
  • August 13, 2023
Moustafa_Hindawi wrote:

Amazing, thank you @Ahmed Shakran for sharing!

 

Could you please share how to run the script??

Using Windows PowerShell in backup server


  • Author
  • Not a newbie anymore
  • 3 comments
  • August 13, 2023
dips wrote:

Great script!

When running it, do any modules need to be imported into?

No you can run it directly after defining the value of variables.


Amr Sadek
Forum|alt.badge.img
  • New Here
  • 1 comment
  • August 13, 2023

Amazing as usual @Ahmed Shakran. Thank you for your contribution, and looking forward to more and more success and useful posts for everyone's benefit. 


coolsport00
Forum|alt.badge.img+20
  • Veeam Legend
  • 4131 comments
  • August 17, 2023

Just catching this….very well done @Ahmed Shakran 


Moustafa_Hindawi
Forum|alt.badge.img+6
Ahmed Shakran wrote:
Moustafa_Hindawi wrote:

Amazing, thank you @Ahmed Shakran for sharing!

 

Could you please share how to run the script??

Using Windows PowerShell in backup server

Thanks Ahmed, I make what is the command to run it, what is it the executables 


Comment