PowerShell script exchange
Post Reply
Ant
Novice
Posts: 6
Liked: never
Joined: Dec 07, 2017 10:07 pm
Full Name: Anthony Richardson

Cannot find correct property for backup copy end time

Post by Ant »

I have pretty well got this licked but the property I am using for a backup copy end time is out by a varying amount. Usually only a minute or two compared to the GUI but I want to make sure that I am using an accurate property. If it is just that it is not capturing some clean up time then I am not worried but I don't want to get down the track somewhere and find it is out by a mile. Obviously the correct property would be best if anyone knows which one it is. I am using Get-VBRBackup and $_.findlastintimestorage().actualenddate. I have looked at about a dozen or so forum posts suggesting varying cmdlets but have had no luck with any of them. I am using PS 5.1.14409.1018 on 2012R2 with VBR Build 11.0.0.837 P20210525.

Code: Select all

function vbr-getjobs{
		$BackupList=@()
			$CopyJobs = (Get-VBRBackup | where {$_.JobType -eq 'SimpleBackupCopyWorker'} | sort name)
			$CopyJobs | foreach-object{
				$CopyJob = $_.getjob().name -split '\\'
				[datetime]$Start = (get-date $_.lastpointcreationtime  -format "dddd, dd MMMM yyyy h:mm:ss tt")
				[datetime]$Finish = (get-date $_.findlastintimestorage().actualenddate  -format "dddd, dd MMMM yyyy h:mm:ss tt")
				$repositoryID = $_.repositoryid
				$BackupList += [pscustomobject]@{
					BackupName = $CopyJob[1]
					CopyName = $CopyJob[0]
					Start = $Start
					Finish = $Finish
					IsRunning = $_.GetJob().IsRunning
					RepName = (Get-VBRBackupRepository | where{$_.id -eq $repositoryid}).name
					RepCap_GB = (Get-VBRBackupRepository | where{$_.id -eq $repositoryid}).getcontainer().cachedtotalspace.inGigabytes
					RepFree_GB = (Get-VBRBackupRepository | where{$_.id -eq $repositoryid}).getcontainer().cachedfreespace.inGigabytes
				}
			}
			$BackupJobs = (Get-VBRJob | where {$_.JobType -eq 'Backup'} | sort name)
			$BackupJobs | foreach-object{
				$Session = $_.FindLastSession()
				$Task = $session.GetTaskSessions()
				$repositoryID = $session.getjob().gettargetrepository().id
				[datetime]$Start = (get-date $Task.jobsess.creationtime[0]  -format "dddd, dd MMMM yyyy h:mm:ss tt")
				[datetime]$Finish = (get-date $Task.jobsess.endtime[0]  -format "dddd, dd MMMM yyyy h:mm:ss tt")
				$backupList += [pscustomobject]@{
					BackupName = $_.name
					CopyName = ""
					Start = $Start
					Finish = $Finish
					IsRunning = $_.IsRunning
					RepName = (Get-VBRBackupRepository | where{$_.id -eq $repositoryid}).name
					RepCap_GB = (Get-VBRBackupRepository | where{$_.id -eq $repositoryid}).getcontainer().cachedtotalspace.inGigabytes
					RepFree_GB = (Get-VBRBackupRepository | where{$_.id -eq $repositoryid}).getcontainer().cachedfreespace.inGigabytes
				}
			}
		$BackupList | sort-object -property BackupName, CopyName | ft

}


clear-host
vbr-getjobs

oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Cannot find correct property for backup copy end time

Post by oleg.feoktistov »

Hi Anthony,

Can you tell me please which data in the UI you are trying to correlate the value of ActualEndTime property with? Is it the value you see in Date column when expanding Properties of a Backup and looking at Files window with a list of storages?

Thanks,
Oleg
Ant
Novice
Posts: 6
Liked: never
Joined: Dec 07, 2017 10:07 pm
Full Name: Anthony Richardson

Re: Cannot find correct property for backup copy end time

Post by Ant »

Hi Oleg,
I am using the start and finish times from the Action pane after selecting the backup copy job in 'Jobs', 'Backup Copy' then the copy job. This is without selecting the individual backup job in the lower left below the summary data. If I do the break up of each individual backup job copy still shows the last completed as out by a couple of minutes.
I am not 100% on the terminology, so I don't know if this is what you mean but if I open the copy job in a new window from 'Jobs', 'Backup Copy' and double click on the copy job from the top right pane it shows the same values as the first way I mentioned.
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Cannot find correct property for backup copy end time

Post by oleg.feoktistov »

I duly reviewed your script, checked our .NET classes implementation and, to be honest, still can't figure out what ActualEndTime property in CStorage class stands for. My guess is that's the time when a storage is locked out from further modifications. But this value is nowhere near what you are after, I believe. Now, from what you are describing, you are actually looking for last session's start and end times. It is quite simple to get these for a common job, but for a backup copy job in immediate mode it might get a bit tricky since you need to obtain job workers first:

Code: Select all

$job = Get-VBRJob -Name 'Backup Copy Simple Job'
$workers = $job.GetWorkerJobs()
$session = $workers[0].FindLastSession()
$session | select Name, @{n='StartTime';e={$_.SessionInfo.CreationTime}}, @{n='EndTime';e={$_.SessionInfo.EndTime}}
Let me know if that's what you have been looking for.

Thanks!
Ant
Novice
Posts: 6
Liked: never
Joined: Dec 07, 2017 10:07 pm
Full Name: Anthony Richardson

Re: Cannot find correct property for backup copy end time

Post by Ant »

Thanks Oleg, your $worker[0] property triggered me to realise I was thinking in terms of the copy job instead of each copy job session. For copy jobs where there was only one backup job it worked fine but if there were multiple sources I was not enumerating all of the backup jobs that were copied. Now I have all of the finish times perfectly accurate. Plus using VBR-Job for both makes it faster.

Code: Select all

function vbr-getjobs{
		$BackupList=@()
			$Job = (Get-VBRJob | sort name)
			$Job | foreach-object{
				if($_.JobType -eq 'SimpleBackupCopyPolicy'){
					foreach($Worker in $_.GetWorkerJobs()){
						$Session = $Worker.FindLastSession()
						$CopyJob = $Session.Name -split '\\'
						$BackupName = $CopyJob[1]
						$CopyName = $CopyJob[0]
						[datetime]$Start = (get-date $Session.SessionInfo.CreationTime  -format "dddd, dd MMMM yyyy h:mm:ss tt")
						[datetime]$Finish = (get-date $Session.SessionInfo.EndTime -format "dddd, dd MMMM yyyy h:mm:ss tt")
						$backupList += [pscustomobject]@{
							BackupName = $BackupName
							CopyName = $CopyName
							Start = $Start
							Finish = $Finish
							IsRunning = $_.IsRunning
						}
					}
				}
				if($_.JobType -eq 'Backup'){
					$Session = $_.FindLastSession()
					$Task = $session.GetTaskSessions()
					$BackupName = $_.Name
					$CopyName = ""
					$Name = $_.Name
					[datetime]$Start = (get-date $Task.JobSess.CreationTime[0]  -format "dddd, dd MMMM yyyy h:mm:ss tt")
					[datetime]$Finish = (get-date $Task.Jobsess.EndTime[0]  -format "dddd, dd MMMM yyyy h:mm:ss tt")
					$backupList += [pscustomobject]@{
						BackupName = $BackupName
						CopyName = $CopyName
						Start = $Start
						Finish = $Finish
						IsRunning = $_.IsRunning
					}
				}
			}
		$BackupList | sort-object -Property @{Expression = "CopyName"; Descending = $false},
			@{Expression = "Start"; Descending = $false},
			@{Expression = "BackupName"; Descending = $false} | ft
}


clear-host
vbr-getjobs

Post Reply

Who is online

Users browsing this forum: No registered users and 22 guests