PowerShell script exchange
Post Reply
phil987AQ
Novice
Posts: 9
Liked: never
Joined: Dec 14, 2016 7:47 pm
Full Name: Phil Bailey
Contact:

SQL scheduled automated restore to another server

Post by phil987AQ »

Hello
I wanted to know if this feature is coming soon? I'm looking for automated sql restores to another server. For example production databases to dev after nightly backup every day.
Thanks
Phil
Gostev
Chief Product Officer
Posts: 31456
Liked: 6647 times
Joined: Jan 01, 2006 1:01 am
Location: Baar, Switzerland
Contact:

Re: SQL scheduled automated restore to another server

Post by Gostev »

Hi, Phil

This feature is already available through PowerShell.

Thanks!
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: SQL scheduled automated restore to another server

Post by veremin »

Check this section of our User Guide for more information. Use -ServerName parameter to restore to different server. Thanks.
dellock6
Veeam Software
Posts: 6137
Liked: 1928 times
Joined: Jul 26, 2009 3:39 pm
Full Name: Luca Dell'Oca
Location: Varese, Italy
Contact:

Re: SQL scheduled automated restore to another server

Post by dellock6 »

you may want to have a look at this awesome post from my colleague Preben Berg, sounds like what you are looking for:
https://poulpreben.com/refresh-sql-data ... velopment/
Luca Dell'Oca
Principal EMEA Cloud Architect @ Veeam Software

@dellock6
https://www.virtualtothecore.com/
vExpert 2011 -> 2022
Veeam VMCE #1
inoisikoiski
Influencer
Posts: 17
Liked: never
Joined: Apr 12, 2019 9:55 am
Full Name: Inoi Visp
Contact:

Re: SQL scheduled automated restore to another server

Post by inoisikoiski »

Hi,
Is there a script as well for sql object restore? The script is basically for developers who doesn't have admin rights and would like to do an object restore.
Thanks
Inoi
foggy
Veeam Software
Posts: 21069
Liked: 2115 times
Joined: Jul 11, 2011 10:22 am
Full Name: Alexander Fogelson
Contact:

Re: SQL scheduled automated restore to another server

Post by foggy »

Hi Inoi, I don't think objects restore is available in PS.
inoisikoiski
Influencer
Posts: 17
Liked: never
Joined: Apr 12, 2019 9:55 am
Full Name: Inoi Visp
Contact:

Re: SQL scheduled automated restore to another server

Post by inoisikoiski »

Thanks foggy.
carruzzom
Lurker
Posts: 1
Liked: never
Joined: May 29, 2019 7:45 am
Contact:

Re: SQL scheduled automated restore to another server

Post by carruzzom »

Hi everyone,

I've tried this script but unfortunately with the new version of Veeam to command is obsolete :(

WARNING: This cmdlet is obsolete, use Get-VESQLDatabase instead

I don't find a way to adapt the script correctly. Do you have by any chance an upgraded version of this script ?

Thanks in advance
Best regards

Matt
Antanas26
Novice
Posts: 5
Liked: never
Joined: Sep 11, 2019 12:08 pm
Full Name: Antanas Tamasiunas
Contact:

Re: SQL scheduled automated restore to another server

Post by Antanas26 »

Hi guys. I am wondering about the same thing... Can someone confirm if scheduled SQL database and/or object restores are still supported in the current version 9.5U4 (or will be supported in version 10)? Many thanks.
oleg.feoktistov
Veeam Software
Posts: 1912
Liked: 635 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: SQL scheduled automated restore to another server

Post by oleg.feoktistov »

Hi Antanas,

Scheduled SQL database restore now can be done with Veeam Explorer cmdlets. Have a look at this guide. SQL Objects restore is not available with Powershell yet, though you can run it non-scheduled in Veeam Explorer for SQL GUI.

Thanks,
Oleg
ATM
Lurker
Posts: 2
Liked: never
Joined: Jan 17, 2020 10:51 am
Full Name: Andrey K
Contact:

Re: SQL scheduled automated restore to another server

Post by ATM »

Hello All,

configuring automated restore to another server and get an error message:

Code: Select all

Restore-VESQLDatabase : The specified file already exists on the target server.
C:\!Scripts\erp_restore.ps1:22 знак:1
+ Restore-VESQLDatabase -Force -Database $database -databasename "erp-d ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Restore-VESQLDatabase], Exception
    + FullyQualifiedErrorId : The specified file already exists on the target server.,Veeam.SQL.PowerShell.RestoreVESQLDatabaseCmdlet

I am using below script and -Force switch with Restore-VESQLDataBase:

Code: Select all

Add-PSSnapin -Name VeeamPSSnapIn
$restorepoint = Get-VBRApplicationRestorePoint -SQL | Sort-Object –Property CreationTime –Descending | Select -First 1
Start-VESQLRestoreSession -RestorePoint $restorepoint
$session = Get-VESQLRestoreSession
$database = Get-VESQLDatabase -Session $session[0] -Name "erp" 
write-host "session: $session"
write-host "database: $database"
write-host "restorepoint: $restorepoint"
$cred = Get-VBRCredentials -Name "veeam"
$files = Get-VESQLDatabaseFile -Database $database
#$files
#    Path                                               Type
#    D:\SQL_DBs\erp.mdf                                 Primary
#    C:\SQL\LOGs\erp_log.ldf                         Secondary
#
$path = @("E:\SQL_DATA\erp-daily.mdf","C:\SQL\LOGS\erp-daily_log.ldf")
Restore-VESQLDatabase -Database $database -databasename "erp-daily" -ServerName "XXXXXXXXXX" -File $files -TargetPath $path -SqlCredentials $cred -Force
Stop-VESQLRestoreSession -Session $session[0]
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: SQL scheduled automated restore to another server

Post by veremin »

PowerShell is no different than UI in this case - restore fails, if the files already exist in target directory. Thanks!
ATM
Lurker
Posts: 2
Liked: never
Joined: Jan 17, 2020 10:51 am
Full Name: Andrey K
Contact:

Re: SQL scheduled automated restore to another server

Post by ATM »

@veremin:
You mean that -Force switch is not working as it is written in manual? https://helpcenter.veeam.com/docs/backu ... l?ver=95u4
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: SQL scheduled automated restore to another server

Post by veremin »

It applies to the cases when you restore database to target SQL server and the restored database already exists there. Again in PowerShell we simply follow the UI behaviour. Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests