PowerShell script exchange
Post Reply
Ahmed Shakran
Novice
Posts: 9
Liked: 3 times
Joined: Feb 23, 2023 2:01 pm
Full Name: Ahmed Shakran
Contact:

Create VM Backup jobs by script

Post by Ahmed Shakran » 1 person likes this post

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.

Code: Select all

{{

#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

}}
Best Regards,
Ahmed Shakran
Mildur
Product Manager
Posts: 8735
Liked: 2294 times
Joined: May 13, 2017 4:51 pm
Full Name: Fabian K.
Location: Switzerland
Contact:

Re: Create VM Backup jobs by script

Post by Mildur » 1 person likes this post

Hello Ahmed

Thank you for sharing the script with us.
If you like, you may also post it to our Script library in the community hub:
https://community.veeam.com/script-library-67

Best,
Fabian
Product Management Analyst @ Veeam Software
Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests