PowerShell script exchange
Post Reply
Etilimos
Influencer
Posts: 16
Liked: never
Joined: Feb 16, 2022 3:17 pm
Contact:

Veeam Report Backup Copy

Post by Etilimos »

Hello,

I have 2 VBR servers on which run backups and copy backup every day. I have a script that runs to retrieve the status of backup jobs each morning and sends me a summary by email. However I would like to create a new script which will also be able to give me the status of the backup copy each morning.

I don't know how to do it, can someone help me on this?
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Veeam Report Backup Copy

Post by oleg.feoktistov »

Hi,

Can you, please, elaborate which backup copy jobs are you talking about? Are they of vi/hv or agent type?

Thanks,
Oleg
Etilimos
Influencer
Posts: 16
Liked: never
Joined: Feb 16, 2022 3:17 pm
Contact:

Re: Veeam Report Backup Copy

Post by Etilimos »

Hi,

This is a backup copy of a VM to an external bay.
Etilimos
Influencer
Posts: 16
Liked: never
Joined: Feb 16, 2022 3:17 pm
Contact:

Re: Veeam Report Backup Copy

Post by Etilimos »

I need to get the backup copy report (they are in prunning mode).

Image

I tried the command :

Code: Select all

VBR-GetJOB - Name * 
but the value : LastResult is : none while on the VBR console the value is success
Image
Image
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Veeam Report Backup Copy

Post by oleg.feoktistov »

Hi,

Thanks for the details info.

There are several approaches to getting last result from a job:

- From CBackupJob.Info.LatestStatus property, but cannot guarantee it is going to work all the time in the future:

Code: Select all

$job = Get-VBRJob -Name 'Backup Copy Job 1'
$job.Info.LatestStatus
- From actual session object using sorting:

Code: Select all

$job = Get-VBrJob -Name 'Backup Copy Job 1'
$sessions = Get-VBRBackupSession -Name "$($job.Name)*"
$sessions | sort -Property EndTime | select -First 1
Hope it helps,
Oleg
Etilimos
Influencer
Posts: 16
Liked: never
Joined: Feb 16, 2022 3:17 pm
Contact:

Re: Veeam Report Backup Copy

Post by Etilimos »

Hi,

Thank you for your time, I have tested both commands but each time I have no values that come up. I forgot to mention that I am still in version 10.0.1.4854 and I have to migrate to V11 next Tuesday.

Image
Image
david.domask
Veeam Software
Posts: 2123
Liked: 513 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Veeam Report Backup Copy

Post by david.domask » 1 person likes this post

Etilimos,

You were a bit too literal in copying Oleg ;) He made a small typo LatestStatud vs LatestStatus. (I do this all the time...)

It should work in v10 but in v11 I can confirm Oleg's stuff works:

Code: Select all

PS C:\Users\Administrator> $job = Get-VBRJob -name 'classic-bcj'
PS C:\Users\Administrator> $job.info.LatestStatus
Failed
PS C:\Users\Administrator> $sess = Get-VBRBackupSession -Name $($Job.Name) | Sort -Property EndTime -Descending | Select -First 1
PS C:\Users\Administrator> $sess

Job Name             State      Start Time             End Time               Result
--------             -----      ----------             --------               ------
classic-bcj          Stopped    1/14/2022 13:19:57     1/14/2022 13:21:08     Failed
A small hint, use auto-complete (tab) to save typing and avoid PEBKAC errors. The shell will load the properties for objects if you type a few of the characters just to save you some time.

You can see here in my lab how suddenly it jumps and auto-completes: https://imgur.com/G93ww6Z

It saves a lot of of typing. Use the shell to your advantage!

As for your second command, you cannot do the wildcard like that and pipe it out as it's not clear what you actually captured. If $job returned an array of jobs (very likely), you'll need to iterate over all items in the array, you won't be able to use Get-VBRBackupSession on it.

So it will be a simple loop like:

Code: Select all

ForEach($j in $jobs){
     $sess = Get-VBRBackupSeession -Name $($j.Name) | Sort -Property EndTime -Descending | Select -First 1
     $sess
}
But this might not work as written, it's just an example. You need to see what your input from the Get-VBRJob actually returned.
David Domask | Product Management: Principal Analyst
Etilimos
Influencer
Posts: 16
Liked: never
Joined: Feb 16, 2022 3:17 pm
Contact:

Re: Veeam Report Backup Copy

Post by Etilimos »

Hi,

Thanks a lot David, i use normaly auto-complete on classic powershell but in the Veeam Console Powershell auto-complete doesn't work (i don't know why).
david.domask
Veeam Software
Posts: 2123
Liked: 513 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Veeam Report Backup Copy

Post by david.domask »

> Veeam Console Powershell auto-complete doesn't work (i don't know why).

It's just Powershell :) There's no difference.

As I looked at your screenshot, I have a guess why it didn't work; you actually had an array of jobs instead of a single job, so the shell had ambiguity as to what it should return. So it would return properties/methods common to the array, but it wouldn't load Properties on individual objects in the array, so that's likely what's going on.

Check your $job variable and see what actually is outputted; I strongly suspect either it's empty or it has multiple objects.
David Domask | Product Management: Principal Analyst
Etilimos
Influencer
Posts: 16
Liked: never
Joined: Feb 16, 2022 3:17 pm
Contact:

Re: Veeam Report Backup Copy

Post by Etilimos »

Hi,

My rapport is now OK thank you so much !!
I would like to add as information the backup time and if there is an error what is the error message.
I can't find the value to query for these two points.

Can you help me please ? :)
david.domask
Veeam Software
Posts: 2123
Liked: 513 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Veeam Report Backup Copy

Post by david.domask »

Hi Etilimos!

Glad you got it working.

The properties you want are on the job session, and you can find it with these properties:

CreationTime
CreationTimeUTC
EndTime
EndTimeUTC

As for the error, it's a little trickier as the _job_ might fail, or individual tasks might fail.

The GetDetails() method on the job session object will tell you the job failure message.

To check Task Session Failures, pass the $sess.id to Get-VBRTaskSession and you can check similar properties there. Give it a shot and let me know if you have challenges.
David Domask | Product Management: Principal Analyst
Etilimos
Influencer
Posts: 16
Liked: never
Joined: Feb 16, 2022 3:17 pm
Contact:

Re: Veeam Report Backup Copy

Post by Etilimos »

Thanks for your reponse :)

I tried properties CreationTime but i've got no result

Image
david.domask
Veeam Software
Posts: 2123
Liked: 513 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Veeam Report Backup Copy

Post by david.domask »

Because it's a CBackupCopySession object property, not a CBackupJob object property ;)

Make a Session Variable like you did above for the most recent session, and then try.
David Domask | Product Management: Principal Analyst
Etilimos
Influencer
Posts: 16
Liked: never
Joined: Feb 16, 2022 3:17 pm
Contact:

Re: Veeam Report Backup Copy

Post by Etilimos »

Sorry but I didn't understand... :(
david.domask
Veeam Software
Posts: 2123
Liked: 513 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Veeam Report Backup Copy

Post by david.domask »

Use this to get a session:
$job = Get-VBRjob -name "name of the job" #btw, don't use wild cards here, it's just confusing you. When you use wildcards, you might get multiple jobs returned. Pick a specific job as an example
$sess = Get-VBRBackupSeession -Name $($job.Name) | Sort -Property EndTime -Descending | Select -First 1

Then try checking $sess.CreationTime
David Domask | Product Management: Principal Analyst
Etilimos
Influencer
Posts: 16
Liked: never
Joined: Feb 16, 2022 3:17 pm
Contact:

Re: Veeam Report Backup Copy

Post by Etilimos »

I will see with what you told me I would also like to get the copy job with the state in working
Image

I tried :

Code: Select all

$JobsRunning = Get-VBRJob -Name '*COPY JOB*' | Where-Object {$_.State -eq "Working"}
but it doesn't work :(
Etilimos
Influencer
Posts: 16
Liked: never
Joined: Feb 16, 2022 3:17 pm
Contact:

Re: Veeam Report Backup Copy

Post by Etilimos »

Does anyone have an idea?
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Veeam Report Backup Copy

Post by oleg.feoktistov »

Hi,

It doesn't work because that's just powershell view, CBackupJob class has no State property. To get job last state you need to query latest session. The shortest way to do it would be leveraging an unsupported .NET method:

Code: Select all

$JobsRunning = Get-VBRJob -Name '*COPY JOB*' | Where-Object {$_.GetLastState() -eq "Working"}
The supported way to obtain it would be:

Code: Select all

$jobs = Get-VBRJob -Name '*COPY JOB*'
$sessions = Get-VBRBackupSession | sort -Property CreationTime
$lastSessions = @()
foreach ($job in $jobs) {
  $lastSession = $sessions | where {$_.JobName -eq $job.Name} | select -Last 1
  $lastSessions += $lastSession

}

$lastSessions | where {$_.State -eq 'Idle'}
Hope it helps,
Oleg
Etilimos
Influencer
Posts: 16
Liked: never
Joined: Feb 16, 2022 3:17 pm
Contact:

Re: Veeam Report Backup Copy

Post by Etilimos »

Hello,

I would like to improve my script because it currently shows me the LastResult value in the VBR console but it is not necessarily the real value.
I explain myself, it happens that when a first copyjob arrives in error and that this one carries out a retry in success the LastResult value keeps the value "failed" until the next copyjob.
Image
Image

Do you know how to recover the value in the second capture?
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Veeam Report Backup Copy

Post by oleg.feoktistov »

Hi,

In this case you need to get task session status. For agent backup copy job (I am assuming you have periodic mode) the approach would be:

Code: Select all

$job = Get-VBRComputerBackupCopyJob -Name 'Backup Copy Job'
$lastSession = Get-VBRBackupSession | where {$_.JobId -eq $job.Id} | sort -Property EndTime | select -Last 1
$taskSessions = Get-VBRTaskSession -Session $lastSession
$taskSessions
Thanks,
Oleg
Etilimos
Influencer
Posts: 16
Liked: never
Joined: Feb 16, 2022 3:17 pm
Contact:

Re: Veeam Report Backup Copy

Post by Etilimos »

Hello Oleg,

Thanks a lot for your help, indeed it works when I replace

Code: Select all

$job = Get-VBRComputerBackupCopyJob -Name 'Backup Copy Job
With the name of one of my copyjob example :

Code: Select all

$job = Get-VBRComputerBackupCopyJob -Name 'CAP_LYON - FOS08 - COPY JOB DCE'
However when I try to do it for all my copyjobs, namely :

Code: Select all

$job = Get-VBRComputerBackupCopyJob -Name '*COPY JOB*'
I get the following error:

Code: Select all

Get-VBRComputerBackupCopyJob: The given key was not present in the dictionary.
At line:1 char:8
+ $job = Get-VBRComputerBackupCopyJob -Name '*COPY JOB*'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Get-VBRComputerBackupCopyJob], KeyNotFoundException
    + FullyQualifiedErrorId : System.Collections.Generic.KeyNotFoundException,Veeam.Backup.PowerShell.Cmdlets.GetVBRComputerBackupCopyJob
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Veeam Report Backup Copy

Post by oleg.feoktistov »

Does it happen every time you use wildcard when filtering jobs with Get-VBRComputerBackupCopyJob?
Did you try to reload our powershell module and reconnect to VBR console? Thanks!
Etilimos
Influencer
Posts: 16
Liked: never
Joined: Feb 16, 2022 3:17 pm
Contact:

Re: Veeam Report Backup Copy

Post by Etilimos »

Yes, it does that to me every time. I have restarted the server but the problem persists :(
Etilimos
Influencer
Posts: 16
Liked: never
Joined: Feb 16, 2022 3:17 pm
Contact:

Re: Veeam Report Backup Copy

Post by Etilimos »

I realize now that even if I specify only one copyjob the error message is the same

Code: Select all

PS C:\Users\PG5459-C> $job = Get-VBRComputerBackupCopyJob -Name 'CAP_TOULOUSE - LIEUSAINT03 - COPY JOB DCQ'
Get-VBRComputerBackupCopyJob : The given key was not present in the dictionary.
At line:1 char:8
+ $job = Get-VBRComputerBackupCopyJob -Name 'CAP_TOULOUSE - LIEUSAINT03 ...
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-VBRComputerBackupCopyJob], KeyNotFoundException
    + FullyQualifiedErrorId : System.Collections.Generic.KeyNotFoundException,Veeam.Backup.PowerShell.Cmdlets.GetVBRCo
   mputerBackupCopyJob
david.domask
Veeam Software
Posts: 2123
Liked: 513 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Veeam Report Backup Copy

Post by david.domask »

Hey @Etilimos,

Looks like a technical issue -- can you please reproduce the issue and:

1. Note the time of the test and the job in question
2. Run the test from the VBR server itself (open the console from Menu > Console > Powershell)
3. Note the user used for the test
4. Make a manual backup of the Veeam Configuration Database: https://www.veeam.com/kb1471
5. Export logs for the VBR server itself: https://veeam.com/kb1832, use the 3rd radio option "Export all logs for selected components" and select the Veeam server

Open the case and include the above information and upload the DB and logs; we'll need to just check what's going on internally.
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests