Solved

Database Recovery from Script or Task fails

Posted on 2014-11-30
3
176 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 500 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

687 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