Specify database files SQL target location from PS

PowerShell script exchange

Specify database files SQL target location from PS

Veeam Logoby vburgun » Mon Jun 12, 2017 4:35 pm

I need to plan the automatic restoration of a database from one server to another.
I thought I could do it with PowerShell.

Unfortunately, the locations of the data and logs are not the same between the two servers.

I can not find a parameter to modify the location of the data with the command "Start-VBRSQLDatabaseRestore".

I tried to create a blank database with the correct parameters on the destination server. But when Veeam restores the database, it overwrites the existing database and recreates a database with default locations.

Code: Select all
invoke-sqlcmd -inputfile "$DatabaseDestination.sql" -serverinstance $ServeurDestination

Code: Select all
Connect-VBRServer -Server $ServeurVeeam
#$LastBackup = (Get-VBRApplicationRestorePoint -SQL -Name "$ServeurSQLSource")[-1]
#$BackuBase = $LastBackup | Get-VBRSQLDatabaseRestoreInterval -Database $Database
$LastBackup = (Get-VBRApplicationRestorePoint -SQL -Name "$ServeurSQLSource")[-1]
$BackuBase = Get-VBRSQLDatabase -ApplicationRestorePoint $LastBackup[0] -Name "$DatabaseSource"
$Interval = Get-VBRSQLDatabaseRestoreInterval -Database $BackuBase
#$Cred = Get-VBRCredentials -Name "OFIVALMO\svc_vea_bck"
Start-VBRSQLDatabaseRestore -Database $BackuBase -ServerName $ServeurDestination -DatabaseName $DatabaseDestination

Can you help me ? Or do you know another way?
Posts: 1
Liked: never
Joined: Mon Jun 12, 2017 4:24 pm
Full Name: vburgun

Re: Specify database files SQL target location from PS

Veeam Logoby dgmyrs » Wed Aug 02, 2017 4:48 pm

Hi, I know this might be a bit late, but hopefully, it is still helpful. From what I have found, there is no way to specify the file location with the powershell commandlets. See powershell-f26/sql-server-default-file-locations-t42895.html for more details on what I have found. To get around this, in my script I have let it restore to the default location and then issue sql commands afterwards to change the file location/name. Not ideal, but it's the only method that works with PowerShell.
Posts: 2
Liked: 2 times
Joined: Thu Nov 10, 2016 5:14 pm

Re: Specify database files SQL target location from PS

Veeam Logoby v.Eremin » Thu Aug 03, 2017 11:44 am

We're working on that at the moment. One of the next product release should have this functionality included. Thanks.
Veeam Software
Posts: 14261
Liked: 1066 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Return to PowerShell

Who is online

Users browsing this forum: No registered users and 1 guest