-
- Influencer
- Posts: 17
- Liked: never
- Joined: Apr 12, 2019 9:55 am
- Full Name: Inoi Visp
- Contact:
SQL restore database with multiple datafiles on different drive using PS
Hi,
As stated in the subject, I am trying to restore a sql database with multiple datafiles (.mdf, .ndf) to a different location and the logfiles to another location. I just want the drive (location) as an input. Can anyone help please.
Thanks
As stated in the subject, I am trying to restore a sql database with multiple datafiles (.mdf, .ndf) to a different location and the logfiles to another location. I just want the drive (location) as an input. Can anyone help please.
Thanks
-
- Product Manager
- Posts: 14844
- Liked: 3086 times
- Joined: Sep 01, 2014 11:46 am
- Full Name: Hannes Kasparick
- Location: Austria
- Contact:
Re: SQL restore database with multiple datafiles on different drive using PS
Hello,
I moved your post to the powershell forum.
Could you describe a little bit more which commands you are using? Are you using Restore-VESQLDatabase ?
Which parameters are you using? As far as I can see there is no need to specify the log files path but you can use TargetPath if you require multiple locations for the database files.
Best regards,
Hannes
I moved your post to the powershell forum.
Could you describe a little bit more which commands you are using? Are you using Restore-VESQLDatabase ?
Which parameters are you using? As far as I can see there is no need to specify the log files path but you can use TargetPath if you require multiple locations for the database files.
Best regards,
Hannes
-
- Veeam Vanguard
- Posts: 282
- Liked: 113 times
- Joined: Apr 20, 2017 4:19 pm
- Full Name: Joe Houghes
- Location: Castle Rock, CO
- Contact:
Re: SQL restore database with multiple datafiles on different drive using PS
Hannes is describing example #3 in the documentation here to be able to specify file paths to restore your database files, and it will allow different paths per file.
https://helpcenter.veeam.com/docs/backu ... l?ver=95u4
You could add some logic to build out a full path based on an input of drive letter, which would then be used as your target path for the restore.
https://helpcenter.veeam.com/docs/backu ... l?ver=95u4
You could add some logic to build out a full path based on an input of drive letter, which would then be used as your target path for the restore.
Husband, Father, Solutions Architect, Geek | @DenverVMUG & @DenverPSUG leader | International Speaker | Veeam Vanguard | vExpert (PRO) | Cisco Champion
-
- Influencer
- Posts: 17
- Liked: never
- Joined: Apr 12, 2019 9:55 am
- Full Name: Inoi Visp
- Contact:
Re: SQL restore database with multiple datafiles on different drive using PS
Thanks Hannes. I am indeed using Restore-VESQLDatabase.
The thing is, for example, the production datafile location is on E:\SQLData and logfile is L:\SQLlog. And in our DEV servers, it's D:\SQLData and L:\SQLlogs. I tried using the -TargetFolder but all datafiles were in all location. Also tried the -TargetPath however, i managed to make it work when there is only one datafile (.mdf) and one logfile. My problem with -TargetPath is if the database has multiple datafiles.
Thanks again.
The thing is, for example, the production datafile location is on E:\SQLData and logfile is L:\SQLlog. And in our DEV servers, it's D:\SQLData and L:\SQLlogs. I tried using the -TargetFolder but all datafiles were in all location. Also tried the -TargetPath however, i managed to make it work when there is only one datafile (.mdf) and one logfile. My problem with -TargetPath is if the database has multiple datafiles.
Thanks again.
-
- Veeam Vanguard
- Posts: 282
- Liked: 113 times
- Joined: Apr 20, 2017 4:19 pm
- Full Name: Joe Houghes
- Location: Castle Rock, CO
- Contact:
Re: SQL restore database with multiple datafiles on different drive using PS
You need to create an array of file paths for every file that you want to restore, and the file order should match the array that is returned when you run the 'Get-VESQLDatabaseFile' cmdlet.
Husband, Father, Solutions Architect, Geek | @DenverVMUG & @DenverPSUG leader | International Speaker | Veeam Vanguard | vExpert (PRO) | Cisco Champion
-
- Influencer
- Posts: 17
- Liked: never
- Joined: Apr 12, 2019 9:55 am
- Full Name: Inoi Visp
- Contact:
Re: SQL restore database with multiple datafiles on different drive using PS
Sorry, not really a hardcore on PS. I'm trying to figure out how when using -TargetPath will it know which is which (mdf, ndf, ldf etc)
-
- Product Manager
- Posts: 20415
- Liked: 2302 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: SQL restore database with multiple datafiles on different drive using PS
You will have two arrays:
-File <VESQLDatabaseFile[]>
-TargetPath <string[]>
Say, a first element in first array is .mdf file. To place .mdf file in "C:\Temp\" directory you will need to make sure that "C:\Temp" string is the first element of the second array.
Thanks!
-File <VESQLDatabaseFile[]>
-TargetPath <string[]>
Say, a first element in first array is .mdf file. To place .mdf file in "C:\Temp\" directory you will need to make sure that "C:\Temp" string is the first element of the second array.
Thanks!
-
- Influencer
- Posts: 17
- Liked: never
- Joined: Apr 12, 2019 9:55 am
- Full Name: Inoi Visp
- Contact:
Re: SQL restore database with multiple datafiles on different drive using PS
Thanks! That made sense. Got my script working.
Who is online
Users browsing this forum: No registered users and 7 guests