PowerShell script exchange
Post Reply
Zedification
Enthusiast
Posts: 60
Liked: 6 times
Joined: Jul 29, 2010 8:34 am
Full Name: Zed
Contact:

Monitor Backup Copy job

Post by Zedification »

Hello,

I searching for a script sample to monitor the continuous backup copy job status.
I want to report the succes, warning or failed status. I am not very aware about scripting so be cool with me. :D

Thanks.

Zed!
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Monitor Backup Copy job

Post by veremin »

Hi, Zed, using the following script you can the latest state of backup copy:

Code: Select all

asnp VeeamPSSNapin
$Job = Get-VBRJob -name "Name of backup copy Job"
$LastSession = $Job.FindLastSession()
$LastSession.State
Thanks.
Zedification
Enthusiast
Posts: 60
Liked: 6 times
Joined: Jul 29, 2010 8:34 am
Full Name: Zed
Contact:

Re: Monitor Backup Copy job

Post by Zedification »

Thanks.
I will try that and keep you aware.

Zed!
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Monitor Backup Copy job

Post by veremin »

Be aware that the script provided is one time procedure, if you want to make it report on continuous basis, you will have to create a cycle. Thanks.
toon.v10
Novice
Posts: 6
Liked: 3 times
Joined: Oct 12, 2013 4:10 am
Full Name: Toon Vandendriessche
Contact:

Re: Monitor Backup Copy job

Post by toon.v10 »

Hi,

With the FindLastSession() method it shows the state of the current running copy job. Since it's a continous job it's state is idle and Last Result value is None.
What i want to know is if the latest finished copy job was successfull.
I can do that now by getting all the sessions, sort by date and then select the second one, but it's cumbersome.
I think it would be better to change the method FindLastSession so that it displays the information of the latest finished session, not the currently running (idle state) session, or is there another way to achieve this?
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Monitor Backup Copy job

Post by veremin » 1 person likes this post

I think it would be better to change the method FindLastSession so that it displays the information of the latest finished session, not the currently running (idle state) session, or is there another way to achieve this?
This is by design. The FindLastSession method returns the latest session, not the last finished one.

The approach described by you (second session, etc.) should do the trick:

Code: Select all

$Session = Get-VBRBackupSession | ? {$_.jobname -eq $Job.Name} | sort {$_.CreationTime} -Descending | select -first 2 | select -Last 1
$Session.Result
Thanks.
Elemer.gazda
Influencer
Posts: 17
Liked: 4 times
Joined: Feb 14, 2018 12:01 pm
Full Name: Elemer Gazda
Contact:

Re: Monitor Backup Copy job

Post by Elemer.gazda »

I am doing exactly as described above (Selecting 2nd last job to get the status of the Backup Copy job status).
However I want to fine tune this a bit.
Sometimes the Backup Copy interval can be quite long (7 days or 1 month), and because of this I want to achieve the folloiwing with powershell:
If the Endtime of the last backupCopy session is not 1/1/1900 than look at the results of the individual items (VMs) in the Backup Copy job and see if they are all successfull or not.
I haven't find the command to list the statuses of the VMs in the last BackupCopy session
This is what I have so far:

Code: Select all

$Sessions = Get-VBRBackupSession
$BackupCopySessionsLast = $Sessions | Where {$_.Jobtype -eq "BackupSync"} |Group-Object JobId | ForEach-Object {$_.Group | Sort-Object CreationTime -Descending | Select -First 1 }| Select * 

ForEach($Job in $BackupCopyActiveJobs){
	$EndTime = ($BackupCopySessionsLast | Where {$_.JobId -eq $Job.Id}).EndTime
	If($EndTime -ne "01/01/1900"){
		# Command to get the statuses of individual tasks (VMs) in the backup Copy Job
	}
}
Any ideas?
P.S. $BackupCopyActiveJobs is acchieved by filtering down Backup Copy jobs which are not disabled.
Vek17
Service Provider
Posts: 49
Liked: 15 times
Joined: May 29, 2018 8:42 pm
Contact:

Re: Monitor Backup Copy job

Post by Vek17 »

You want to look into task sessions which will give you per VM task information.

Code: Select all

$Sessions = Get-VBRBackupSession
$BackupCopySessionsLast = $Sessions | Where {$_.Jobtype -eq "BackupSync"} |Group-Object JobId | ForEach-Object {$_.Group | Sort-Object CreationTime -Descending | Select -First 1 }| Select * 

ForEach($Job in $BackupCopyActiveJobs){
	$EndTime = ($BackupCopySessionsLast | Where {$_.JobId -eq $Job.Id}).EndTime
	If($EndTime -ne "01/01/1900"){
		foreach($Task in $Job.GetTaskSessions()){
                      #Do Per VM Stuff
                }
	}
}
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Monitor Backup Copy job

Post by veremin » 1 person likes this post

This script returns names of VMs that have been successfully processed within the latest job session. You can incorporate this example in your code:

Code: Select all

Asnp VeeamPSSnapin
$Job = Get-VBRJob -name "Name of your backup copy job"
$Session = $Job.FindLastSession()
$Session.GetTaskSessions() | where {$_.Status -eq "Success"} | select Name
Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests