PowerShell script exchange
Post Reply
masonit
Service Provider
Posts: 325
Liked: 23 times
Joined: Oct 09, 2012 2:30 pm
Full Name: Maso
Contact:

Veeam Agent in protection group, find sessions

Post by masonit »

Hi

Is there any support for finding sessions for Veeam Agent in protection group? Get-VBRBackupSession does not work.

\Masonit
jhoughes
Veeam Vanguard
Posts: 279
Liked: 112 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Castle Rock, CO
Contact:

Re: Veeam Agent in protection group, find sessions

Post by jhoughes » 2 people like this post

Here's some code that will return all job & task sessions for agent backup jobs. You can add a parameter to specify a job name, if you need to target a single job.

As written, it will return these as the variables $AllJobSessions (job session IDs only), and $AllTaskSessions (full details of each task session).

Here's the code to query the agent job task sessions, hope it helps.

Code: Select all

$AgentJobs = Get-VBRJob | Where-Object {$_.JobType -eq 'EpAgentBackup'}

[System.Collections.ArrayList]$AllJobSessions = @()
[System.Collections.ArrayList]$AllTaskSessions = @()
foreach ($AgentJob in $AgentJobs){

    $JobSessions = [Veeam.Backup.Core.CBackupSession]::GetByJob($AgentJob.Id)

    if ([bool]$JobSessions){

        foreach ($CurrentSession in $JobSessions) {
            
          $auxdata = [xml]$CurrentSession.Info.AuxData
          $SessionIDs = (($auxdata.AuxData.EpPolicyJobSessionContext.Sessions) -split ';')

          foreach ($SingleSessionID in $SessionIDs) {
            if (![String]::IsNullOrWhiteSpace($SingleSessionID)) {

              $null = $AllJobSessions.Add($SingleSessionID)
  
            }
  
          }

        }

      }

    $UniqueJobSessions = $AllJobSessions | Select-Object -Unique
    
    foreach ($CurrentSessionID in $UniqueJobSessions) {

      $TaskSessions = Get-VBRTaskSession (Get-VBRSession -Id $CurrentSessionID)

      foreach ($CurrentTaskSession in $TaskSessions) {

        $null = $AllTaskSessions.Add($CurrentTaskSession)

      }

    }

}

Write-Output $AllTaskSessions
Only the $AllTaskSessions will be written to the pipeline, and you can dig further into the details with:

Code: Select all

$AllTaskSessions | Select-Object -First 1 -Property *
Husband, Father, Solutions Architect, Geek Extraordinaire | @DenverVMUG, @AustinVMUG & @ATXPowerShell leader | VMware vExpert | Cisco Champion
masonit
Service Provider
Posts: 325
Liked: 23 times
Joined: Oct 09, 2012 2:30 pm
Full Name: Maso
Contact:

Re: Veeam Agent in protection group, find sessions

Post by masonit »

Thanks!

I guess cmdlets for this will be available in later versions?

\Masonit
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Veeam Agent in protection group, find sessions

Post by veremin »

Correct, we're planning to have a specific cmdlet in version 10. Thanks!
masonit
Service Provider
Posts: 325
Liked: 23 times
Joined: Oct 09, 2012 2:30 pm
Full Name: Maso
Contact:

Re: Veeam Agent in protection group, find sessions

Post by masonit »

Great!

I am trying to see if I can get disk usage (not total size) on Veeam Agents (protection group) from VBR server. I can see in the session info for each agent that VBR is collecting this info, ex:

2019-11-08 01:00:16 :: Total size: 1004,6 GB (590,6 GB used)

Is there a better way of collecting this info than with session logs?

\Masonit
masonit
Service Provider
Posts: 325
Liked: 23 times
Joined: Oct 09, 2012 2:30 pm
Full Name: Maso
Contact:

Re: Veeam Agent in protection group, find sessions

Post by masonit »

jhoughes wrote: Nov 05, 2019 12:47 pm Here's some code that will return all job & task sessions for agent backup jobs. You can add a parameter to specify a job name, if you need to target a single job.

As written, it will return these as the variables $AllJobSessions (job session IDs only), and $AllTaskSessions (full details of each task session).

Here's the code to query the agent job task sessions, hope it helps.

Only the $AllTaskSessions will be written to the pipeline, and you can dig further into the details with:

Hi jhoughes

Is it possible to control tasksessions to collect? Maybe just sessions for last 4 days? It seems like it collects all available sessions. Takes a long time..

\Masonit
jhoughes
Veeam Vanguard
Posts: 279
Liked: 112 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Castle Rock, CO
Contact:

Re: Veeam Agent in protection group, find sessions

Post by jhoughes »

Sure, at the top of the 'foreach ($CurrentSession in $JobSessions)' loop, you could add an if statement to check if the date is within the last 4 days.

It would skip the job sessions otherwise.
Husband, Father, Solutions Architect, Geek Extraordinaire | @DenverVMUG, @AustinVMUG & @ATXPowerShell leader | VMware vExpert | Cisco Champion
masonit
Service Provider
Posts: 325
Liked: 23 times
Joined: Oct 09, 2012 2:30 pm
Full Name: Maso
Contact:

Re: Veeam Agent in protection group, find sessions

Post by masonit »

Thanks!

Any idea how to collect disk usage on Veeam Agents from VBR?

\Masonit
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Veeam Agent in protection group, find sessions

Post by veremin » 1 person likes this post

Session should have a backedupsize property that seems to provide information you're after. Thanks!
masonit
Service Provider
Posts: 325
Liked: 23 times
Joined: Oct 09, 2012 2:30 pm
Full Name: Maso
Contact:

Re: Veeam Agent in protection group, find sessions

Post by masonit »

Yes! Thanks! :)

\Masonit
masonit
Service Provider
Posts: 325
Liked: 23 times
Joined: Oct 09, 2012 2:30 pm
Full Name: Maso
Contact:

Re: Veeam Agent in protection group, find sessions

Post by masonit »

Hi!

I have been using the session backedupsize properties since my last reply in this thread. It has been working perfect so far. But now I have an issue. I have one pg with a ad Windows file cluster object. That file cluster is backuped with a vbr job. The cluster (clu01) is between 2 servers (server01, server02). When the backup runs I can see in the gui session that first clu01 appears and later server01 and server02 starts to backup up. In the session info servrer01 and server02 is not providing any diskusage info. It is only clu01 that show this info and it seems like it is a total value of both server01 and server02. But when when looking at the powershell session data. Clu01 is not showing any backedupsize data. It's only server01 and server02 that has this. Is there an easy way to collect the total backedupsize properties for the cluster as it is shown in the gui? Or do I need to add the cluster nodes together (server01, server02).

\Magnus
oleg.feoktistov
Veeam Software
Posts: 1912
Liked: 635 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Veeam Agent in protection group, find sessions

Post by oleg.feoktistov »

Hey Magnus,

Try the method below:

Code: Select all

$job = Get-VBRJob -Name "Cluster backup job"
$sessions = $job.FindLastSession()
$child = $sessions.GetChildSessions()
$child[0].BackupTotalSize 
Thanks,
Oleg
Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests