We've been using a script for a long time now to report the backup size per job each day. However, we've noticed that backups using the new backup chain format (per-vm backup file and metadata) returns no value for the GetAllStorages() method. For the backups that haven't been upgraded yet we still get a value. I'm guessing this is due to the new backup chain format?
I'm fairly amateur with powershell and looking for some pointers on how to resolve this, any help would be appreciated. Below is the script that we've been using:
Code: Select all
# Load Veeam Snapin
Import-Module Veeam.Backup.PowerShell
#Clear out variable values
$VbrJobs = @()
$JobReport = @()
$Backup = @()
$BackupSize = @()
$Job = @()
#Get All Backup Jobs
$VbrJobs = Get-VBRJob | where-object {$_.IsScheduleEnabled -eq $True -and $_.JobType -eq "Backup"} | Sort-Object typetostring, name
#Loop through all backups jobs
Foreach($Job in $VbrJobs)
{
#Clear values of all variables used
$Objects = @()
$Object = @()
$VMName = @()
$Tasks = @()
$vmcount = @()
$GetVMs = @()
$WarningVMs = @()
$WarningMsg = @()
#Find the Last Backup Job where equals job name
$JobDetails = $Job.FindLastSession()
$Log = $JobDetails.Logger.GetLog()
#Get the VBRBackup where equals job name in order to expose size of backup
$Backup = Get-VBRBackup -Name $Job.Name
$RepoTarget = $Job.FindTargetRepository()
$RepoTarget = $RepoTarget.Name
#Expose size of Backup and run calculation
$BackupSize = $Backup.GetAllStorages() | Sort-Object creationtime | Select-Object -last 1 | select @{e={[math]::Round($_.stats.backupsize/1024/1024/1024,2)}}
#Get all the VMs in the Job
$Objects = $Job.GetObjectsInJob()
#Count the number of VMs in Job
$vmcount = $Objects.Count
$BackupDate=(get-date (get-date).AddDays(-1) -UFormat "%d/%m/%Y")
if ($Job.FindLastSession().Logger.GetLog().UpdatedRecords.Title | Select-String "Synthetic") {
$isFull = "True"
}
else {
$isFull = "False"
}
#Build Hash table of Completed Backup Jobs
$JobReport += New-Object -TypeName psobject -Property @{
JobName=$JobDetails.JobName;
DateofBackup=$BackupDate;
StartTime=$JobDetails.CreationTimeUTC;
EndTime=$JobDetails.EndTime;
Full=$isFull;
Result=$JobDetails.Result;Size=$BackupSize.'[math]::Round($_.stats.backupsize/1024/1024/1024,2)';
VMCount=$vmcount
Repo=$RepoTarget
}
}
$GetDateYYYYMMDD = Get-Date -UFormat "%Y-%m-%d"
$NewFolderPath = "C:\VeeamReports\"
$GetDayOfWeek = (get-date).DayOfWeek
# Set the location of the file to save to
$FilePath = $NewFolderPath + $GetDateYYYYMMDD + "-Veeam-BackupReports.csv"
#Sort Hash table by JobName
$JobReport = $JobReport | Sort-Object -Property JobName
#Select Details to save to File - will append for the week
$JobReport | select -Property JobName,DateofBackup,StartTime,EndTime,Full,Result,Size,VMCount,Repo | Export-Csv -Append $FilePath -NoTypeInformation