SQL Restore Options

ta5
Member Posts: 1,164
Hello
We have an automated script that backups the production db and restores it in a staging db on the same server. We use the restore command with the "WITH MOVE" clause.
So far, so good. It would be nice if the logical filename could also be changed, otherwise the logical file name of the staging db would be the same as in the production db, which is a bit confusing.
I know that its possible to use the alter database command after the restore, using "MODIFY FILE" clause. Anyway, I'm looking for an option to have it done in 1 command...
Thx in advance.
Thomas
We have an automated script that backups the production db and restores it in a staging db on the same server. We use the restore command with the "WITH MOVE" clause.
So far, so good. It would be nice if the logical filename could also be changed, otherwise the logical file name of the staging db would be the same as in the production db, which is a bit confusing.
I know that its possible to use the alter database command after the restore, using "MODIFY FILE" clause. Anyway, I'm looking for an option to have it done in 1 command...
Thx in advance.
Thomas
0
Answers
-
Nobody? I guess then, it's a kind of a phantom problem :-k0
-
Shouold work like this (using the NEWNAME clause):
USE [master] GO RESTORE DATABASE [test] FROM DISK = N'E:\Backup\navlive.bak' WITH FILE = 1, MOVE N'NAV_601_1_Data' TO N'E:\Databases\Test_1_Data.ndf', MOVE N'NAV_601_Data' TO N'E:\Databases\Test_Data.mdf', MOVE N'NAV_601_Log' TO N'E:\Databases\Test_Log.ldf', NOUNLOAD, STATS = 5 GO USE [test] GO ALTER DATABASE [test] MODIFY FILE (NAME=N'NAV_601_Data', NEWNAME=N'NAV_Test_Data') ALTER DATABASE [test] MODIFY FILE (NAME=N'NAV_601_1_Data', NEWNAME=N'NAV_Test_1_Data') ALTER DATABASE [test] MODIFY FILE (NAME=N'NAV_601_Log', NEWNAME=N'NAV_Test_Log') GO
Jörg A. Stryk (MVP - Dynamics NAV)
NAV/SQL Performance Optimization & Troubleshooting
STRYK System Improvement
The Blog - The Book - The Tool0 -
Hi Jörg
Thanks a lot. And it's not possible to have it as option of the restore command, is it?
Regards
Thomas0 -
ta5 wrote:Hi Jörg
Thanks a lot. And it's not possible to have it as option of the restore command, is it?
Regards
Thomas
As far as I know it's not possible. But why not just adding those few lines to your script?Jörg A. Stryk (MVP - Dynamics NAV)
NAV/SQL Performance Optimization & Troubleshooting
STRYK System Improvement
The Blog - The Book - The Tool0 -
Thanks. Yes I'll add the lines. I was just wondering0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 321 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions