Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Restore from .BAK file
Message
 
 
To
03/01/2014 20:26:04
Dragan Nedeljkovich
Now officially retired
Zrenjanin, Serbia
General information
Forum:
Microsoft SQL Server
Category:
Backups
Environment versions
SQL Server:
SQL Server 2012
Application:
Web
Miscellaneous
Thread ID:
01591308
Message ID:
01591330
Views:
27
>>>Here's the script I came up with back then, which I'm editing for each case (but then I have just a few databases each year):
>>>
>>>
use master
>>>
>>>IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N'dbName')
>>>	DROP DATABASE [dbName]
>>>create database dbName on 
>>>	(name = 'dbName',
>>>	filename=N'x:\path\to\new\db\dbName.mdf')
>>>	log on (name = 'dbName_log',
>>>	filename=N'x:\path\to\new\db\dbName.ldf')
>>>restore filelistonly
>>>	from disk='y:\path\to\backup\dbname_backup.bak'
>>>
>>>restore database  [dbName]
>>>	from disk='y:\path\to\backup\dbname_backup.bak'
>>>	with replace, 
>>>	move 'dbName' to 'x:\path\to\new\db\dbName.mdf',
>>>	move 'dbName_log' to 'x:\path\to\new\db\dbName.ldf'
>>>
>>>
>>>The first two commands may not be necessary nowadays, but I keep them just in case. I'm not really keen on knowing what each does and why.
>>
>>First, I agree, that for the number of files I have (about 15) I can simply create hard-coded script and execute it. I don't understand everything in your script so I will have to study it. Like, for example, you said that the first two commands may not be necessary. Which commands and why not?
>
>Creating the database is probably unnecessary, it's there so I can detect if I don't have the rights to the target, or perhaps SQL 2000 was unable to restore a nonexistent one.
>
>The "restore filelist only" was probably needed back then to confirm that the .bak contains a real database backup - again, something that would crash on error before it got into the more complicated stuff. Less of a chance that I'd get some mysteriously wrong error message.
>
>I also had the requirement to change the logical name of the database, as it may have been named the same in several instances (same app, different customers), so they could coexist on the same server.
>
>>Also I found the following Restore script online (in one of the forums):
>>
>>RESTORE DATABASE [db1] FROM  DISK = N'C:\folder\db1.bak' WITH  FILE = 1,  NOUNLOAD,  STATS = 10
>>
>>But I don't understand the purpose of "WITH FILE =1, NOUNLOAD, STATS = 10." A lot to learn.
>>Thank you for your help.
>
>I can guess at those, but hey, there's help (just google it, DO NOT TRY FROM SSMS as you'll waste hours).

Thank you very much. I will read your input carefully tomorrow. Just too tired right now to think.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Reply
Map
View

Click here to load this message in the networking platform