Skip to main content

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

 

}}

Great script thanks for sharing it. 👍


Amazing, thank you @Ahmed Shakran for sharing!

 

Could you please share how to run the script??


Thank you, I will test it in my lab!


Great script!

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


Great script. Thanks for sharing with us


Amazing, thank you @Ahmed Shakran for sharing!

 

Could you please share how to run the script??

Using Windows PowerShell in backup server


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.


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. 


Just catching this….very well done @Ahmed Shakran 


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