?
Solved

Database Recovery from Script or Task fails

Posted on 2014-11-30
3
Medium Priority
?
182 Views
Last Modified: 2014-12-01
I made a job to backup my database, MUM2, and named it MYMHalfHour.bak

I'm trying to create a script that will recover the database from this backup, to a development copy, called MYM_Dev1.

I use this script:

RESTORE DATABASE [MYM_Dev1] FROM  
DISK = N'C:\Backups\MYMBups\MYMHalfHour.bak' 
WITH  FILE = 1,  MOVE N'MUM2' 
TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\MYM_Dev1.mdf', 
 MOVE N' MUM2_log' 
 TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\MYM_Dev1_1.ldf', 
  NOUNLOAD,  STATS = 10

Open in new window


I get this error:
Logical file 'MUM2' is not part of database 'MYM_Dev1'. Use RESTORE FILELISTONLY to list the logical file names.

If I use the IDE to try to do a restore: Tasks | Restore | Database:
Select Device: C:\backups\MYMHalfHour.bak
Database: Mum2
Destination:
Database: MYM_Dev1

I get an error:
System.Data.SqlClient.SqlError: The file 'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\Mum2.mdf' cannot be overwritten.  It is being used by database 'Mum2'. (Microsoft.SqlServer.SmoExtended)

Which I don't understand, because I'm not restoring to MUM2, I'm restoring to MYM_Dev1. I even took MUM2 offline and tried it and get the same error.

But when I go to the Files tab, the Logical File name for the files is not MUM2, but is:
SSSBase2012
SSSBase2012_log

which is the name of another database on this server.

So I've tried two different methods and both have different errors. Please help, what am I doing wrong?

Also, if I run the script: RESTORE FILELISTONLY I get this:
SSSBase2012       C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\Mum2.mdf      D      SSSBase2012_log      C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\Mum2_1.ldf      L

So I tried this script:
RESTORE DATABASE [MYM_Dev1] FROM  
DISK = N'C:\Backups\MYMBups\MYMHalfHour.bak' 
WITH  FILE = 1,  MOVE N'SSSBase2012' 
TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\MYM_Dev1.mdf', 
 MOVE N' SSSBase2012_log' 
 TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\MYM_Dev1_1.ldf', 
  NOUNLOAD,  STATS = 10

Open in new window


But it errors with:
Logical file ' SSSBase2012_log' is not part of database 'MYM_Dev1'.

thanks.
0
Comment
Question by:Starr Duskk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 5

Expert Comment

by:Trent Smith
ID: 40472730
Not sure if this will work or not but try it and let me know.

Alter Database MYM_Dev1

Set Single_User with Rollback Immediate

Restore Database MYM_Dev1
From Disk = 'C:\Backups\MYMBups\MYMHalfHour.bak'
With Replace, Stats = 5
0
 
LVL 8

Accepted Solution

by:
Dung Dinh earned 2000 total points
ID: 40473145
Hi,

I'm not sure but logical name of file log makes me confuse here. Why does it contain white space?

 MOVE N' SSSBase2012_log'
 TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\MYM_Dev1_1.ldf',
  NOUNLOAD,  STATS = 10
0
 
LVL 2

Author Closing Comment

by:Starr Duskk
ID: 40473192
Dung,

That was it! The space within the single quote broke it!

thanks for the sharp eyes!
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question