PowerShell script exchange
Post Reply
t481
Enthusiast
Posts: 82
Liked: 1 time
Joined: Apr 28, 2015 7:52 am
Contact:

Agent SQL cluster DB restore with PowerShell

Post by t481 »

Hello,
I'm looking to create a simple PS script to restore a list of DBs from an SQL cluster and I'm a little confused by the commandlets

Here's what I think I need to do
Get the backup job
Get the latest restore point
Start a restore session (Start-VESQLRestoreSession) and give it the latest restore point

That's the gist of it.

To get the job I am using the "Get-VBRComputerBackupJob" However, I don't seem to be able to get the latest point using "Get-VBRRestorePoint" as it's not available for VBRComputerBackupJob.

Does anyone know how to do this?

Thank you in advance
PetrM
Veeam Software
Posts: 3626
Liked: 608 times
Joined: Aug 28, 2013 8:23 am
Full Name: Petr Makarov
Location: Prague, Czech Republic
Contact:

Re: Agent SQL cluster DB restore with PowerShell

Post by PetrM »

Hello,

I guess you should use Get-VBRBackup instead of Get-VBRComputerBackupJob to get the backup set and pass it as an argument to Get-VBRRestorePoint cmdlet.

Thanks!
t481
Enthusiast
Posts: 82
Liked: 1 time
Joined: Apr 28, 2015 7:52 am
Contact:

Re: Agent SQL cluster DB restore with PowerShell

Post by t481 »

Thanks @PetrM
I've already tried that but running Get-VBRBackup -Name "Job name" returns null but if i run Get-VBRComputerBackupJob -Name "Job name" it returns the backup object!
Am i not using it correctly?1
PetrM
Veeam Software
Posts: 3626
Liked: 608 times
Joined: Aug 28, 2013 8:23 am
Full Name: Petr Makarov
Location: Prague, Czech Republic
Contact:

Re: Agent SQL cluster DB restore with PowerShell

Post by PetrM »

Hello,

It works fine in my environment. Could you please check that the name of corresponding job is in the list of objects returned by "Get-VBRBackup"?

Thanks!
t481
Enthusiast
Posts: 82
Liked: 1 time
Joined: Apr 28, 2015 7:52 am
Contact:

Re: Agent SQL cluster DB restore with PowerShell

Post by t481 »

Thanks @PetrM
I did that and found that both commandlets return a different object name. VBRComputerBackupJob returns the exact job name you specified whereas Get-VBRBackup returns the name of the job plus the name of the cluster being backed up.

I am now able to retrieve the backup job
$backup = Get-VBRBackup -Name $jobName

I'm retrieving the latest restore point using:
$restorePoint = Get-VBRRestorePoint -Backup $backup | Sort-Object –Property CreationTime –Descending | Select-Object -First 1

However it appears that Get-VBRRestorePoint returns an object of type "Veeam.Backup.Core.COib" Whereas
Start-VESQLRestoreSession -RestorePoint $restorePoint
Expects an object of type "Veeam.Backup.Interaction.Explorer.PowerShell.IVBRApplicationRestorePoint"

This is so complicated for what it is :-(

Any advice?
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Agent SQL cluster DB restore with PowerShell

Post by oleg.feoktistov »

Hi,

That's because you need to get your SQL restore point with Get-VBRApplicationRestorePoint cmdlet. It will be of the right class, so you will be able to pass it to Start-VESQLRestoreSession.

Thanks,
Oleg
ChrisGundry
Veteran
Posts: 259
Liked: 40 times
Joined: Aug 26, 2015 2:56 pm
Full Name: Chris Gundry
Contact:

Re: Agent SQL cluster DB restore with PowerShell

Post by ChrisGundry »

If it helps, our SQL restore script basic components are:

Code: Select all

$RestorePoint = Get-VBRApplicationRestorePoint -SQL -Name "SQL1" | Sort -Descending | Select -First 1

Start-VESQLRestoreSession -RestorePoint $RestorePoint

$session = Get-VESQLRestoreSession

$database = Get-VESQLDatabase -Session $session[0] -Name "DBNameToRestore"

$restoreinterval = Get-VESQLDatabaseRestoreInterval -Database $database

Restore-VESQLDatabase -Database $database -ServerName "SQLServer" -TargetFolder "C:\SQL\Restore" -SqlCredentials $creds -ToPointInTime $restoreinterval.ToUtc

Stop-VESQLRestoreSession
Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests