views:

22985

answers:

11

i backed up a data:

BACKUP DATABASE MyDatabase
TO DISK = 'MyDatabase.bak'
WITH INIT --overwrite existing

And then tried to restore it:

RESTORE DATABASE MyDatabase
   FROM DISK = 'MyDatabase.bak'
   WITH REPLACE --force restore over specified database

And now the database is stuck in the restoring state.

Some people have theorized that it's because there was no log file in the backup, and it needed to be rolled forward using:

RESTORE DATABASE MyDatabase
WITH RECOVERY

Except that, of course, fails:

Msg 4333, Level 16, State 1, Line 1
The database cannot be recovered because the log was not restored.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.

And exactly what you want in a catastrophic situation is a restore that won't work.


The backup contains both a data and log file:

RESTORE FILELISTONLY 
FROM DISK = 'MyDatabase.bak'

Logical Name    PhysicalName
=============   ===============
MyDatabase    C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\MyDatabase.mdf
MyDatabase_log  C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\MyDatabase_log.LDF
+11  A: 

Hi,

You need to use the WITH RECOVERY option, with your database RESTORE command, to bring your database online as part of the restore process.

This is of course only if you do not intend to restore any transaction log backups, i.e. you only wish to restore a database backup and then be able to access the database.

Your command should like this,

RESTORE DATABASE MyDatabase
   FROM DISK = 'MyDatabase.bak'
   WITH REPLACE,RECOVERY

You may have more sucess using the restore database wizard in SQL Server Management Studio. This way you can select the specific file locations, the overwrite option, and the WITH Recovery option.

Cheers, John

John Sansom
I've never had to use the recovery statement when doing what he is doing. WITH REPLACE should suffice.
Sam
Yes, I was using NORECOVERY but the restore process hangs. Using WITH RECOVERY, REPLACE it doesn't hang the process anymore
Junior Mayhé
This solved my problem. We had a SAN failure in the middle of a restore and this was a quick and clean solution.
Registered User
@InnerJoin: Excellent news!
John Sansom
Thanks John, your answer helped me.
AndrewJacksonZA
@AndrewJackson: You're welcome!
John Sansom
A: 

Have you tried running a VERIFY ONLY? Just to make sure it's a sound backup.

http://msdn.microsoft.com/en-us/library/ms188902.aspx

Sam
+3  A: 

i figured out why.

If the client who issued the RESTORE DATABASE command disconnects during the restore, the restore will be stuck.

It's odd that the server, when told to restore a database by a client connection, will not finish the restore unless the client stays connected the entire time.

Ian Boyd
All SQL Commands require that the client stay connected the entire time.
mrdenny
@mrdenny: i would have assumed that changes get undone when a client disconnects.
Ian Boyd
+6  A: 

Here's how you do it:

  1. Stop the service (MSSQLSERVER);
  2. Rename or delete the Database and Log files (C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data...) or wherever you have the files;
  3. Start the service (MSSQLSERVER);
  4. Delete the database with problem;
  5. Restore the database again.

Good luck!

Tipu Delacablu
Tipu, thanks for that. I had a similar problem to the original poster, but it was caused by the server running out of disk space whilst restoring and so caused a permanent restoring state.
Pauk
Thank you, a practical answer that works!
pete the pagan-gerbil
+2  A: 

OK, I have similar problem and exactly as it was in case of Pauk, it was caused by the server running out of disk space while restoring and so caused a permanent restoring state. How to end this state without stopping SQL Server services?

I have found a solution :) Drop database dbname

Bingo. THat solved my problem
Dan
+3  A: 

I had this situation restoring a database to an SQL Server 2005 Standard Edition instance using Symantec Backup Exec 11d. After the restore job completed the database remained in a "Restoring" state. I had no disk space issues-- the database simply didn't come out of the "Restoring" state.

I ran the following query against the SQL Server instance and found that the database immediately became usable:

RESTORE DATABASE <database name> WITH RECOVERY
Evan Anderson
A: 

There can also be problem deleting a stuck database if snapshot is enabled. For me this worked:

  1. First I followed Tipu Delacablu steps (read a few posts up)
  2. run command: drop database [your database], which will give you an error telling you the name of the snapshot database
  3. run command: drop database [snapshot database], and then run the command in step 2 again.
A: 

I have the same issue but I am unable to connect to the SqlServer so I can not get into the Query, any suggestions?

What error do you see? Can you post a screenshot?
Ian Boyd
A: 

Thanks Tipu - I had to delete the file in C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup as well.

Nigel
A: 

I have had this problem when I also recieved a TCP error in the event log...

Drop the DB with sql or right click on it in manager "delete" And restore again.

I have actually started doing this by default. Script the DB drop, recreate and then restore.

ZeusT
A: 

I want to know how to restore database after it has been overwriten by backing up restore.My case is as follows I have restored my database from old backup by I restored this database by mistake on last data base updated so it overwritten this updated database.so please tell me how to restore my original database before it's overwritten.

hardtoget410
You should ask this as a new question and on [serverfault.com](http://serverfault.com/) not here.
Martin Smith