PowerShell script exchange
Post Reply
JeroenConfirmed
Novice
Posts: 4
Liked: never
Joined: Feb 25, 2025 8:10 am
Contact:

Get running Offload jobs for X number of days and terminate them

Post by JeroenConfirmed »

Some time ago we had issues with Cloudconnect Offloading jobs which kept piling up. We had to manually kill them trough the task manager, but there is no indication which job is what.

I was thinking of putting a script together to automate this, should this come back in the future.
I have found some usable snippets of code from following forum posts:
powershell-f26/how-to-manage-jobs-in-th ... 86341.html
powershell-f26/sobr-azure-offload-statu ... 65880.html

I currently have this incomplete non working code:

Code: Select all

#Connect to VBR
Connect-VBRServer

#Define SOBR offload job  = Archivebackup
$sobrOffload = [Veeam.Backup.Model.EDbJobType]::ArchiveBackup
#Get running SOBR offload jobs
$runningSessionsArchiveBackup = [Veeam.Backup.Core.CBaseSession]::GetRunning($sobrOffload)
#write $runningSessionsArchiveBackup

$runningSessionsArchiveBackupOlderThan7days= [Veeam.Backup.Core.CBackupSession]::GetByTypeAndTimeInterval($runningSessionsArchiveBackup,(Get-Date).adddays(-7), (Get-Date).adddays(1)) 
write $runningSessionsArchiveBackupOlderThan7days
It seems you cannot mix EDBJobType and GetByTypeAndTimeInterval according to the error:
Cannot convert argument "jobType", with value: "Veeam.Backup.Model.CBaseSessionInfo[]", for "GetByTypeAndTimeInterval" to type "Veeam.Backup.Model.EDbJobT
ype": "Cannot convert the "Veeam.Backup.Model.CBaseSessionInfo" value of type "Veeam.Backup.Model.CBaseSessionInfo" to type "Veeam.Backup.Model.EDbJobType
"."


The goal here is to get the running SOBR Offload jobs, for example 7 days, and terminate the ones older than a given time.

If anyone can aid me in this, I would be very grateful
david.domask
Veeam Software
Posts: 2731
Liked: 629 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Get running Offload jobs for X number of days and terminate them

Post by david.domask »

Hi JeroenConfirmed, welcome to the forums.

The above code is using unsupported methods, so not sure it's worth diving too deeply into the code -- the issue looks to be that GetByTypeAndTimeInterval() expects a job type but you pass a CBaseSession object. Should work to just replace $runningSessionsArchiveBackup with $sobrOffload when you populate $runningSessionsArchiveBackupOlderThan7days.

However, for a supported way of doing this, use Get-VBRSession with the -Type Parameter -- check the cmdlet documentation with Get-Help to see the valid values for Type, but you want the Archive* job types. ArchiveBackup is move to Capacity Tier, ArchiveCopy for copy to Capacity Tier, etc.
David Domask | Product Management: Principal Analyst
JeroenConfirmed
Novice
Posts: 4
Liked: never
Joined: Feb 25, 2025 8:10 am
Contact:

Re: Get running Offload jobs for X number of days and terminate them

Post by JeroenConfirmed »

Hello David,

I shall have a look at the official VBR Cmdlets and get back to this post when I have something. Thank you for the guidance.

Jeroen
JeroenConfirmed
Novice
Posts: 4
Liked: never
Joined: Feb 25, 2025 8:10 am
Contact:

Re: Get running Offload jobs for X number of days and terminate them

Post by JeroenConfirmed »

Hello David,

I have tried the Get-VBRSession cmdlet.
If I run the following cmdlet it returns the entire history of the offload jobs, which I don't need.

Code: Select all

Get-VBRSession -type ArchiveBackup
When I want to get the running jobs I need to define the name of the job according to the cmdlet explanation :

Code: Select all

Get-VBRSession [b]-Job <VBRJob> [-State [/b]{Stopped | Starting | Stopping | [b]Working [/b]| Pausing | Resuming | WaitingTape | Idle | Postprocessing | WaitingRepository | Pendin
    g | WaitingSlot | ActionRequired}] [<CommonParameters>]
The name of the offload jobs we have is "SOBR Offload" or "SOBR01 Offload".
Image
When using this cmdlet I get the following:

-----------
PS C:\Users\admin> get-vbrsession -job "SOBR01 Offload" -state working
Get-VBRSession : Cannot bind parameter 'Job'. Cannot convert the "SOBR01 Offload" value of type "System.String" to type "Veeam.Backup.PowerShell.Infos.VBRJob".
At line:1 char:21
+ get-vbrsession -job "SOBR01 Offload" -state working
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-VBRSession], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Veeam.Backup.PowerShell.Cmdlets.GetVBRSession

PS C:\Users\admin>
PS C:\Users\admin> Get-VBRSession -job "SOBR01 Offload"
Get-VBRSession : Cannot bind parameter 'Job'. Cannot convert the "SOBR01 Offload" value of type "System.String" to type "Veeam.Backup.PowerShell.Infos.VBRJob".
At line:1 char:21
+ Get-VBRSession -job "SOBR01 Offload"
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-VBRSession], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Veeam.Backup.PowerShell.Cmdlets.GetVBRSession

------------

If I try to retrieve the name using get-vbrjob as seen in the docs I get the following
https://helpcenter.veeam.com/docs/backu ... ml?ver=120

----------
PS C:\Windows\system32> $job = Get-VBRJob -Name "SOBR Offload"
$session = Get-VBRSession -Job $job
Get-VBRSession : Cannot validate argument on parameter 'Job'. The argument is null. Provide a valid value for the argument, and then try running the command again
.
At line:2 char:32
+ $session = Get-VBRSession -Job $job
+ ~~~~
+ CategoryInfo : InvalidData: (:) [Get-VBRSession], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Cmdlets.GetVBRSession

------------------

So am I doing something wrong with the job name retrieval here or Is there another way to get the -state parameter without defining a job name?
david.domask
Veeam Software
Posts: 2731
Liked: 629 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Get running Offload jobs for X number of days and terminate them

Post by david.domask »

Hi JeroenConfirmed,

> So am I doing something wrong with the job name retrieval here or Is there another way to get the -state parameter without defining a job name?

A little bit yes :)

Use the -Type parameter, not the -Job parameter. -Job parameter requires a CJob object from Get-VBRJob (and the other Get-VBR*Job cmdlets), but the Offload Job is a bit different in that it's not a user-manageable job. So you would use the -Type parameter with Archive, ArchiveBackup, ArchiveCopy, etc.

As noted, you can check all options for the parameter with Get-Help Get-VBRSession and check the output (copy it to a text file), then you can see the results of the different Archive* types passed to -Type parameter.
David Domask | Product Management: Principal Analyst
JeroenConfirmed
Novice
Posts: 4
Liked: never
Joined: Feb 25, 2025 8:10 am
Contact:

Re: Get running Offload jobs for X number of days and terminate them

Post by JeroenConfirmed »

Hello David,

I believe you misunderstood. What I was trying to make clear was that "Get-VBRsessions -type ArchiveBackup" is definitely the cmdlet I need, but I cannot specific what the state is. There is no "-state" syntax under "-Session". So while I can specify the offload jobs in general with it's entiry history, I cannot say 'show me the offload jobs which are running right now".

kind regards,

Jeroen
david.domask
Veeam Software
Posts: 2731
Liked: 629 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Get running Offload jobs for X number of days and terminate them

Post by david.domask »

Hi JeromeConfirmed,

Indeed, I did miss that you were trying to use the -State parameter; as noted in the User Guide examples, -State works with the -Job parameter and there are parameter bindings to enforce this.

However, if you check the object(s) returned by the cmdlet without the state, you can see the State property there, so simply filter the output on state:

Get-VBRSession -Type ArchiveBackup | Where-Object {$_.State -ne "Stopped" -or $_.State -ne "Stopping"}
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests