1. Locate all datastores or certain datastores and uses those for the name of the backup job from a specific host. You only really need one host to query as all hosts in a cluster should see all the same volumes.
2. Creates the backup job with settings specific to a StoreOnce backup appliance. This can be altered to support any device.
3. Creates initial job at hh:mm time and increments jobs in m increments. Again, this can be adjusted.
4. Configures a post job script to run on every execution of the job.
5. Sets the number of restore points to maintain to 28. Again, can be modified.
6. Sets number of days to retain deleted vms in backups (28, but can be modified).
There are a lot of prompts listed, but currently unused. They will be implemented to prompt users for the above information instead of editing the script every time. I did find out a nice side effect to this program. I wanted to be able to run the script periodically to create new backup jobs for newly created datastores. I wanted to be sure it didn't create duplicate jobs. Well, Veeam does not allow a job to be created with the an already existing name, so you could potentially set this up as a pre/post script to create jobs every night for any new datastores created during the day.
I appreciate any feedback or tweaks to the script. I hope someone finds some use for this.
Here it is:
----------------------------------------------------------------------------------------------------
Code: Select all
#Questions:
# Why is a prescript called a prescript and a post script called a commandline?
Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue
write-host "This script created by Kevin Wood at Worldcom Exhange, Inc. on 7-27-2016"
write-host "This script will automatically build backup jobs based on datastores and their names"
write-host "Jobs will start at HH:mm time and increment every X minutes"
write-host "Collecting Host information"
$datastore = Get-VBRServer -Name "sbo3-ta00-vh57.hosting.local" |Find-VBRViDatastore -Name "sbo3-ta00-3p01-clus08-ds*"
write-host "Collecting Data Stores"
$datastorename = Get-VBRServer -Name "sbo3-ta00-vh57.hosting.local" |Find-VBRViDatastore -Name "sbo3-ta00-3p01-clus08-ds*"|select name
write-host "Setting Backup Target"
$repository = Get-VBRBackupRepository -Name "Veeam_BS3_BO3_TA00_SS1_S1"
$RestorePoints = "28" # Restore Points
$RetainDaysadd = "28" # VM deleted retention period in days
$starttime = Get-Date "00:00"
write-host "Setting start time to " $starttime
$timeincrement = 5
write-host "Setting time increments to gap backups to " $timeincrement
for ($i=0; $i -lt $datastore.length; $i++) {
$d = $datastorename[$i].Name
write-host "Creating backup job " $d
Add-VBRViBackupJob -Name $d -Entity $datastore[$i] -BackupRepository $repository
$Jobname = Get-VBRJob -Name $d
$JobOptions = $Jobname | Get-VBRJobOptions
write-host "Setting Restore points to " $RestorePoints
$JobOptions.BackupStorageOptions.RetainCycles = $RestorePoints
$JobOptions.BackupStorageOptions.EnableDeletedVmDataRetention = $true
write-host "Setting Advanced Storage Options for job " $d
Set-VBRJobAdvancedStorageOptions -Job $Jobname -enablededuplication $FALSE -CompressionLevel 5 -StorageBlockSize KbBlockSize4096
write-host "Setting Advanced Options for job " $d
Set-VBRJobAdvancedOptions -Job $Jobname -EnableIntegrityChecks $True -Enabled $True -CommandLine "C:\Program Files\Veeam\Backup and Replication\Scripts\job_date_retention.bat" -Retaindays $Retaindaysadd
write-host "Setting Advanced Vi Options for job " $d
Set-VBRJobAdvancedViOptions -Job $Jobname -EnableChangeTracking $True -UseChangeTracking $True -ExcludeSwapFile $True
write-host "Setting Advanced Backup Options for job " $d
Set-VBRJobAdvancedBackupOptions -Job $Jobname -Algorithm Incremental -TransformFullToSyntethic $True -TransformToSyntethicDays Sunday -EnableFullBackup $True -FullBackupScheduleKind Monthly -DayNumberInMonth Second -FullBackupDays Sunday
$time = Get-Date -f HH:mm $starttime
Get-VBRJob -Name $d | Set-VBRJobSchedule -Daily -At $time -DailyKind Everyday
write-host "Setting backup schedule for job" $d "to" $time
[datetime]$starttime = $starttime.AddMinutes(5)
}