PowerShell script exchange
Post Reply
sysadmnctu
Novice
Posts: 3
Liked: never
Joined: Oct 26, 2020 11:33 am
Contact:

Getting backup results per day for a particular job

Post by sysadmnctu »

Hi,

I'm quit struggeling finding a script that will give me a csv file with the backup results per day from the last 3 months.
I know that i can generate a HTML file, but i can't really mingle this in an report.

So i'm looking for a clean and simple script that will generate something like this:

Date.........Job.......Result
19/10/2020 Jobname Success
20/10/2020 Jobname Success
21/10/2020 Jobname Success
22/10/2020 Jobname Success
23/10/2020 Jobname Success
26/10/2020 Jobname Success

Though the result may also be failed, or warning.

So far i found this script, but it summarizes the results. But i want it on a day basis,

Thank you so much in advance!

Code: Select all

Add-PSSnapin "VeeamPSSnapIn"
$MonthlySessions = Get-VBRBackupSession | where {$_.creationtime -ge (Get-Date).AddDays(-30)}
$ReviewDate = Get-Date
$Collection = @()
$origfile = "c:\boot.ini"
Foreach ($job in Get-VBRjob){
$Details = New-Object PSObject 

# Puts Job Name in the report
$Details | Add-Member -Name "Veeam Job Name" -MemberType NoteProperty -Value $job.name
# Puts List of Servers in each job into report 
$Details | Add-Member -Name "Servers" -MemberType NoteProperty -Value (($job.GetObjectsInJob() | foreach { $_.Name }) -join "," ) 

# Pulls Monthly Results Failed / Warning / Success
$MonthlyJobSessions = $MonthlySessions | where {$_.origJobname -eq $Job.name}
$FailedJobSessions = $MonthlyJobSessions | where {($_.result -eq "Failed") -and ($_.isretrymode -eq $False)}
$WarningJobSessions = $MonthlyJobSessions | where {($_.result -eq "Warning")}
$SuccessfulJobSessions = $MonthlyJobSessions | where {($_.result -eq "Success")}

# Puts review date in report
$Details | Add-Member -Name "Date of Review" -MemberType NoteProperty -Value $ReviewDate

# Adds Success / Warning / Fail to report
$Details | Add-Member -Name "Number of Successful Sessions" -MemberType NoteProperty -Value $SuccessfulJobSessions.count
$Details | Add-Member -Name "Number of Warning Sessions" -MemberType NoteProperty -Value $WarningJobSessions.count
$Details | Add-Member -Name "Number of Failed Sessions" -MemberType NoteProperty -Value $FailedJobSessions.count

$Collection += $Details
}
$Collection | Export-CSV BackupReview.csv
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Getting backup results per day for a particular job

Post by oleg.feoktistov »

Hi and Welcome to the Veeam Forums!

Try looking into Globa email notification settings.
Should save you some time maintaining the script on daily basis.

Thanks,
Oleg
sysadmnctu
Novice
Posts: 3
Liked: never
Joined: Oct 26, 2020 11:33 am
Contact:

Re: Getting backup results per day for a particular job

Post by sysadmnctu »

Hi Oleg,

We already have the email notification on.

I just have to report on a quarterly basis what the results were of a specific job. So I want to show them what was the result of each job run from July 1 to September 30 in 1 overview, exactly as I gave as an example above
Henrik.Grevelund
Service Provider
Posts: 171
Liked: 26 times
Joined: Feb 13, 2017 2:56 pm
Full Name: Henrik Grevelund
Contact:

Re: Getting backup results per day for a particular job

Post by Henrik.Grevelund » 3 people like this post

Hi there,

this script should be able to do what you want:

Code: Select all


Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue

Write-Host "Disconnect VBR server"
Disconnect-VBRServer | out-null
Write-Host "Connect VBR server"
connect-vbrserver -server localhost



Function GetJobLine($id, $Jobname)
    {
    $JobObjectSessions = $backupSessions | Where-Object {$_.info.jobid.guid -eq $id} | Sort-Object -Property Creationtime
    $jobline = @()
    Foreach ($JobObjectSession in $jobobjectsessions)
        {
        $out_obj = New-Object PSCustomObject
        $out_obj | Add-Member -type NoteProperty -Name 'Date' -Value $JobObjectSession.Creationtime
        $out_obj | Add-Member -type NoteProperty -Name 'Job' -Value $jobname
        $out_obj | Add-Member -type NoteProperty -Name 'Result' -Value $JobObjectSession.Result
        $jobline += $out_obj
        }
    return $jobline
    }

#collect job data from Veeam for the last 700 days
$starttime = (Get-Date '18:00').AddDays(-700)
Write-Host "Getting Backup Sessions"
$backupSessions = Get-VBRBackupSession| Where-Object {$_.CreationTime -gt $starttime}
#Collect backup jobs incl. NAS backup
Write-Host "Getting Backup Jobs"
$AllBackupjobs = Get-VBRJob | ?{$_.JobType -eq "Backup" -or $_.JobType -eq "NasBackup" }


Write-Host "Start finding data"

$joblines = @()

#For each job
Foreach ($JobObject in $AllBackupjobs)
    {
    $id = $JobObject.Id.Guid
    $Jobname = $JobObject.name
    Write-Host "job name " $Jobname
    $JobLines += GetJobLine $id $Jobname 
    #GetJobLine $id $Jobname 
    }

$joblines
Have nice day,
Henrik
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Getting backup results per day for a particular job

Post by oleg.feoktistov » 1 person likes this post

You can then integrate this custom calendar to Henrik's script to pick the date conveniently. Thanks!
sysadmnctu
Novice
Posts: 3
Liked: never
Joined: Oct 26, 2020 11:33 am
Contact:

Re: Getting backup results per day for a particular job

Post by sysadmnctu »

Fantastic guys! This helps me a 100%!
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests