Running SQL jobs

PowerShell script exchange

Running SQL jobs

Veeam Logoby RasmusB » Tue May 02, 2017 8:04 am

from powershell i want to monitor running sql jobs.
From findchildsqllogbackupjob i can get the findlastsession().sessioninfo
But as i see it, it shows failures and warnings on the last session, which is not the running log job?
is there a way to monitor warnings and failures in the current running sql log job ?
RasmusB
Novice
 
Posts: 3
Liked: never
Joined: Tue May 02, 2017 7:54 am
Full Name: Rasmus Bertelsen

Re: Running SQL jobs

Veeam Logoby v.Eremin » Tue May 02, 2017 11:34 am

If you want to catch errors within running SQL log backup job session, you will need to parse task sessions, using code similar to the following:

Code: Select all
Asnp VeeamPSSnapin
$Job = Get-VBRJob -name "Name of backup job"
$LastSession = $job.FindChildSqlLogBackupJob().FindLastSession()
$LastSession.GetTaskSessions().logger.getlog().UpdatedRecords | where {$_.Status -eq "EFailed"} |  sort starttime | select starttime, title


Thanks.
v.Eremin
Veeam Software
 
Posts: 13563
Liked: 1007 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Running SQL jobs

Veeam Logoby RasmusB » Wed May 03, 2017 8:35 am

It's not working as intended.

I have a SQL job with a error, which im able to read out.
But i have another job with a warning, and it just shows ENone or ESucceeded - so something isn't working.
RasmusB
Novice
 
Posts: 3
Liked: never
Joined: Tue May 02, 2017 7:54 am
Full Name: Rasmus Bertelsen

Re: Running SQL jobs

Veeam Logoby v.Eremin » Thu May 04, 2017 12:14 pm

Can you elaborate on what you're trying to achieve?

Based on the description provided:

- There is a running SQL Transaction log backup job
- There are different errors and warnings in current task session statistics window
- The SQL Transaction log backup job doesn't have a final result, as it's still running
- Therefore, you want to catch errors and warning from task sessions statistics window

Right?
v.Eremin
Veeam Software
 
Posts: 13563
Liked: 1007 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Running SQL jobs

Veeam Logoby RasmusB » Mon May 08, 2017 11:26 am

Yes 100% correct :)
RasmusB
Novice
 
Posts: 3
Liked: never
Joined: Tue May 02, 2017 7:54 am
Full Name: Rasmus Bertelsen

Re: Running SQL jobs

Veeam Logoby v.Eremin » Mon May 08, 2017 1:53 pm

Then, you should leverage the script provided above and modify code slightly in case it does not meet your requirements.

This is what script does:

- Takes the latest SQL transaction log backup session
- Parses its task sessions to find entities having Failed state
- Outputs those sessions titles along with creation times

If you think that some session get output wrongly, remove "where" and "select" code sections, get a list of all sessions and see what filter you can use to meet your requirements.

Thanks.
v.Eremin
Veeam Software
 
Posts: 13563
Liked: 1007 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin


Return to PowerShell



Who is online

Users browsing this forum: Google [Bot] and 5 guests