Skip to main content

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

 

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


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


@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


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


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!


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