PowerShell script exchange
Post Reply
pshute
Veteran
Posts: 254
Liked: 14 times
Joined: Nov 23, 2015 10:56 pm
Full Name: Peter Shute
Contact:

Getting details of currently running tape restore job

Post by pshute »

Is there a cmdlet that returns details about tape restore jobs?

Get-VBRRestoreSession seems to only list restore associated with restore points on disk. Get-VBRTape seems to only list backup to tape jobs.
veremin
Product Manager
Posts: 20400
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Getting details of currently running tape restore job

Post by veremin »

Don't have tape restore sessions in my lab, so, cannot check whether the script works as expected, but one of these examples should do the trick:

Code: Select all

[Veeam.Backup.Core.CRestoreSession]::GetRunning($Job.id) #you need to specify the job's id here
[Veeam.Backup.Core.CRestoreSession]::FindByOibId($RestorePoint.id) #you need to specify the id of the restore point from which restore process has been executed
Thanks!
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 669 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Getting details of currently running tape restore job

Post by oleg.feoktistov »

Or else try this one just to return all vm tape restore sessions:

Code: Select all

$jobType = [Veeam.Backup.Model.EDbJobType]::VmTapeRestore
$sessions = [Veeam.Backup.Core.CRestoreSession]::GetAll() | Where-Object {$_.JobType -eq $jobType}
pshute
Veteran
Posts: 254
Liked: 14 times
Joined: Nov 23, 2015 10:56 pm
Full Name: Peter Shute
Contact:

Re: Getting details of currently running tape restore job

Post by pshute »

Unfortunately that doesn't work. Even this code to list them all only listed things like file level restores, etc, for the last year or so (in reverse chronological order), but no tape restores. There should have been several in that time.
$sessions = [Veeam.Backup.Core.CRestoreSession]::GetAll()
I didn't check properly, but the results look similar to
Get-VBRRestoreSession
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 669 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Getting details of currently running tape restore job

Post by oleg.feoktistov »

Sorry, Peter, one thing didn't catch my attention - tape restore sessions are restore type dependant.
I don't see a way to determine directly whether the restore session is a tape-related or not.
Basically, you need to query for the source job type first to filter them properly:

Code: Select all

$backups = Get-VBRBackup -Name 'Backup To Tape'
foreach ($backup in $backups) {
$restorepoints = Get-VBRRestorePoint -Backup $backup
   foreach ($restorepoint in $restorepoints) {
	$sourceJob = $restorepoint.FindSourceJob()
	if ($sourceJob.JobType -eq 'VmTapeBackup') {
	   [Veeam.Backup.Core.CRestoreSession]::FindByOibId($restorepoint.Id)
        }
    }
}
Best regards,
Oleg
pshute
Veteran
Posts: 254
Liked: 14 times
Joined: Nov 23, 2015 10:56 pm
Full Name: Peter Shute
Contact:

Re: Getting details of currently running tape restore job

Post by pshute »

That doesn't return anything for me. I modified it to include everythng available (please confirm I've done that correctly):
$backups = Get-VBRBackup
# -Name 'Backup To Tape'
foreach ($backup in $backups) {
$restorepoints = Get-VBRRestorePoint -Backup $backup
foreach ($restorepoint in $restorepoints) {
$sourceJob = $restorepoint.FindSourceJob()
if (1 -eq 1) {
[Veeam.Backup.Core.CRestoreSession]::FindByOibId($restorepoint.Id)
}
}
}
It only returned details of three jobs, all of type "Guest File Restore (Windows)".
pshute
Veteran
Posts: 254
Liked: 14 times
Joined: Nov 23, 2015 10:56 pm
Full Name: Peter Shute
Contact:

Re: Getting details of currently running tape restore job

Post by pshute »

Looks like
Get-VBRBackup -Name "Backup Job 1 - main on Tape"
returns a result after the restore point has been retrieved from tape, but not during the restore.

I see someone has removed the restore point I was concerned about, and is currently restoring another from a different tape. The above command returns nothing. Before the other restore point was removed, it was returning details about that restore point. I can see that it has creaed the vbk file, but not the vbm file yet (job is at 30%). I suspect it won't return anything until it creates the vbm file.
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 669 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Getting details of currently running tape restore job

Post by oleg.feoktistov »

Hi Peter,

That's what I meant - restore type properties have no relations to the source storage type, so the sessions retrieved actually relate to tapes. They just don't have any direct information about it. Check the script below:

Code: Select all

$backups = Get-VBRTapeBackup
$jobType = [Veeam.Backup.Model.EDbJobType]::VmTapeBackup
foreach ($backup in $backups) {
$restorepoints = Get-VBRRestorePoint -Backup $backup
   foreach ($restorepoint in $restorepoints) {
       $sourceJob = $restorepoint.FindSourceJob()

	    if ($sourceJob.JobType -eq $jobType) {
     
            [Veeam.Backup.Core.CRestoreSession]::FindByOibId($restorepoint.Id) | select Name, @{n='Source Job Type';e={$sourceJob.JobType}}, @{n='Restore Type';e={$_.JobTypeString}}

    }
  }
}
Thanks,
Oleg
pshute
Veteran
Posts: 254
Liked: 14 times
Joined: Nov 23, 2015 10:56 pm
Full Name: Peter Shute
Contact:

Re: Getting details of currently running tape restore job

Post by pshute »

Sorry, I'm a bit confused now. That code returns nothing. Is that because the tape restore job is no longer running?

And why are we using a deprecated cmdlet?

I'm confused about what Get-VBRTapeBackup does. If I run

Code: Select all

Get-VBRTapeBackup | fl JobName, JobType, CreationTime, LastPointCreationTime, VmCount
I get this:
WARNING: This cmdlet is obsolete and no longer supported

JobName : Backup Job 1 - main on Tape
JobType : VmTapeBackup
CreationTime : 23/10/2015 2:53:40 PM
LastPointCreationTime : 21/04/2020 8:00:29 PM
VmCount : 32

JobName : Backup Job 1 - main on Tape
JobType : VmTapeBackup
CreationTime : 23/10/2015 2:53:40 PM
LastPointCreationTime : 31/03/2020 8:00:31 PM
VmCount : 41

JobName : Backup Job 1 - main on Tape
JobType : VmTapeBackup
CreationTime : 23/10/2015 2:53:40 PM
LastPointCreationTime : 31/12/2019 8:00:37 PM
VmCount : 32

JobName : Backup Job 1 - test on Tape
JobType : VmTapeBackup
CreationTime : 23/10/2015 2:53:40 PM
LastPointCreationTime : 2/05/2017 9:00:55 PM
VmCount : 36
Three jobs with the same name, and one with a name I used to used a long time ago (then renamed it). The names are the names of disk backup jobs, with "on Tape" appended.

All have the same CreationTime. Is that the date I created that tape backup job? And the LastPointCreationTime is the date of the backup the tape job copied to tape? Why are there only four of them? We run this job weekly. The related disk backup jobs run daily.

And why the variation in the VmCount? The GUI says there are 31 VMs in the job, why is it saying 32 for the first and third? I can believe that the last one listed could have had 36 in it, as things change, but I can't believe the second one had 41 in it. It's only a few weeks ago. The GUI says it also had 31.
pshute
Veteran
Posts: 254
Liked: 14 times
Joined: Nov 23, 2015 10:56 pm
Full Name: Peter Shute
Contact:

Re: Getting details of currently running tape restore job

Post by pshute »

Also, why was the backup restored from tape a few days ago called Get-VBRBackup -Name "Backup Job 1 - main on Tape", but the one restored from tape yesterday is called Get-VBRBackup -Name "Backup Job 1 - main on Tape_imported"?

Both appeared in the Imported section in the GUI.
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 669 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Getting details of currently running tape restore job

Post by oleg.feoktistov »

Sorry, I'm a bit confused now. That code returns nothing. Is that because the tape restore job is no longer running?
Should return the tape restore sessions regardless of their state.
And why are we using a deprecated cmdlet?
Get-VBRBackup doesn't return tape backups.
All have the same CreationTime. Is that the date I created that tape backup job? And the LastPointCreationTime is the date of the backup the tape job copied to tape?
CreationTime is the date when the first restore point was created with this backup job. LastPointCreationTime is the date for the most recent one.

I figured that since Backup holds the property value needed (JobType: VmTapeBackup), we can get rid of querying for a source job object:

Code: Select all

 $backups = Get-VBRTapeBackup | where {$_.JobType -eq 'VmTapeBackup'}
foreach ($backup in $backups) {
$restorepoints = Get-VBRRestorePoint -Backup $backup
   foreach ($restorepoint in $restorepoints) {
     
            [Veeam.Backup.Core.CRestoreSession]::FindByOibId($restorepoint.Id) | select Name, @{n='Source Job Type';e={$backup.JobType}}, @{n='Restore Type';e={$_.JobTypeString}}, State

  }
} 
The script above works as expected in my lab and retrieves all the tape restore sessions including running ones.
I'd suggest reaching our support if the output data for PS cmdlets differs from one in UI.

Thanks,
Oleg
pshute
Veteran
Posts: 254
Liked: 14 times
Joined: Nov 23, 2015 10:56 pm
Full Name: Peter Shute
Contact:

Re: Getting details of currently running tape restore job

Post by pshute »

Unfortunately someone has now removed all the restored backups, so I can't test further. It would take several hours to set up test conditions again.

For now, this is doing what I want:

Code: Select all

$backups = Get-VBRBackup -Name "*tape*"
foreach ($backup in $backups)
	{
	$JobName = $backup | Select-Object -Property JobName
	$DirPath = $backup | Select-Object -Property Dirpath
	$MetaFileName = $backup | Select-Object -Property MetaFileName 
	$LastPointCreationTime = $backup | Select-Object -Property LastPointCreationTime
	$MetaUpdateTime = $backup | Select-Object -Property MetaUpdateTime 
	$s = "Veeam backup restored from tape " + $MetaUpdateTime.MetaUpdateTime + " exists - check if still needed, file space may be low until removed"
	$body = "Name in GUI = " + $JobName.JobName.ToString() + "
	Path = " + $DirPath.DirPath.ToString() + "\"+ $MetaFileName.MetaFileName.ToString() + " 
	Most recent restore point in backup = " + $LastPointCreationTime.LastPointCreationTime + "
	Restored " + $MetaUpdateTime.MetaUpdateTime + "
	To remove, in Veeam, go to Home then Backups then Disk (Imported), right click on the backup, then Remove From Disk."
	if ($backup) {Send-MailMessage -From "xxx@yyy.org.au" -To "zzz@yyy.org.au" -Subject $s -Body $body -SmtpServer "mail2.yyy.org.au"  }
	}
I've scheduled this to run every few hours. It assumes that any backup with "tape" in the name has been restored from tape, and emails me the details.

This assumption has been true for two so far. In one case Veeam appended "on tape" to the name of the original job, in the other it appended "on tape_imported".
Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests