I made this script for reporting to my superiors and potentially trace the backup information of the subsidiaries afterwards.
I'm new to powershell and scripting so I think it's not super optimized. I wanted to do it by myself to learn (except html part).
1- Can you help me improve it through advice or method that I could have applied?
2- I cannot find how to get reverse incremental information. If the backup mode is reverse incremental, it always displays Incremental.
3- Also the search for tape jobs takes time (on average one minute per job according to measurement)
Code: Select all
<#
# Job Reporting
# Author: Me
# Script and data info: This script performs a reporting of current backup schedule
# Warning : It takes time
#
#>
$result = @()
$vbrjobs = Get-VBRJob # Creating a list of Veeam Backup Job (not tape)
foreach($vbrjob in $vbrjobs){
$name = $vbrjob.Name # Job name
$description = $vbrjob.Description # Job description
write-host "Gathering information for $name..."
# Getting data backed up informations
$listdata = Get-VBRJobObject -Job $vbrjob # Getting list of data backed up by the job
$namedata= ($listdata | Where-Object type -eq Include).name # Getting data name
$sizedata = ($listdata | Where-Object type -eq Include).approxsizestring # Getting data size
# Getting schedules job
write-host "Récupération des schedules..."
$scheduledays = $vbrjob.Info.ScheduleOptions.OptionsDaily.DaysSrv
$scheduleshours = "$($vbrjob.Info.ScheduleOptions.OptionsDaily.TimeLocal.Hour)h$($vbrjob.Info.ScheduleOptions.OptionsDaily.TimeLocal.minute)"
$activefullday = $vbrjob.AutoScheduleOptions.ActiveFullBackupDays
# Getting retention of job (not tape)
write-host "Récupération des rétentions (pas tape)..."
$retention = $vbrjob.BackupStorageOptions.RetainCycles
# Getting schedules tape job
write-host "Récupération du schedule tape... Prend du temps!"
$vbrjobtape = Get-VBRTapeJob | where {$_.object.name -eq $vbrjob.name}
$mediapool = Get-VBRTapeMediaPool -Name $vbrjobtape.Target # Name of the mediapool associated with the job
if($mediapool.type -eq "GFS"){
$weeklydayweek = $vbrjobtape.GFSScheduleOptions.WeeklyOptions.WeeklyDay
$monthlydaynumber = $vbrjobtape.GFSScheduleOptions.MonthlyOptions.DayOfWeekNumber
$monthlydayweek = $vbrjobtape.GFSScheduleOptions.MonthlyOptions.DayOfWeek
$yearlydaynumber = $vbrjobtape.GFSScheduleOptions.YearlyOptions.DayOfWeekNumber
$yearlydayweek = $vbrjobtape.GFSScheduleOptions.YearlyOptions.DayOfWeek
$yearlymonth = $vbrjobtape.GFSScheduleOptions.YearlyOptions.MonthOfyear
$tapeschedule = "$($weeklydayweek)/Weekly",
"$($monthlydaynumber)/$($monthlydayweek)/Monthly",
"$($yearlydaynumber)/$($yearlymonth)/$($yearlydayweek)/Yearly"
}
else{
$type = $vbrjobtape.ScheduleOptions.Type
switch ( $type ) {
"AfterJob" { $tapeschedule = 'AfterJob' }
"Daily" { $tapeschedule = "$($vbrjobtape.ScheduleOptions.DailyOptions.period)/$($vbrjobtape.ScheduleOptions.DailyOptions.DayOfWeek)"}
"Monthly" {$tapeschedule = "$($vbrjobtape.ScheduleOptions.MonthlyOptions.period)/$($vbrjobtape.ScheduleOptions.MonthlyOptions.DayOfWeek)" }
}
}
# Getting retention secondary targets
write-host "Getting secondary target retention if exist"
$vbrjoboptions = Get-VBRJobOptions -Job $vbrjob # Shorcut name to get access to job properties
if ($vbrjoboptions.sanintegrationoptions.SanSnapshotBackupTransferEnabled -eq "True"){
$snapshottransfert = $vbrjoboptions.sanintegrationoptions.SanSnapshotBackupTransferRetention
} else {$snapshottransfert = "N/A"}
if ($vbrjoboptions.sanintegrationoptions.SanSnapshotSourceEnabled -eq "True"){
$snapshotsource = $vbrjoboptions.sanintegrationoptions.SanSnapshotSourceRetention
} else {$snapshotsource = "N/A"}
# Getting Backup Mode
write-host "Récupération du mode de backup"
$fullnumber = $vbrjob.AutoScheduleOptions.ActiveFullBackupKind
if ($vbrjoboptions.Options.RootNode.Algorithm -eq "Syntethic"){
$backupmode = "Reversed Incremental"
}
if ($vbrjoboptions.Options.RootNode.Algorithm -eq "Increment") {
if ($vbrjob.Options.Options.RootNode.TransformFullToSyntethic -eq "True" -And $vbrjoboptions.Options.RootNode.TransformIncrementsToSyntethic -eq "True") {
$backupmode = "Incremental ( Synthetic full enabled, Transform previous full backup chains into rollbacks )"
}
if ($vbrjoboptions.Options.RootNode.TransformFullToSyntethic -eq "True" -And $vbrjoboptions.Options.RootNode.TransformIncrementsToSyntethic -eq "False") {
$backupmode = "Incremental ( Synthetic full enabled )"
}
if ($vbrjoboptions.Options.RootNode.TransformFullToSyntethic -eq "False" -And $vbrjoboptions.Options.RootNode.TransformIncrementsToSyntethic -eq "False") {
$backupmode = "Incremental ( Synthetic full disabled, Active full backups )"
}
}
# All info into $result variable
$result += $vbrjob | select Name,
Description,
@{n='Data';e={$dataname}},
@{n='DataSize';e={$sizedata}},
@{n='ScheduleHours';e={$scheduleshours}},
@{n='ScheduleDays';e={$scheduledays}},
@{n='BackupMode';e={$backupmode}},
@{n='ActiveFullDay';e={$activefullday}},
@{n='RestorePointRepository';e={$retention}},
@{n='SnapshotAFFA300';e={$snapshotsource}},
@{n='SnapshotFAS2650';e={$snapshottransfert}},
@{n='TapeJob';e={$vbrjobtape.name}},
@{n='TapeSchedule';e={$tapeschedule}
}
}
# Send mail
$headerBackColor = '#4F81BD' # backgroundcolor for column headers
$oddRowBackColor = '#DCE6F1' # background color for odd rows
$style = @"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Report</title>
<meta name="generator" content="PowerShell" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
body {
font-family: Verdana, Arial, Geneva, Helvetica, sans-serif;
font-size: 12px;
color: black;
}
table, td, th {
border-color: black;
border-style: solid;
font-family: Verdana, Arial, Geneva, Helvetica, sans-serif;
font-size: 11px;
}
table {
border-width: 0 0 1px 1px;
border-spacing: 0;
border-collapse: collapse;
}
td, th {
margin: 0;
padding: 4px;
border-width: 1px 1px 0 0;
text-align: left;
}
th {
color: white;
background-color: $headerBackColor;
font-weight: bold;
}
</style>
"@
$mymail = $result | ConvertTo-Html -Property Name,Description,Data,Datasize,Scheduleshours,ScheduleDays,BackupMode,ActiveFullDay,RestorePointRepository,SnapshotAFFA300,SnapshotFAS2650,TapeJob,TapeSchedule -Head $style | Out-String
$attachement = $mymail | Out-File .\backup-strategy.html
Send-MailMessage -BodyAsHtml $mymail -Attachments .\backup-strategy.html -from "me" -To "me" -SmtpServer smtp.directory.manitou.com -subject "Backup Strategy"