PowerShell script exchange
Post Reply
Ubachha
Lurker
Posts: 2
Liked: never
Joined: Sep 02, 2020 1:23 pm
Full Name: VK
Contact:

Closing a session after recovery

Post by Ubachha »

Hello!
Help solve the problem:
I need to periodically restore several MS SQL databases to a test server. I wrote a small script, but after its execution the task does not close and hangs in the "working" state. What's wrong about the script?

Code: Select all

Add-PSSnapin -Name VeeamPSSnapIn

$source_host = "SQL_Main"
$base1 = "base1"
$User = "XXXX\XXXXX"
$PWord = ConvertTo-SecureString -String "XXXXXXXX" -AsPlainText -Force
$target_cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord
$target_host = "SQL_Copy"
$target_instance = "COPY"

$(
$restorepoint = Get-VBRApplicationRestorePoint -SQL -Name $source_host | Sort-Object –Property CreationTime -Descending | Select -First 1
Start-VESQLRestoreSession -RestorePoint $restorepoint
$session = Get-VESQLRestoreSession
$database = Get-VESQLDatabase -Session $session[0] -Name $base1

$restore_session = Restore-VESQLDatabase -Database $database -ServerName $target_host -InstanceName $target_instance -DatabaseName $base1 -GuestCredentials $target_cred -SqlCredentials $target_cred -Force
) *>&1 >> "C:\Errors.log"
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Closing a session after recovery

Post by oleg.feoktistov » 1 person likes this post

Hi @Ubachha and Welcome to our Forums!

You need to add Stop-VESQLRestoreSession cmdlet after $restore_session variable since restore session doesn't stop automatically. It is implemented by design to allow restoration of multiple databases in scope of one session.

Thanks,
Oleg
Ubachha
Lurker
Posts: 2
Liked: never
Joined: Sep 02, 2020 1:23 pm
Full Name: VK
Contact:

Re: Closing a session after recovery

Post by Ubachha »

Thank you so much
Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests