PowerShell script exchange
Post Reply
jluce
Enthusiast
Posts: 25
Liked: 3 times
Joined: Jan 14, 2015 2:23 am
Full Name: John Luce
Contact:

Start-VBRSQLDatabaseRestore question

Post by jluce »

As a newbie in PowerShell I got assigned a task to come up with a script that allows Veeam to copy a SQL database to our test SQL servers for their use daily. The source SQL server
is utilizing transaction SQL log backup provided by Veeam. A question came up while attempting to restore a SQL database that is covered by this whether Veeam is restoring only the snapshot or the snapshot and rerunning the logs up to the point called for by the -ToPointTime. The script we are using is as follows:

Code: Select all

Add-PSSnapin -Name VeeamPSSnapIn
$restorepoint = Get-VBRApplicationRestorePoint -SQL -Name "ProBus SQL" | Select -Last  1
$ProductionDatabase = Get-VBRSQLDatabase -ApplicationRestorePoint $restorepoint[0] -Name "MANGA"
$guestcreds = Get-VBRCredentials -Name "domain\veeamsvc"
$sqlcreds = Get-VBRCredentials -Name "domain\veeamsvc"
$DateTime  = (get-date)
$DateTimeDesired = $DateTime.AddMinutes(-30)
$UDateTime = $DateTimeDesired.ToUniversalTime()
Start-VBRSQLDatabaseRestore -Database $ProductionDatabase -ServerName TESTSQLSVR -DatabaseName MANGA_DAILY_PROD -GuestCredentials $guestcreds -SqlCredentials $sqlcreds -ToPointInTime $UDateTime
The script seems to run however the variable $UDateTime is a UniversalTime which produces the output "Wednesday, April 6, 2016 3:18:35 PM" which we are not sure is being read correctly. Any ideas on this subject?

One additional question is when using PowerShell, where are the logs for the interaction being stored?
Thanks!
veremin
Product Manager
Posts: 20282
Liked: 2257 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRSQLDatabaseRestore question

Post by veremin »

Just out of curiosity - why are you using universal time? Aren't you living in timezone differing from UTC? Thanks.
jluce
Enthusiast
Posts: 25
Liked: 3 times
Joined: Jan 14, 2015 2:23 am
Full Name: John Luce
Contact:

Re: Start-VBRSQLDatabaseRestore question

Post by jluce »

Somewhere along the line we ran into the need for the Get-VBRDatabaseRestoreInterval which returns its output UTC. Since we are not using it we could save ourselves some effort.
veremin
Product Manager
Posts: 20282
Liked: 2257 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRSQLDatabaseRestore question

Post by veremin »

Not sure whether I got your question, does or does not the provided script work for you? In the latter case what particular error you get? Thanks.
jluce
Enthusiast
Posts: 25
Liked: 3 times
Joined: Jan 14, 2015 2:23 am
Full Name: John Luce
Contact:

Re: Start-VBRSQLDatabaseRestore question

Post by jluce »

The script seems to work. Before we give it to our boss. We wanted to be sure that the script as indicated will give us the latest log back -30 minutes.
veremin
Product Manager
Posts: 20282
Liked: 2257 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRSQLDatabaseRestore question

Post by veremin »

Everything appears to be scripted properly. The only line I'm not sure about is conversion to universal time.

Typically, UTC differs from your local time, meaning $UDateTime variable will represent your current time plus or minus several hours. So, I'm wondering how point in time recovery would behave in this case: will it revert db to past 30 minutes or it will revert db to past several hours + 30 minutes.

Thus, I'd recommend to backup the SQL machine and check the script on it afterwards to see whether the code works as expected.

Thanks.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 12 guests