Credit to v.Eremin for helping me with the scheduling piece of this.
My script creates backup jobs based on folders in VCenter and prefixes the jobs with HSB and PARKWAY repository names for better organizing in the job window, modify for your needs. It copies most of the settings from my existing job, HSB Applications, just change to whatever you have.
* The $Array part requires having the powercli module for powershell installed, which I did for my Veeam backup manager as it just makes it all simpler for me. I can then get all the folders easily and create the jobs on them.
* Change the $hour and $minute variables to be what time you would want the first job to start.
* The IF statements increment the job start times by 5 minutes.
Code: Select all
# Set the repository, date and minutes
$Repository1 = Get-VBRBackupRepository -name HSB2
$Repository2 = Get-VBRBackupRepository -name PARKWAY1
$Date = Get-Date -format "MMM d yyyy"
$hour = 18
$minute = 05
# Copy the job options from HSB Applications, it's easier to copy than to create from scratch
$Job = Get-VBRJob -name "HSB Applications"
$Options = $Job.GetOptions()
# Set the job VSS options
$vssoptions=New-VBRJobVssOptions -forjob
$vssoptions.Enabled="True"
$vssoptions.GuestFSIndexingType="None"
$vssoptions.TransactionLogsTruncation="Always"
# Create the Array for all the jobs
$Array = Get-Folder | where {$_.type -eq "VM" -and $_.name -notlike "*disc*" -and $_.name -notlike "vm"} | foreach{$_.name} | sort
# Start the loop to create backup jobs
foreach ($_ in $Array)
{
# Create a backup job
$Description = "$_ backup job created by Jon on $Date"
Find-VBRViFolder -server vcenterslm -Name $_ | Add-VBRViBackupJob -Name "HSB $_" -BackupRepository $Repository1 -Description $Description
# Apply the job options
$NewJob = Get-VBRJob -name "HSB $_"
$NewJob.SetOptions($Options)
# Apply the VSS Settings
$NewJob | Set-VBRJobVssOptions -Options $vssoptions
$NewJob | Set-VBRJobVssOptions -Credentials "Domain\vbackup"
# Set the job schedule and increment by 5 minutes
$ScheduleOptions = New-VBRJobScheduleOptions
$ScheduleOptions.OptionsContinuous.Enabled = $False
$ScheduleOptions.OptionsMonthly.Enabled = $False
$ScheduleOptions.OptionsScheduleAfterJob.IsEnabled = $False
$ScheduleOptions.OptionsPeriodically.Enabled = $False
IF ($minute -gt 55)
{
$hour += 1
$minute = 00
}
IF ($hour -gt 23)
{
$hour = 00
}
ELSE
{
$Date = Get-Date -Hour $hour -Minute $minute
$minute += 5
}
$ScheduleOptions.StartDateTime = $Date
$ScheduleOptions.OptionsDaily.Enabled = $True
$ScheduleOptions.OptionsDaily.Kind = "Everyday"
$ScheduleOptions.OptionsDaily.Time = $Date
$Options = $Job.GetOptions()
$Options.JobOptions.RunManually = $False
$Job.SetOptions($Options)
# Apply the schedule
Set-VBRJobScheduleOptions -Job $NewJob -Options $ScheduleOptions
# Disable the job because we don't want things taking off on their own yet
Disable-VBRJob -Job "HSB $_"
}
Add-VBRViBackupCopyJob -DirectOperation -Name "PARKWAY Development" -Backupjob "HSB Dev SharePoint","HSB Dev SQL","HSB Dev Web","HSB Testing" -Repository $Repository2
Add-VBRViBackupCopyJob -DirectOperation -Name "PARKWAY File and Print" -Backupjob "HSB File Servers","HSB Printing" -Repository $Repository2
Add-VBRViBackupCopyJob -DirectOperation -Name "PARKWAY Telecom" -Backupjob "HSB Telecom","HSB Voice" -Repository $Repository2
Add-VBRViBackupCopyJob -DirectOperation -Name "PARKWAY Domain" -Backupjob "HSB Domain Services" -Repository $Repository2
Add-VBRViBackupCopyJob -DirectOperation -Name "PARKWAY Monitor" -Backupjob "HSB Monitoring" -Repository $Repository2
Add-VBRViBackupCopyJob -DirectOperation -Name "PARKWAY Exchange" -Backupjob "HSB Exchange" -Repository $Repository2
Add-VBRViBackupCopyJob -DirectOperation -Name "PARKWAY SharePoint" -Backupjob "HSB SharePoint" -Repository $Repository2
Add-VBRViBackupCopyJob -DirectOperation -Name "PARKWAY Oracle" -Backupjob "HSB Oracle" -Repository $Repository2
Add-VBRViBackupCopyJob -DirectOperation -Name "PARKWAY SQL" -Backupjob "HSB SQL" -Repository $Repository2
Add-VBRViBackupCopyJob -DirectOperation -Name "PARKWAY Templates" -Backupjob "HSB Templates" -Repository $Repository2
Add-VBRViBackupCopyJob -DirectOperation -Name "PARKWAY Veeam" -Backupjob "HSB Veeam" -Repository $Repository2
Add-VBRViBackupCopyJob -DirectOperation -Name "PARKWAY Web" -Backupjob "HSB Web" -Repository $Repository2