Last active
August 29, 2015 13:57
-
-
Save smurawski/9352803 to your computer and use it in GitHub Desktop.
Description for Get-NetbackupStatus.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[cmdletbinding()] | |
param ( | |
# Starttime for backup operation, in NBU format | |
$StartTime = "17:00:00", | |
# Endtime for backup operation, in NBU format | |
$Endtime = "17:00:00", | |
# Path to $outputfile | |
$OutputPth = "C:\scripts", | |
# Name of outputfile | |
$OutputFile = "BackupReport.txt", | |
# Address of SMTP server | |
$SmtpServer = "smtp.server", | |
# From e-mail address | |
$From = "netbackup@company.com", | |
# To e-mail address. Multiple addresses can be used, seperate by comma | |
$To = "report@company.com", | |
# Textfile containing e-mail addresses to CC, one per line. Located in $outputpth | |
$CC = "CC-Recipients.txt", | |
# Number of characters in the $client string, including whitespace | |
$ClientStringLength = 15, | |
# Number of characters in the $Policy string, including whitespace | |
$PolicyStringLength = 25, | |
# Number of characters in the $Files string, including whitespace | |
$FileStringLength = 10, | |
# Number of characters in the $KBs string, including whitespace | |
$KBStringLength = 12, | |
# Number of characters in the $Elapsed string, including whitespace | |
$ElapsedString = 10 | |
) | |
Push-Location 'C:\Program Files\Veritas\NetBackup\bin\admincmd' | |
function Get-NbuStartAndEndTime { | |
param ([string]$StartTime) | |
$Now = Get-Date | |
New-Object PSObject -Property @{ | |
Now = $Now | |
StartDate = If (($Now.DayOfWeek -like 'Monday')) { | |
"{0:MM\/dd\/yyyy $StartTime}" -f ($Now.AddDays(-3)) | |
} | |
else { | |
"{0:MM\/dd\/yyyy $StartTime}" -f ($Now.AddDays(-1)) | |
} | |
EndDate = "{0:MM\/dd\/yyyy $Endtime}" -f ($Now) | |
} | |
} | |
function Get-NbuPolicyList { | |
./bppllist.exe | |
} | |
function Get-NbuPolicyDetail { | |
param ([string]$Policy) | |
$Detail = ./bppllist.exe $Policy -L | |
New-Object PSObject -Property @{ | |
Detail = $Detail | |
Active = ( ($Detail | Select-String "Active\:" | %{$_.ToString().SubString(19).Trim()}) -like 'yes' ) | |
ClientList = ($Detail | select-String "Client/HW/OS/Pri/DMI/CIT\:" | foreach {($_.ToString().Split()[2]).trim()}) | where {-not [string]::IsNullOrEmpty($_)} | |
PolicyType = ($Detail | Select-String "Policy Type\:" | %{$_.ToString().SubString(19).Trim()}) | |
} | |
} | |
function Get-NbuImage { | |
param ($ClientImages) | |
ForEach ($Image in $ClientImages) { | |
if (-not [string]::IsNullOrEmpty($Image)) { | |
$Image = $Image.ToString().Split() | |
$JobStart = [Int32]$Image[13] | |
$JobEnd = [Int32]($JobStart+[Int32]$Image[14]) | |
$JobStartTime = $NBU_BaseTime.AddSeconds($JobStart) | |
$JobEndTime = $NBU_BaseTime.AddSeconds($JobEnd) | |
New-Object PSObject -Property @{ | |
Files = [Int32]$Image[19] | |
KBs = [Int32]$Image[18] | |
JobStart = [Int32]$Image[13] | |
JobEnd = [Int32]($JobStart+[Int32]$Image[14]) | |
JobStartTime = $JobStartTime | |
JobEndTime = $JobEndTime | |
ElapsedTime = New-TimeSpan $JobStartTime $JobEndTime | |
} | |
} | |
} | |
} | |
function Get-NbuPolicyClientActivityDetail { | |
param ([string[]]$ClientList, $Timings, $Policy) | |
foreach ($client in $ClientList) | |
{ | |
New-Object PSObject -Property @{ | |
ClientName = $client | |
Jobs = ./bperror.exe -client $Client -U -backstat -s info -d $Timings.StartDate -e $Timings.EndDate 2>&1 | Select-String $Policy | |
Images = ./bpimagelist.exe -client $Client -d $($Timings.StartDate) -e $EndDate 2>&1 | Select-String $Policy | |
} | |
} | |
} | |
$OutputFilePath = $OutputPth + "\" + $OutputFile # Combine $OutputPth and $OutputFile to a single string | |
# --- | |
$JobHeader = "STATUS CLIENT POLICY SCHED SERVER TIME COMPLETED" # General header for backup job status | |
$ClientNotReported = @("";"Servers that did not (yet) report any activity";"----------------------------------------------";("CLIENT"+" "*($ClientStringLength-6))+("POLICY"+" "*($PolicyStringLength-6))) # initialize array for servers that did not report activity at the time of running the report and add header | |
$AllSuccessfulJobs = @() | |
$AllPartiallyCompletedJobs = @() | |
$AllFailedJobs = @() # Initialize array to contain the final results for all failed jobs | |
$UsedPolSched = @() # Initialize array to contain policies and schedules used during backup operation, used to report on disk storageunits. | |
# --- | |
$NBU_BaseTime = get-date "1/1/1970 00:00:00" # Netbackup Basetime, used to calculate elapsed time | |
$TotalFiles = 0 | |
$TotalKB = 0 | |
$NBUStats = @() | |
$NBUStatsHeader = @("";"BACKUP STATISTICS";("CLIENT"+" "*($ClientStringLength-6))+("POLICY"+" "*($PolicyStringLength-6))+("FILES"+" "*($FileStringLength-5))+("SIZE"+" "*($KBStringLength-4))+("ELAPSED"+" "*($ElapsedString-7))) # Array containing header for backup statistics | |
$NBUStatsHeader += @("-"*$NBUStatsHeader[2].Length) | |
$Timings = Get-NbuStartAndEndTime -StartTime $StartTime | |
$temp = foreach ($Policy in (Get-NbuPolicyList)) | |
{ | |
$PolicyDetail = Get-NbuPolicyDetail -Policy $Policy | |
$PolicyClientActivityDetail = Get-NbuPolicyClientActivityDetail -ClientList $PolicyDetail.ClientList -Timings $Timings -Policy $Policy | |
New-Object PSObject -Property @{ | |
PolicyName = $Policy | |
PolicyDetail = $PolicyDetail | |
PolicyJob = $PolicyJobs | |
} | |
} | |
Pop-Location | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment