PowerShell script exchange
Deepak
Lurker
Posts: 1
Liked: never
Joined: Jul 20, 2021 9:50 am
Full Name: DEEPAk Gulati
Contact:

Want to capture running jobs by "session type" i.e SOBR-Tiering

Post by Deepak »

Hi,

I want to capture the running jobs by the "session type" i.e in my case , i want to capture the "SOBR Tiering" job but couldn't find any relevant powershell command to get it directly. Please help
Vitaliy S.
VP, Product Management
Posts: 27055
Liked: 2710 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: Want to capture running jobs by "session type" i.e SOBR-Tiering

Post by Vitaliy S. »

Hi,

If you're referring to the offload sessions for capacity and archive tiers, then these are not exposed via PowerShell, but thanks for your FR!

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

Re: Want to capture running jobs by "session type" i.e SOBR-Tiering

Post by oleg.feoktistov » 1 person likes this post

Hi,

Vitally is correct. For now, as a workaround you can use unofficial .NET method below to get running offload sessions:

Code: Select all

$jobType = [Veeam.Backup.Model.EDbJobType]::ArchiveBackup
$sessions = [Veeam.Backup.Core.CBaseSession]::GetRunning() | where {$_.JobType -eq $jobType} 
Thanks,
Oleg
AlexL
Service Provider
Posts: 89
Liked: 5 times
Joined: Aug 24, 2010 8:55 am
Full Name: Alex
Contact:

Re: Want to capture running jobs by "session type" i.e SOBR-Tiering

Post by AlexL »

How would I get all sobr sessions, not just running ones?
oleg.feoktistov
Veeam Software
Posts: 1912
Liked: 635 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Want to capture running jobs by "session type" i.e SOBR-Tiering

Post by oleg.feoktistov »

Here is the workaround through .NET types:

Code: Select all

$tiering = [Veeam.Backup.Model.EDbJobType]::ArchiveBackup
$freezing = [Veeam.Backup.Model.EDbJObType]::ArchiveFreezing
$jobTypes = @()
$jobTypes += $tiering, $freezing
[Veeam.Backup.Core.CBackupSession]::GetByJobType($jobTypes) 
AlexL
Service Provider
Posts: 89
Liked: 5 times
Joined: Aug 24, 2010 8:55 am
Full Name: Alex
Contact:

Re: Want to capture running jobs by "session type" i.e SOBR-Tiering

Post by AlexL »

awesome, just what I need

on a side note, I'm also looking for something like this:

total number of restore points in a specified sobr that are created today and are offloaded to object storage
or perhaps better, a list of all restore points created today for a specified sobr that have allready been offloaded to object storage
AlexL
Service Provider
Posts: 89
Liked: 5 times
Joined: Aug 24, 2010 8:55 am
Full Name: Alex
Contact:

Re: Want to capture running jobs by "session type" i.e SOBR-Tiering

Post by AlexL »

figured it out, this query (mssql 2019 and v11a) does it for us, where 0 is local and 1 is offloaded, mind you, we use copy immediate

Code: Select all

SELECT  TOP (100) PERCENT dbo.[Backup.Model.Storages].external_content_mode, COUNT(dbo.[Backup.Model.Storages].external_content_mode) AS count
FROM     dbo.[Backup.Model.Storages] INNER JOIN
             dbo.[Backup.Model.OIBs] ON dbo.[Backup.Model.Storages].id = dbo.[Backup.Model.OIBs].storage_id
WHERE  (dbo.[Backup.Model.Storages].creation_time >= { fn CURDATE() })
GROUP BY dbo.[Backup.Model.Storages].external_content_mode
and this can of course be very easy queried with only a few lines of powershell
oleg.feoktistov
Veeam Software
Posts: 1912
Liked: 635 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Want to capture running jobs by "session type" i.e SOBR-Tiering

Post by oleg.feoktistov » 1 person likes this post

That could be the case. However, since this subforum is dedicated to VBR & VE powershell modules, I must note that querying this info through our PS module imposes a problem. In Powershell storages copied (not moved) to capacity tier are referenced by original storages' id, thus, are not displayed neither in Get-VBRRestorePoint, nor in $backup.GetAllStorages() output. When obtained with $backup.GetAllStorages(), their ExternalContentMode, unlike in Backup.Model.Storages table, will stay "Internal". So, to validate that this particular storage has a copy in capacity tier via VBR powershell you would need to also check Backup.Model.StorageCopies table for copies. Hence, mapping your SQL query to Powershell using our VBR module, I would do something like this:

Code: Select all

$backup = Get-VBRBackup
$rps = Get-VBRRestorePoint -Backup $backup
$storages = @() # Log of all storages is safed here 
$OffloadedCount = 0 # count of offloaded storages for today
$currDate = (Get-Date).ToShortDateString()
foreach ($rp in $rps) {
 $storage = $rp.GetStorage()
 $storapeCopy = [Veeam.Backup.Core.CStorageCopy]::FindByStorageId($storage.Id)
 if ($storapeCopy) {
  $HasOffloadedCopy = $true
 }
 else {
  $HasOffloadedCopy = $false
 }
 
 $storages += $storage | select Id, PartialPath, ExternalContentMode, @{n='HasOffloadedCopy';e={$HasOffloadedCopy}}
 $creationTime = $storage.CreationTime.ToShortDateString()
 if ($storage.ExternalContentMode -eq "External" -or $HasOffloadedCopy -eq $true -and $creationTime -eq $currDate) {
  $OffloadedCount++
 }
}
Thanks!
AlexL
Service Provider
Posts: 89
Liked: 5 times
Joined: Aug 24, 2010 8:55 am
Full Name: Alex
Contact:

Re: Want to capture running jobs by "session type" i.e SOBR-Tiering

Post by AlexL »

cool, thanks, will definitely look at that, the powershell way is of course preferred above a self sort of reverse engineered sql query, hopefully in v12 (or v11b?) there will be a cmdlet for this
tdewin
Veeam Software
Posts: 1775
Liked: 646 times
Joined: Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin
Contact:

Re: Want to capture running jobs by "session type" i.e SOBR-Tiering

Post by tdewin » 2 people like this post

@oleg.feoktistov and I had an internal chat for a customer that just wanted to see the last 24h. Turns out there is an UNSUPPORTED way of doing this. It seems so useful that we decided to share it here

Code: Select all

$now = get-date
$offsetfilter = $now.AddDays(-1)
$jts = @([Veeam.Backup.Model.EDbJobType]::ArchiveBackup,[Veeam.Backup.Model.EDbJobType]::ArchiveFreezing)
$sessions = [Veeam.Backup.DBManager.CDBManager]::Instance.JobsSessions.GetSessionsByTypeAndInterval($jts, $offsetfilter,$now) | sort-object -property CreationTime
foreach ($session in $sessions) {
 $fullsessions = [Veeam.Backup.Core.CBackupSession]::GetByOriginalSessionId($session.OriginalSessionId)
 foreach ($fullsession in $fullsessions) {
	write-host "====================="
	write-host $fullsession.CreationTime
	write-host $fullsession.Result
 	write-host $fullsession.State  
        foreach ($task in $fullsession.GetTaskSessions()) { 
          write-host "-- sub"
          write-host $task.Name
	  write-host $task.Status
          foreach ($logline in ($task.Logger.GetLog().UpdatedRecords)) {
            if ($logline.title -match "(vbk|vib)") {
               write-host $logline.title
            }
          }
        }
 }
}
For those wondering about what jobtypes there are, you can query the enum like this:

Code: Select all

[System.Enum]::GetValues([Veeam.Backup.Model.EDbJobType])
Disclaimer: Use at your own risk as the dotnet calls as stated earlier are unsupported
oleg.feoktistov
Veeam Software
Posts: 1912
Liked: 635 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Want to capture running jobs by "session type" i.e SOBR-Tiering

Post by oleg.feoktistov »

Turns out now there is some other curious method available:

Code: Select all

$repo = Get-VBRBackupRepository -Name 'SOBR.Azure' -ScaleOut
$backup = Get-VBRBackup -Name 'Backup to SOBR with Azure'
$objects = $backup.GetObjectIds()
foreach ($object in $objects) {
  $backup.GetStoragesInCapacityTier($object, $repo.CapacityExtent.Id)
}
It looks simplier and works like a charm either with moved or copied storages.
efd121
Enthusiast
Posts: 46
Liked: 2 times
Joined: Aug 07, 2015 8:45 pm
Full Name: David Engler
Contact:

Re: Want to capture running jobs by "session type" i.e SOBR-Tiering

Post by efd121 »

Looking at the code snippet from oleg.feoktistov from Dec 2nd is there a way to get the restore points from the data returned?

I want to use the returned data and start a restore from the Capacity tier's most recent backup

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

Re: Want to capture running jobs by "session type" i.e SOBR-Tiering

Post by oleg.feoktistov »

Hi David,


Yes, you can get restore point for each storage using GetOibs method:

Code: Select all

$repo = Get-VBRBackupRepository -Name 'SOBR.Azure' -ScaleOut
$backup = Get-VBRBackup -Name 'Backup to SOBR with Azure'
$objects = $backup.GetObjectIds()
$allStorages = @()
foreach ($object in $objects) {
  $storages = $backup.GetStoragesInCapacityTier($object, $repo.CapacityExtent.Id)
  $allStorages += $storages
}

foreach ($storage in $allStorages) {
  $storage.GetOibs()
}
Best regards,
Oleg
efd121
Enthusiast
Posts: 46
Liked: 2 times
Joined: Aug 07, 2015 8:45 pm
Full Name: David Engler
Contact:

Re: Want to capture running jobs by "session type" i.e SOBR-Tiering

Post by efd121 »

Thanks for the quick reply I plan to try this soon
efd121
Enthusiast
Posts: 46
Liked: 2 times
Joined: Aug 07, 2015 8:45 pm
Full Name: David Engler
Contact:

Re: Want to capture running jobs by "session type" i.e SOBR-Tiering

Post by efd121 »

I was able to try the code you provided but I'm not sure how to use the results as a restore point for Start-VBRRestoreVM

Is there a way to convert or use this as the restore point Start-VBRRestoreVM needs?
oleg.feoktistov
Veeam Software
Posts: 1912
Liked: 635 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Want to capture running jobs by "session type" i.e SOBR-Tiering

Post by oleg.feoktistov »

You can just create empty array and push there every oib found in scope of the second foreach loop:

Code: Select all

$allOibs = @()
foreach ($storage in $allStorages) {
  $oib = $storage.GetOibs()
  $allOibs += $oib
}
Then you can choose the restore point you need from $allOibs array. The object you choose will already be in the accepted type for Start-VBRRestoreVM.

Thanks!
efd121
Enthusiast
Posts: 46
Liked: 2 times
Joined: Aug 07, 2015 8:45 pm
Full Name: David Engler
Contact:

Re: Want to capture running jobs by "session type" i.e SOBR-Tiering

Post by efd121 »

I was able to start a restore and I will let you know when I can confirm its pulling the data from offsite.

I want to temporarily disconnect my onprem servers to be sure but wont be able to do that until later this week or next

Dave
efd121
Enthusiast
Posts: 46
Liked: 2 times
Joined: Aug 07, 2015 8:45 pm
Full Name: David Engler
Contact:

Re: Want to capture running jobs by "session type" i.e SOBR-Tiering

Post by efd121 »

I was able to get some time today to try a restore from the AWS immutable bucket. When I run the code below it starts a restore but the data is being pulled from the local repo vs the AWS bucket.
Do I need to disconnect/power off the local repos or is there something else i can do to force the restore to come from the offsite bucket?

Code: Select all

$repo = Get-VBRBackupRepository -Name 'SOBR01' -ScaleOut
$backup = Get-VBRBackup -Name 'Job01'
$objects = $backup.GetObjectIds()
$allStorages = @()
foreach ($object in $objects) {
  $storages = $backup.GetStoragesInCapacityTier($object, $repo.CapacityExtent.Id)
  $allStorages += $storages
}

#foreach ($storage in $allStorages) {
#  $storage.GetOibs()
#}

$allOibs = @()
foreach ($storage in $allStorages) {
  $oib = $storage.GetOibs()
  $allOibs += $oib
}

$rps = $allOibs | Sort-Object -Property CreationTime -Descending
$RestoreFolder = 'vDR'
$RestorePool = 'DR-Pool'
$restoreSvr = Get-VBRServer -Name 'host01'
$folder = Find-VBRViFolder -Server $restoreSvr -Name $restoreFolder
$rsPool = Find-VBRViResourcePool -Server $restoreSvr -Name $restorePool
$restoreDS = Find-VBRViDatastore -Server $restoreSvr -Name 'DR_10'
Start-VBRRestoreVM –RestorePoint $rps[0] –Server $restoreSvr -ResourcePool $rsPool –Datastore $restoreDS -Folder $folder -VMName 'server_restore' -DiskType Thick -RunAsync –PowerUp $false -SkipTagsRestore
oleg.feoktistov
Veeam Software
Posts: 1912
Liked: 635 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Want to capture running jobs by "session type" i.e SOBR-Tiering

Post by oleg.feoktistov »

Yes, looks like in case with Powershell VBR still takes relevant points from local repo if they are available. Please try to put performance extents into maintenance mode and invoke restore from the same point. Restore session should then throw the warning that performance tier is not available and force restore from your AWS bucket. Thanks!
efd121
Enthusiast
Posts: 46
Liked: 2 times
Joined: Aug 07, 2015 8:45 pm
Full Name: David Engler
Contact:

Re: Want to capture running jobs by "session type" i.e SOBR-Tiering

Post by efd121 »

Putting the performance tiers into maintenance mode has force the restore to be pulled from the offsite AWS bucket but my main VBR server is the one reading the data. Are there any options to prevent this?
As expected I'm getting the warning that the files are not found on the performance tier

All Proxies except the ones in the remote Data Center are disabled.
All Backup repos are in maintenance mode in the primary Data Center
oleg.feoktistov
Veeam Software
Posts: 1912
Liked: 635 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Want to capture running jobs by "session type" i.e SOBR-Tiering

Post by oleg.feoktistov »

Hi David,

Sorry, looks like after vacation I missed your message in this topic.
Yes, you could use gateway server for object storage repository you have on capacity tier.
Check this guide for more infomation. Also make sure that the server chosen is not the one where VBR is installed.

Best regards,
Oleg
Albert-NL
Novice
Posts: 4
Liked: never
Joined: Oct 07, 2020 12:25 pm
Full Name: Albert Hols
Contact:

Re: Want to capture running jobs by "session type" i.e SOBR-Tiering

Post by Albert-NL »

Could it be that the below script/method is no longer working in V12?
Getting errors like:
Exception calling "GetByTypeAndTimeInterval" with "3" argument(s): "Object reference not set to an instance of an object." You cannot call a method on a null-valued expression.
I know it's not supported but is there a supported way to retrieve SOBR job details via Powershell?

tdewin wrote: Nov 18, 2021 12:59 pm @oleg.feoktistov and I had an internal chat for a customer that just wanted to see the last 24h. Turns out there is an UNSUPPORTED way of doing this. It seems so useful that we decided to share it here

Code: Select all

$now = get-date
$offsetfilter = $now.AddDays(-1)
$jts = @([Veeam.Backup.Model.EDbJobType]::ArchiveBackup,[Veeam.Backup.Model.EDbJobType]::ArchiveFreezing)
$sessions = [Veeam.Backup.DBManager.CDBManager]::Instance.JobsSessions.GetSessionsByTypeAndInterval($jts, $offsetfilter,$now) | sort-object -property CreationTime
foreach ($session in $sessions) {
 $fullsessions = [Veeam.Backup.Core.CBackupSession]::GetByOriginalSessionId($session.OriginalSessionId)
 foreach ($fullsession in $fullsessions) {
	write-host "====================="
	write-host $fullsession.CreationTime
	write-host $fullsession.Result
 	write-host $fullsession.State  
        foreach ($task in $fullsession.GetTaskSessions()) { 
          write-host "-- sub"
          write-host $task.Name
	  write-host $task.Status
          foreach ($logline in ($task.Logger.GetLog().UpdatedRecords)) {
            if ($logline.title -match "(vbk|vib)") {
               write-host $logline.title
            }
          }
        }
 }
}
tdewin
Veeam Software
Posts: 1775
Liked: 646 times
Joined: Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin
Contact:

Re: Want to capture running jobs by "session type" i.e SOBR-Tiering

Post by tdewin » 1 person likes this post

I just tried it on v12 and it still works. My guess is that one of your parameters that you are passing is empty. Make sure $now, $offsetfilter and $jts are not empty
Albert-NL
Novice
Posts: 4
Liked: never
Joined: Oct 07, 2020 12:25 pm
Full Name: Albert Hols
Contact:

Re: Want to capture running jobs by "session type" i.e SOBR-Tiering

Post by Albert-NL »

Thanks for testing and letting me know, will double check if there is something wrong in 'my' script.
sykerzner
Service Provider
Posts: 31
Liked: 2 times
Joined: Jul 27, 2020 1:16 pm
Full Name: SYK
Contact:

Re: Want to capture running jobs by "session type" i.e SOBR-Tiering

Post by sykerzner »

Hi Albert-NL and tdewin

I had the same error with V12 and a similar version of the same script.

After some luck and fiddling, I found out that I can it to work if I add this command into the script in line 4

Get-VBRSession -type $jts
(if you don't want any output from that, pipe it to "| out-null" )

Code: Select all

$now = get-date
$offsetfilter = $now.AddDays(-1)
$jts = @([Veeam.Backup.Model.EDbJobType]::ArchiveBackup,[Veeam.Backup.Model.EDbJobType]::ArchiveFreezing)
Get-VBRSession -type $jts | out-null
$sessions = [Veeam.Backup.DBManager.CDBManager]::Instance.JobsSessions.GetSessionsByTypeAndInterval($jts, $offsetfilter,$now) | sort-object -property CreationTime
foreach ($session in $sessions) {
 $fullsessions = [Veeam.Backup.Core.CBackupSession]::GetByOriginalSessionId($session.OriginalSessionId)
 foreach ($fullsession in $fullsessions) {
	write-host "====================="
	write-host $fullsession.CreationTime
	write-host $fullsession.Result
 	write-host $fullsession.State  
        foreach ($task in $fullsession.GetTaskSessions()) { 
          write-host "-- sub"
          write-host $task.Name
	  write-host $task.Status
          foreach ($logline in ($task.Logger.GetLog().UpdatedRecords)) {
            if ($logline.title -match "(vbk|vib)") {
               write-host $logline.title
            }
          }
        }
 }
}
I have no idea why this should work. It's not like I am DOING anything with the Get-VBRsession command output. But I don't know enough about ,net objects and powershell. Kind of feels like a bug.

(not sure what to expect with an unsupported way of doing things)

Any geniuses have a good bet?
david.domask
VeeaMVP
Posts: 1034
Liked: 278 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Want to capture running jobs by "session type" i.e SOBR-Tiering

Post by david.domask » 1 person likes this post

@sykerzner

Is that your full script?

If so, likely the running of the cmdlet "hot loads" the necessary DLLs for the .NET reflection to work.

Can you comment out line 4 and add as the first line

Get-VBRLicenseAutoUpdateStatus | Out-Null

And try the script?

Basically, the .NET Reflection looks to fail for many of the reflections until a normal cmdlet is run. I'm not sure on the specifics of this, but my guess is that the underlying items are lazy-loaded to speed up the Module loading. But this is just a guess.

My suggestion here more or less does the same as what your line 4 does, but it's a faster cmdlet that doesn't need to call so much data as Get-VBRSession.
David Domask | Director: Customer Care | Veeam Technical Support
Albert-NL
Novice
Posts: 4
Liked: never
Joined: Oct 07, 2020 12:25 pm
Full Name: Albert Hols
Contact:

Re: Want to capture running jobs by "session type" i.e SOBR-Tiering

Post by Albert-NL »

Hi David,

Many thanks for this response, it actually confirms my feeling that this looked like a timing issue.
I will test this in our environment next week and let you know the result.

Thanks again.
Albert-NL
Novice
Posts: 4
Liked: never
Joined: Oct 07, 2020 12:25 pm
Full Name: Albert Hols
Contact:

Re: Want to capture running jobs by "session type" i.e SOBR-Tiering

Post by Albert-NL »

Hi David,

It took some time to test your proposed solution for the 'timing' issue but I can confirm everything runs fine after adding the cmdlet :-)
So we are happy now as our SOBR monitoring runs now succesfully again, also on V12.
david.domask
VeeaMVP
Posts: 1034
Liked: 278 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Want to capture running jobs by "session type" i.e SOBR-Tiering

Post by david.domask »

Hi @Albert-NL, I'm really glad to hear it worked :) Enjoy the reporting!
David Domask | Director: Customer Care | Veeam Technical Support
sykerzner
Service Provider
Posts: 31
Liked: 2 times
Joined: Jul 27, 2020 1:16 pm
Full Name: SYK
Contact:

Re: Want to capture running jobs by "session type" i.e SOBR-Tiering

Post by sykerzner »

Hi @david.domask

Thanks for the insight.
I added "Get-VBRLicenseAutoUpdateStatus | Out-Null" instead, but I'm not sure it made much practical difference in the version of the script I'm working with.

Does anyone know how to get a name of the VM being offloaded in the task? The task name itself is an ID (0235b917-d5c4-4156-8a52-419699e7461f), in v11 the JobName would usually have the name of the VM, but now usually shows just "SOBR Offload", which isn't so specific.
Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests