-
- Novice
- Posts: 7
- Liked: never
- Joined: Aug 09, 2018 12:17 pm
Get-VBRComputerBackupJob per Agent status
Hi all,
I'm trying to get an overview of all agents in a Windows Agent Backup with Powershell. The same way VEEAM does when generating a report.
(report)
Is there a way getting this information with Powershell? I can use the Get-VBRComputerBackupJob and Get-VBRComputerBackupJobSession commands, but they do not give me the information per Agent. In our scenario the agents are in a ProtectionGroup. Also with Get-VBRProtectionGroup this group can be read and I can see the Agent names, but how to connect this with individual tasks?
In short I want to:
- Get the Windows Backup Job
- Get the Agents
- Get the infromation from the last task per agent
Hope someone can help me
I'm trying to get an overview of all agents in a Windows Agent Backup with Powershell. The same way VEEAM does when generating a report.
(report)
Is there a way getting this information with Powershell? I can use the Get-VBRComputerBackupJob and Get-VBRComputerBackupJobSession commands, but they do not give me the information per Agent. In our scenario the agents are in a ProtectionGroup. Also with Get-VBRProtectionGroup this group can be read and I can see the Agent names, but how to connect this with individual tasks?
In short I want to:
- Get the Windows Backup Job
- Get the Agents
- Get the infromation from the last task per agent
Hope someone can help me
-
- Veeam Software
- Posts: 2010
- Liked: 670 times
- Joined: Sep 25, 2019 10:32 am
- Full Name: Oleg Feoktistov
- Contact:
Re: Get-VBRComputerBackupJob per Agent status
Hi,
That's what I usually use to fetch this info:
Best regards,
Oleg
That's what I usually use to fetch this info:
Code: Select all
$jobs = Get-VBRComputerBackupJob
$taskSessions = @()
foreach ($job in $jobs) {
$sessions = Get-VBRComputerBackupJobSession | where {$_.JobId -eq $job.Id}
foreach ($session in $sessions) {
$tasks = Get-VBRTaskSession -Session $session
$taskSessions += $tasks
}
}
$taskSessions | select Name, Status, @{n='StartTime';e={$_.Info.Progress.StartTimeUtc}}, `
@{n='EndTime';e={$_.Info.Progress.StopTimeUtc}}, @{n='Size';e={$_.Info.Progress.TotalSize}}, `
@{n='Read';e={$_.Info.Progress.ReadSize}}, `
@{n='Transferred';e={$_.Info.Progress.TransferedSize}}, @{n='Duration';e={$_.Info.Progress.Duration.ToString()}}
Oleg
-
- Novice
- Posts: 7
- Liked: never
- Joined: Aug 09, 2018 12:17 pm
Re: Get-VBRComputerBackupJob per Agent status
Hi Oleg,
Thank you for helping me!
It also seems to give me the information... but a lot more than expected. I try to explain.
The specific Job is only a few weeks old and had two backup sessions.
Running:
$jobs.Count also returns only 1 item.
So the following foreach is only fetching information for this job. Where $job is the one job which is in $jobs.
But when fetching the sessions, it does return all the sessions. Even sessions far before the Job was created. For some reason the Where-statement does not work on the command.
When running the same expression in on the variable. It is working (?)
I manipulated the script a bit so only the tasks for the two sessions are used:
But no tasks are found.
The tasks are found when using all the (1440) sessions. But a lot more information is shown. I only want to see the information of this specific job and those sessions.
I do not understand.
Thank you for helping me!
It also seems to give me the information... but a lot more than expected. I try to explain.
The specific Job is only a few weeks old and had two backup sessions.
Running:
Code: Select all
$jobs = Get-VBRComputerBackupJob
So the following foreach is only fetching information for this job. Where $job is the one job which is in $jobs.
Code: Select all
foreach ($job in $jobs) {
...
}
Code: Select all
$sessions = Get-VBRComputerBackupJobSession | where {$_.JobId -eq $job.Id}
When running the same expression in on the variable. It is working (?)
Code: Select all
$sessions | where {$_.JobId -eq $job.Id}
I manipulated the script a bit so only the tasks for the two sessions are used:
Code: Select all
$jobs = Get-VBRComputerBackupJob
$taskSessions = @()
foreach ($job in $jobs) {
$sessions = Get-VBRComputerBackupJobSession
$sessions2 = $sessions | where {$_.JobId -eq $job.Id}
foreach ($session in $sessions2) {
$tasks = Get-VBRTaskSession -Session $session
$taskSessions += $tasks
}
}
$taskSessions | select Name, Status, @{n='StartTime';e={$_.Info.Progress.StartTimeUtc}}, `
@{n='EndTime';e={$_.Info.Progress.StopTimeUtc}}, @{n='Size';e={$_.Info.Progress.TotalSize}}, `
@{n='Read';e={$_.Info.Progress.ReadSize}}, `
@{n='Transferred';e={$_.Info.Progress.TransferedSize}}, @{n='Duration';e={$_.Info.Progress.Duration.ToString()}}
But no tasks are found.
The tasks are found when using all the (1440) sessions. But a lot more information is shown. I only want to see the information of this specific job and those sessions.
I do not understand.
-
- Novice
- Posts: 7
- Liked: never
- Joined: Aug 09, 2018 12:17 pm
Re: Get-VBRComputerBackupJob per Agent status
Managed to get the information. It was a puzzle, but I think this is working:
Code: Select all
$computerbackupjobs = Get-VBRComputerBackupJob
foreach ($job in $computerbackupjobs) {
$agents = Get-VBRBackup | ? { $_.BackupPolicyTag -eq $job.Id -and $_.JobType -eq 'EpAgentManagement' }
foreach ($agent in $agents) {
$lastsession = $sessions | ? { $_.JobId -eq $agent.JobId } | Select-Object -First 1
$jobobject = Get-VBRJobObject -Job $agent.JobId.Guid
Write-Host "Processing Session: $($job.Name) | $($jobobject.Name)"
sessionid=$($lastsession.Id)
name=$($jobobject.Name)
backupstart=$($lastsession.CreationTime | Get-Date -Format "yyyy-MM-dd HH:mm:ss").ToString()
backupstop=$($lastsession.EndTime | Get-Date -Format "yyyy-MM-dd HH:mm:ss").ToString()
jobname=$($job.Name)
mgtserver="$($env:computername) ($veeamserver)"
jobtype=$($agent.JobType.ToString())
status=$($lastsession.Result).ToString()
}
}
-
- Veeam Software
- Posts: 2010
- Liked: 670 times
- Joined: Sep 25, 2019 10:32 am
- Full Name: Oleg Feoktistov
- Contact:
Re: Get-VBRComputerBackupJob per Agent status
Long story short, looks like backup sessions of agent management job type have child sessions. So, when you try to get task sessions by parent backup sessions, the output is empty. The workaround for this kind of sessions would be to get child one first. Example:
Meanwhile, I brought this up internally. This is definitely a bug, and Get-VBRTaskSession should be showing these child sessions directly.
Thanks!
Code: Select all
$jobs = Get-VBRComputerBackupJob
$jobType = [Veeam.Backup.Model.EDbJobType]::EpAgentManagement
$backupSessions = [Veeam.Backup.Core.CBackupSession]::GetByJobType($jobType)
$taskSessions = @()
foreach ($job in $jobs) {
$sessions = $backupSessions | where {$_.Name -match $job.Name}
foreach ($session in $sessions) {
$childSession = $session.GetChildSessions()
$tasks = Get-VBRTaskSession -Session $session
$taskSessions += $tasks
}
}
$taskSessions | select Name, Status, @{n='StartTime';e={$_.Info.Progress.StartTimeUtc}}, `
@{n='EndTime';e={$_.Info.Progress.StopTimeUtc}}, @{n='Size';e={$_.Info.Progress.TotalSize}}, `
@{n='Read';e={$_.Info.Progress.ReadSize}}, `
@{n='Transferred';e={$_.Info.Progress.TransferedSize}}, @{n='Duration';e={$_.Info.Progress.Duration.ToString()}}
Thanks!
-
- Veeam Software
- Posts: 2010
- Liked: 670 times
- Joined: Sep 25, 2019 10:32 am
- Full Name: Oleg Feoktistov
- Contact:
Re: Get-VBRComputerBackupJob per Agent status
Just a quick update on this one. Apologies for misguidance, but Get-VBRComputerBackupJobSession does return child backup sessions for agent management jobs, it's just almost no way to differentiate them. So, the bug still stands. Meanwhile, you can use a dash sign in conjunction with a wildcard when passing a job name to retrieve only child sessions for this job and then use a loop to retrieve task sessions:
Thanks!
Code: Select all
$job = Get-VBRComputerBackupJob -Name 'Agent Backup Job'
$sessions = Get-VBRComputerBackupJobSession -Name "$($job.Name)?*"
foreach ($session in $sessions) {
Get-VBRTaskSession -Session $session
}
Who is online
Users browsing this forum: No registered users and 3 guests