Skip to content

Instantly share code, notes, and snippets.

@vMarkusK
Last active August 11, 2019 20:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vMarkusK/b4aa762f740d5d2f7202cdbd3179a985 to your computer and use it in GitHub Desktop.
Save vMarkusK/b4aa762f740d5d2f7202cdbd3179a985 to your computer and use it in GitHub Desktop.
Veeam vCloud Auto Create Job
Param (
[Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="Veeam BR Credentials")]
[ValidateNotNullorEmpty()]
[PSCredential]$VeeamCred,
[Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="Veeam BR Server")]
[ValidateNotNullorEmpty()]
[String]$VeeamVBRServer,
[Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="Veeam Backup Job Scale-Out Repository Name")]
[ValidateNotNullorEmpty()]
[ValidateSet("SOR_03","SOR_06")]
[String]$VeeamRepoName,
[Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="Veeam Backup Retention in Days")]
[ValidateNotNullorEmpty()]
[Int]$BackupRetention,
[Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="Veeam Backup Retention in Days")]
[ValidateNotNullorEmpty()]
[ValidateSet("21:00:00","21:30:00", "22:00:00", "22:30:00", "23:00:00", "23:30:00")]
[String]$BackupStartTime,
[Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="Veeam Backup Copy Job Scale-Out Repository Name")]
[ValidateNotNullorEmpty()]
[ValidateSet("SOR_03","SOR_06")]
[String]$VeeamCopyRepoName,
[Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage="Body of the API Call")]
[ValidateNotNullorEmpty()]
[String]$VcdOrgName
)
# Credits:
## https://github.com/VeeamHub/powershell/blob/master/vCD-Create-SelfServiceTenantandPolicyJobs/new_vcd_self_service_client_release.ps1
## https://github.com/mycloudrevolution/Advanced-PRTG-Sensors/blob/master/Veeam/PRTG-VeeamBRStats.ps1
## https://github.com/mycloudrevolution/Veeam-PowerShell-Webinar/blob/master/Webinar-Job-Options.ps1
#region: Check Repos
if ($VeeamRepoName -eq $VeeamCopyRepoName) {
Throw "Backup and Backup Copy in the same SOR does not make sense!"
}
#endregion
#region: Check and Load VeeamPS Snaping
if (!(Get-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue)) {
try {
Add-PSSnapin -PassThru VeeamPSSnapIn -ErrorAction Stop
}
catch {
throw "Failed to load VeeamPSSnapIn!"
}
}
#endregion
#region: Connect VBR Server
$OpenConnection = (Get-VBRServerSession).Server
if($OpenConnection -eq $VeeamVBRServer) {
Write-Debug "BRHost is Already Connected..."
} elseif ($null -eq $OpenConnection) {
try {
Connect-VBRServer -Server $VeeamVBRServer -Credential $VeeamCred
}
catch {
Throw "Failed to connect to Veeam BR Host"
}
} else {
Disconnect-VBRServer
try {
Connect-VBRServer -Server $VeeamVBRServer -Credential $VeeamCred
}
catch {
Throw "Failed to connect to Veeam BR Host"
}
}
$NewConnection = (Get-VBRServerSession).Server
if ($null -eq $NewConnection) {
Throw "Failed to connect to Veeam BR Host"
}
Remove-Variable VeeamCred
#endregion
#region: Collect environment
## vCD Server
try {
$VcdServer = Get-VBRServer -Type vcdSystem
}
catch {
Throw "Get vCD Server Failed!"
}
if (!($VcdServer) -or $VcdServer.count -ne 1 ) {
Throw "Get vCD Server Failed!"
}
## vCD Org
try {
$VcdOrg = Find-VBRvCloudEntity -Server $VcdServer -Organization | Where-Object {$_.Name -eq $VcdOrgName}
}
catch {
Throw "Get vCD Org Failed!"
}
if (!($VcdOrg) -or $VcdOrg.count -ne 1 ) {
Throw "Get vCD Org Failed!"
}
## Backup Repository
try {
$BackupRepository = Get-VBRBackupRepository -ScaleOut | Where-Object {$_.Name -eq $VeeamRepoName}
}
catch {
Throw "Get Veeam SO Repo Failed!"
}
if (!($BackupRepository) -or $BackupRepository.count -ne 1 ) {
Throw "Get Veeam SO Repo Failed!"
}
## Backup Copy Repository
try {
$BackupCopyRepository = Get-VBRBackupRepository -ScaleOut | Where-Object {$_.Name -eq $VeeamCopyRepoName}
}
catch {
Throw "Get Veeam SO Repo Failed!"
}
if (!($BackupCopyRepository) -or $BackupCopyRepository.count -ne 1 ) {
Throw "Get Veeam SO Repo Failed!"
}
#endregion
#region: Create Backup Job
$JobName = $VcdOrg.Name + "_AutoCreated Default Backup"
$JobDescription = $VcdOrg.Name + " - AutoCreated Default Backup. "
$CopyJobName = $VcdOrg.Name + "_AutoCreated Default Backup Copy"
$CopyJobDescription = $VcdOrg.Name + " - AutoCreated Default Backup Copy. "
## Create Job
$VbrJob = Add-VBRvCloudJob -Entity $VcdOrg -Name $JobName -BackupRepository $BackupRepository.Name -Description $JobDescription
## Set Job Options
$VbrJob = Get-VBRJob -Name $JobName
$VbrJobOptions = New-VBRJobOptions -ForBackupJob
### BackupStorage Options
$VbrJobOptions.BackupStorageOptions.RetainCycles = $BackupRetention
$VbrJobOptions.BackupStorageOptions.EnableIntegrityChecks = $True
$VbrJobOptions.BackupStorageOptions.EnableFullBackup = $True
### BackupTarget Options
$VbrJobOptions.BackupTargetOptions.Algorithm = "Increment"
$VbrJobOptions.BackupTargetOptions.FullBackupScheduleKind = "Daily"
$VbrJobOptions.BackupTargetOptions.FullBackupDays = "Saturday"
$VbrJobOptions.BackupTargetOptions.TransformFullToSyntethic = $False
$VbrJobOptions.BackupTargetOptions.TransformIncrementsToSyntethic = $False
### SanIntegration Options
$VbrJobOptions.SanIntegrationOptions.UseSanSnapshots = $True
$VbrJobOptions.SanIntegrationOptions.FailoverFromSan = $True
$VbrJobOptions.SanIntegrationOptions.Failover2StorageSnapshotBackup = $True
$Trash = Set-VBRJobOptions -Job $VbrJob -Options $VbrJobOptions
## Set Job Proxies
$TenantProxies = Get-VBRViProxy | Where-Object {$_.Name -ne "<Unused Proxy Name>" -and $_.Name -ne "<Unused Proxy Name>" }
$Trash = Set-VBRJobProxy -Job $VbrJob -Proxy $TenantProxies
## Set Job Schedule
$Trash = Set-VBRJobSchedule -Job $VbrJob -Daily -At $BackupStartTime
$Trash = Enable-VBRJobSchedule -Job $VbrJob
#endregion
#region: Create Backup Copy Job
## Create Copy Job
$VbrCopyJob = Add-VBRvCloudBackupCopyJob -DirectOperation -Name $CopyJobName -Description $CopyJobDescription -BackupJob $VbrJob.Name -Repository $BackupCopyRepository
## Set Copy GFS Retention
$VbrCopyJobGfsOptions = $VbrCopyJob.GetOptions()
$VbrCopyJobGfsOptions.GenerationPolicy.RetentionPolicyType = 'GFS'
$VbrCopyJobGfsOptions.GenerationPolicy.GFSWeeklyBackups = 4
$VbrCopyJobGfsOptions.GenerationPolicy.GFSMonthlyBackups = 3
$VbrCopyJobGfsOptions.GenerationPolicy.GFSQuarterlyBackups = 2
$VbrCopyJobGfsOptions.GenerationPolicy.GFSYearlyBackups = 1
$VbrCopyJobGfsOptions.GenerationPolicy.EnableRechek = $True
$VbrCopyJobGfsOptions.GenerationPolicy.RecheckDays = [System.DayOfWeek] 'Friday', 'Monday'
$VbrCopyJobGfsOptions.GenerationPolicy.RecheckScheduleKind = 'Monthly'
$VbrCopyJobGfsOptions.GenerationPolicy.SyncIntervalStartTime = '13:00:00'
$VbrCopyJobGfsOptions.GenerationPolicy.SimpleRetentionRestorePoints = 7
$VbrCopyJobGfsOptions.GenerationPolicy.WeeklyBackupDayOfWeek = 'Thursday'
$VbrCopyJobGfsOptions.GenerationPolicy.RecoveryPointObjectiveUnit = 'Day'
$VbrCopyJobGfsOptions.GenerationPolicy.RecoveryPointObjectiveValue = 1
$VbrCopyJobGfsOptions.GenerationPolicy.RecheckBackupMonthlyScheduleOptions.DayNumberInMonth = 'Third'
$VbrCopyJobGfsOptions.GenerationPolicy.RecheckBackupMonthlyScheduleOptions.DayOfWeek = 'Wednesday'
$VbrCopyJobGfsOptions.GenerationPolicy.RecheckBackupMonthlyScheduleOptions.Months = [Veeam.Backup.Common.Emonth] 'January', 'July'
$Trash = Set-VBRJobOptions -Job $VbrCopyJob -Options $VbrCopyJobGfsOptions
## Enable Copy Job
$Trash = $VbrCopyJob | Enable-VBRJob
#endregion
#region: Import Job to Self-Service
$Trash = Set-VBRvCloudOrganizationJobMapping -Action Map -Job $VbrJob
#endregion
Get-VBRJob -Name $JobName | Select-Object Name, JobType, SourceType | Format-Table -AutoSize
Get-VBRJob -Name $CopyJobName | Select-Object Name, JobType, SourceType | Format-Table -AutoSize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment