Get last SQL transaction log session


Userlevel 6
Badge +3

How to get the start and end time of the last SQL log backup session?

I just got this question from one of my customers and it’s not soo easy to get there, so I thought it might be useful to share a basic example. 

You’ll have to get the working task session and read & parse the logs for more details. 

$sql_base_job = "My SQL Server Job"

$j = Get-VBRJob -Name $sql_base_job
$SQLJob = $j.FindChildSqlLogBackupJob()
$session = $SQLJob.FindLastSession()

# Tasksessions will be per machine, I only have one
$taskSession = Get-VBRTaskSession -Session $session
$logBackupLogs = $taskSession.Logger.GetLog().UpdatedRecords

$lastSessionStartLog = $logBackupLogs | ? { $_.Title.Contains("New transaction log backup interval started") } | Select -Last 1
$lastSessionEndLog = $logBackupLogs | ? { $_.Title.Contains("Transaction log backup completed") } | Select -Last 1

# Sanity check (Endtime > Starttime) might be good if a session was started but not yet finished
Write-Output "Last log session start: " $lastSessionStartLog.StartTime

Write-Output "Last log session stop: " $lastSessionEndLog.StartTime

 


6 comments

Userlevel 7
Badge +20

I find these very interesting thanks for sharing.  Seeing PowerShell is always cool. 😎

Userlevel 6
Badge +3

@Kseniya just noticed that there’s no syntax highlighting for PowerShell when adding inline code - maybe this is something that can be added here?!

Userlevel 7
Badge +14

@Kseniya just noticed that there’s no syntax highlighting for PowerShell when adding inline code - maybe this is something that can be added here?!

Ksenia is no longer working for Veeam, tagging @Madi.Cristil

Userlevel 6
Badge +3

Oops, thanks for correcting it .. I wasn’t too active in the community the last time. Shame on me.

Userlevel 7
Badge +7

Hi @StefanZi :) Nice to meet you first of all! Let me know how can I help. If anything you can also write me on Teams!

Userlevel 7
Badge +14

Oops, thanks for correcting it .. I wasn’t too active in the community the last time. Shame on me.

No worries, we started the Automation Desk today, perhaps you are interested in that too?

Comment