PowerShell script exchange
Post Reply
npaixao
Lurker
Posts: 1
Liked: 1 time
Joined: May 06, 2015 12:47 pm
Full Name: Nuno Paixao
Location: Saint John, NB, Canada
Contact:

Backup Performance - VM Source LUN vs Backup Target

Post by npaixao » 1 person likes this post

We were seeing uneven performance in some of our backups. We needed a tool that
allowed us to correlate the Source SAN/LUN location for each of our virtual machines
to the Target NAS/LUN location that the backup file was getting written to.
We could not find such a tool, and so I was tasked with writing a script to collect that data.

This powershell script creates a CSV file with a record for each VM/VMDK combination
with their source and target locations and associated performance metrics.
A scheduled task was created to record historical performance.


Code: Select all

########################################################
## Cirrus9BackupReport
## ------------
## Author: Nuno Paixao, Cirrus9
## Email: nuno.paixao at cirrus9.net
## Web: http://www.cirrus9.net/
########################################################

########################################################
## Create a CSV report from last night's backups showing
## each Virtual Machine, the source of the data,
## the target for the backup, and performance metrics.
########################################################

########################################################
## Initialize the Veeam Snap-In
########################################################
asnp "VeeamPSSnapIn" -ErrorAction SilentlyContinue

########################################################
## Initialize Array for CSV Output
########################################################
$BiggerList = @()

########################################################
## Get a list of Veeam Backup Jobs & loop through them
########################################################
$Jobs = Get-VBRJob | Sort -Property Name 
foreach ($EachJob in $Jobs) {
    if ( $EachJob -ne $null ) {

        ########################################################
        ## Find the last session for that backup job
        ########################################################
        $LastSession = $EachJob.FindLastSession()
        if ( $LastSession -ne $null ) {

            ##################################################################
            ## Get a list of Virtual Machines in each job & loop through them
            ##################################################################
            $TaskSessions = $LastSession | Get-VBRTaskSession 
            foreach ($EachVM in $TaskSessions) {

                ##################################################################
                ## Re-initialize array that will hold data for each VM/VMDK combination
                ##################################################################
                $BigList = @()
            
                ##################################################################
                ## Get a list of Log Entries & Loop through them
                ##################################################################
                if ( $EachVM -ne $null ) {
                    $LogRecords = $EachVM.Logger.GetLog().UpdatedRecords | Sort -Property updatetime
                    foreach ($EachLog in $LogRecords) {
                        if ( $EachLog -ne $null ) {
                        
                            ##################################################################
                            ## What LUN/SAN is the Virtual machine located in
                            ## ... Assumes ALL VMDK's for each VM is on the same SAN
                            ##################################################################
                            if ( $EachLog.title -like "Saving*" ) {
                                $StringParts = $EachLog.title.Split(' ')
                                $StringResult = $StringParts[1].substring(1,$StringParts[1].length-2)
                                $SourceSAN = $StringResult
                            }
                            
                            ##################################################################
                            ## Which Veeam Backup Procy was used to perform the backup
                            ##################################################################
                            if ( $EachLog.title -like "Using backup proxy*" ) {
                                $StringParts = $EachLog.title.Split(' ')
                                $StringPartsCount = $StringParts.Length - 1
                                $StringResult = $StringParts[$StringPartsCount].substring(1,$StringParts[$StringPartsCount].length-2).ToUpper()
                                $BackupType = $StringResult
                                $ProxyUsed = $StringParts[3]
                            }
                            
                            ##################################################################
                            ## Find all the VMDK's and loop through them.
                            ##################################################################
                            if ( $EachLog.title -like "Hard disk*" ) {
                                $StringParts = $EachLog.title.Split(' ')
                                $DiskNumber = $StringParts[2]

                                ##################################################################
                                ## What is the size of the Disk? Convert to MB if required.
                                ##################################################################
                                $DiskSizeMB = $StringParts[3]
                                $DiskSizeMB = [float] $DiskSizeMB.substring(1,$DiskSizeMB.length-1)
                                $DiskSizeUnits = $StringParts[4]
                                $DiskSizeUnits = $DiskSizeUnits.substring(0,$DiskSizeUnits.length-1)
                                if ( $DiskSizeUnits -eq "KB" ) { $DiskSizeMB = 0 }
                                if ( $DiskSizeUnits -eq "GB" ) { $DiskSizeMB = $DiskSizeMB * 1024 }
                                if ( $DiskSizeUnits -eq "TB" ) { $DiskSizeMB = $DiskSizeMB * 1024 * 1024 }
                                if ( $DiskSizeUnits -eq "PB" ) { $DiskSizeMB = $DiskSizeMB * 1024 * 1024 * 1024 }
		
                                ##################################################################
                                ## What is the size of the backup? Convert to MB if required.
                                ##################################################################
                                $StringParts = $EachLog.Description.Split(' ')
                                $BackupSizeMB = [float] $StringParts[0] 
                                $BackupSizeUnits = $StringParts[1] 
                                if ( $BackupSizeUnits -eq "KB" ) { $BackupSizeMB = 0 }
                                if ( $BackupSizeUnits -eq "GB" ) { $BackupSizeMB = $BackupSizeMB * 1024 }
                                if ( $BackupSizeUnits -eq "TB" ) { $BackupSizeMB = $BackupSizeMB * 1024 * 1024 }
                                if ( $BackupSizeUnits -eq "PB" ) { $BackupSizeMB = $BackupSizeMB * 1024 * 1024 * 1024 }

                                ##################################################################
                                ## What is the speed of the backup? Convert to MB/sec if required.
                                ##################################################################
                                $BackupRateMB = $StringParts[4]
                                $BackupRateUnits = $StringParts[5]
                                if ( $BackupRateUnits -eq "KB/s" ) { $BackupRateMB = 0 }
                                if ( $BackupRateUnits -eq "GB/s" ) { $BackupRateMB = $BackupRateMB * 1024 }
                                if ( $BackupRateUnits -eq "TB/s" ) { $BackupRateMB = $BackupRateMB * 1024 * 1024 }
                                if ( $BackupRateUnits -eq "PB/s" ) { $BackupRateMB = $BackupRateMB * 1024 * 1024 * 1024}
		
                                ##################################################################
                                ## How long did the backup take?
                                ##################################################################
                                $TimeDiff = $EachLog.updatetime - $EachLog.starttime

                                ##################################################################
                                ## Add record for the VM/VMDK to the array.
                                ##################################################################
                                $OneLine = "" | select "JobName","VMName","Destination","SourceSAN","ProxyUsed","BackupType","DiskNumber","DiskSizeMB","BackupSizeMB","BackupRateMBperSec","PrimaryBottleneck","SourceBusy","ProxyBusy","NetworkBusy","TargetBusy","StartTime","EndTime","TotalMinutes"
                                $OneLine.JobName = $EachJob.Name
                                $OneLine.VMName = $EachVM.name 
                                $OneLine.Destination = $EachJob.TargetDir
                                $OneLine.SourceSAN = $SourceSAN
                                $OneLine.ProxyUsed = $ProxyUsed
                                $OneLine.BackupType = $BackupType
                                $OneLine.DiskNumber = $DiskNumber
                                $OneLine.DiskSizeMB = $DiskSizeMB
                                $OneLine.BackupSizeMB = $BackupSizeMB
                                $OneLine.StartTime = $EachLog.starttime
                                $OneLine.EndTime = $EachLog.updatetime
                                $OneLine.BackupRateMBperSec = $BackupRateMB
                                $OneLine.TotalMinutes = $TimeDiff.TotalMinutes
                                $BigList += $OneLine
                                $OneLine = $null
                            } 
                            
                            ##################################################################
                            ## How busy is each component?
                            ##################################################################
                            if ( $EachLog.title -like "Busy*" ) {
                                $StringParts = $EachLog.title.Split(' ')
                                $SourceBusy = $StringParts[2]
                                $ProxyBusy = $StringParts[5]
                                $NetworkBusy = $StringParts[8]
                                $TargetBusy = $StringParts[11]
                            }

                            ##################################################################
                            ## Where is the bottleneck?
                            ##################################################################
                            if ( $EachLog.title -like "Primary Bottleneck*" ) {
                                $StringParts = $EachLog.title.Split(' ')
                                $PrimaryBottleneck = $StringParts[2]

                                ##################################################################
                                ## Busy/Bottleneck metrics are per VM. Copy to each VM/VMDK record.
                                ## This is the last Log Record for the VM. Move to outer array.
                                ##################################################################
                                foreach ( $ListItem in $BigList ) {
                                    $ListItem.PrimaryBottleneck = $PrimaryBottleneck
                                    $ListItem.SourceBusy = $SourceBusy
                                    $ListItem.ProxyBusy = $ProxyBusy
                                    $ListItem.NetworkBusy = $NetworkBusy
                                    $ListItem.TargetBusy = $TargetBusy
                                    $BiggerList += $ListItem
                                }
                            }
                        }
                    }
                }
            }
        } 
    }
}

##################################################################
## Output the array to a CSV file.
##################################################################
$LogDate = Get-Date -Format "yyyyMMdd"
$ReportFileName = 'BackupReportPublic-'+$LogDate+'.csv'
$BiggerList | export-csv $ReportFileName
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 14 guests