Exert of currently used code for this (This does not behave exactly how I'd like):
Code: Select all
foreach($Session in $MaintainceSessions){
if([Veeam.Backup.Core.CRepositoryMaintenanceSession]::Get($Session.ID).IsWorking){
#[Veeam.Backup.Core.CRepositoryMaintenanceSession]::Get($Session.ID).AbortSession()
[Veeam.Backup.Core.CRepositoryMaintenanceSession]::Get($Session.ID).CompleteWithSuccess()
}
}
Full function:
Code: Select all
function Optimize-ActiveFulls{
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True)]
[Veeam.Backup.PowerShell.Infos.VBRScaleOutBackupRepository] $Repository
)
BEGIN{
function CacheSanityCheck{
$ExtentMaxTaskCounts = Get-ChildItem C:\ProgramData\Veeam\ReportingCache -Filter 'ExtentMaxTaskCounts*' | Sort-Object name -Descending | select -First 1 | Import-Clixml
$MismatchedRepos = @()
foreach($ID in $ExtentMaxTaskCountsMap.keys){
$Repo = [Veeam.Backup.Core.CBackupRepository]::Get($ID)
if($Repo.Options.MaxTaskCount -ne $ExtentMaxTaskCounts[$ID]){
$MismatchedRepos += [PSCustomObject]@{
RepoName = $Repo.name
ID = $Repo.ID
CachedTask = $ExtentMaxTaskCounts[$ID]
CurrentTasks = $Repo.Options.MaxTaskCount
}
Write-Host "$($Repo.Options.MaxTaskCount) of $($ExtentMaxTaskCounts[$ID]) - Task count mismatch: $($Repo.Name)" -ForegroundColor Red
}else{
Write-Host "$($Repo.Options.MaxTaskCount) of $($ExtentMaxTaskCounts[$ID]) - Task count match: $($Repo.Name)" -ForegroundColor Green
}
}
$MismatchedRepos | Out-GridView -OutputMode Multiple -Title "Select Repo Settings to Reset to Cache" | ForEach-Object{
$Repo = [Veeam.Backup.Core.CBackupRepository]::Get($_.Id)
$Repo.Options.MaxTaskCount = $_.CachedTask
$Repo.SaveOptions()
}
}
#Pre-Run sanity checks
CacheSanityCheck
#Save Inital Task Counts
$ExtentMaxTaskCounts = @{}
forEach($Extent in [Veeam.Backup.Core.CExtendableRepository]::Get($Repository.Id).GetExtents()){
$ExtentMaxTaskCounts.Add($Extent.ID,$Extent.Options.MaxTaskCount)
}
$ExtentMaxTaskCounts | Export-Clixml -Path "C:\ProgramData\Veeam\ReportingCache\ExtentMaxTaskCounts_$([DateTime]::Now.ToString('yyyyMMddHHmmss')).xml"
#Enable PerformFullWhenExtentOffline
Set-VBRScaleOutBackupRepository -Repository $Repository -PerformFullWhenExtentOffline:$true -Extent $Repository.Extent
#Enable mainatiance mode
$MaintainceExtents = $Repository | Get-VBRRepositoryExtent | Out-GridView -OutputMode Multiple -Title 'Extents to put into maintenance mode'
$MaintainceSessions = $MaintainceExtents | Enable-VBRRepositoryExtentMaintenanceMode -RunAsync
#Set Task Counts to 1
[Veeam.Backup.Core.CExtendableRepository]::Get($Repository.Id).GetExtents() | ForEach-Object {$_.Options.MaxTaskCount = 1; $_.SaveOptions()}
}
PROCESS{
Write-Host "To Exit Type: Done"
Do{
$input = Read-Host -Prompt "Update Task Limit (Y)"
if($input -match '^Y'){
$SelectedExtents = [Veeam.Backup.Core.CExtendableRepository]::Get($Repository.Id).GetExtents() | Out-GridView -OutputMode Multiple -Title 'Extents to modify'
do{
$Input = $null
try{
$Input = [Int32](Read-Host -Prompt "New Task Limit")
}catch{
Write-Warning 'Please enter an integer'
}
}while(!$Input)
foreach($Extent in $SelectedExtents){
$Extent.Options.MaxTaskCount = $Input
$Extent.SaveOptions()
}
}
}While($Input -notmatch '^Done$')
}
END{
#Disable PerformFullWhenExtentOffline
Set-VBRScaleOutBackupRepository -Repository $Repository -PerformFullWhenExtentOffline:$false -Extent $Repository.Extent
#Reset Task Counts
foreach($Extent in [Veeam.Backup.Core.CExtendableRepository]::Get($Repository.Id).GetExtents()){
$Extent.Options.MaxTaskCount = $ExtentMaxTaskCounts[$Extent.Id]
$Extent.SaveOptions()
}
#Kill still running mainatiance sessions
foreach($Session in $MaintainceSessions){
if([Veeam.Backup.Core.CRepositoryMaintenanceSession]::Get($Session.ID).IsWorking){
#[Veeam.Backup.Core.CRepositoryMaintenanceSession]::Get($Session.ID).AbortSession()
[Veeam.Backup.Core.CRepositoryMaintenanceSession]::Get($Session.ID).CompleteWithSuccess()
}
}
#Remove extents from maintaince mode
$MaintainceExtents | Disable-VBRRepositoryExtentMaintenanceMode -RunAsync > $null
#Pre-Post sanity checks
CacheSanityCheck
}
}