简体   繁体   English

SQL Server 2005还原挂起

[英]SQL Server 2005 Restore Hanging

I have a database showing up in SQL Enterprise Manager as "(Restoring...)" 我有一个数据库在SQL企业管理器中显示为“(恢复...)”

If i do SP_WHO there is no restore process. 如果我做SP_WHO,则没有恢复过程。

The disk and CPU activity on the server is very low 服务器上的磁盘和CPU活动非常低

I think it is not restoring at all. 我认为它根本没有恢复。

How can I get rid of this? 我怎么能摆脱这个?

I've tried renaming the underlying MDF file, but even when I do "NET STOP MSSQLSERVER" it tells me the file is open. 我已经尝试重命名底层的MDF文件,但即使我做“NET STOP MSSQLSERVER”它告诉我文件是打开的。

I've tried using PROCEXP to find what process has the file open, but even the latest PROCEXP can't seem to do that on Windows Server 2003 R2 x64. 我已经尝试使用PROCEXP来查找文件打开的进程,但即使最新的PROCEXP也无法在Windows Server 2003 R2 x64上执行此操作。 The lower pane view is blank. 下部窗格视图为空白。

In the SQL Server log it says "the database is marked RESTORING and is in a state that does not allow recovery to be run" 在SQL Server日志中,它说“数据库标记为RESTORING,并且处于不允许运行恢复的状态”

Sql Server has two backup types: Sql Server有两种备份类型:

  • Full backup, contains the entire database 完全备份,包含整个数据库
  • Transaction log backup, contains only the changes since the last full backup 事务日志备份,仅包含自上次完全备份以来的更改

When restoring, Sql Server asks you if you want to restore additional logs after the full backup. 还原时,Sql Server会询问您是否要在完全备份后还原其他日志。 If you choose this option, called WITH NORECOVERY, the database will be left in Restoring state. 如果选择此选项(名为WITH NORECOVERY),数据库将处于“还原”状态。 It will be waiting for more transaction logs to be restored. 它将等待恢复更多的事务日志。

You can force it out of Restoring mode with: 您可以使用以下命令将其强制退出恢复模式:

RESTORE DATABASE <DATABASE_NAME> WITH RECOVERY

If this command gives an error, detach the database, remove the MDF files, and start the restore from scratch. 如果此命令出错,请分离数据库,删除MDF文件,然后从头开始还原。 If it keeps failing, your backup file might be corrupted. 如果它一直失败,您的备份文件可能已损坏。

Here's a screenshot of the restore options, with the default selected. 这是恢复选项的屏幕截图,默认选中。 The second option will leave the database in Restoring state. 第二个选项将使数据库处于还原状态。

Image of the restore options http://img193.imageshack.us/img193/8366/captureu.png 恢复选项的图像http://img193.imageshack.us/img193/8366/captureu.png

PS1. PS1。 Are you running the 64 bit version of process explorer? 您是否正在运行64位版本的进程资源管理器? Verify that you see procexp64.exe in the task manager. 验证您是否在任务管理器中看到procexp64.exe。

PS2. PS2。 This is more like a question for serverfault . 这更类似于serverfault的问题。

WITH RECOVERY option is used by default when RESTORE DATABASE/RESTORE LOG commands is executed. 执行RESTORE DATABASE / RESTORE LOG命令时,默认情况下使用WITH RECOVERY选项。 If you're stuck in "restoring" process you can bring back a database to online state by executing: 如果您陷入“恢复”过程,则可以通过执行以下操作将数据库恢复为联机状态:

RESTORE DATABASE YourDB WITH RECOVERY
GO

You can look for more options and some third party tools on this SO post https://stackoverflow.com/a/21192066/2808398 您可以在此SO帖子上查找更多选项和一些第三方工具https://stackoverflow.com/a/21192066/2808398

If you are trying to get rid of the lock on the file I would recommend getting Unlocker http://www.emptyloop.com/unlocker/ 如果你试图摆脱文件上的锁定,我建议你获取Unlocker http://www.emptyloop.com/unlocker/

It'll give you an option to unlock the file, or kill the process that has locked the file. 它将为您提供解锁文件的选项,或者终止锁定文件的进程。 Run this on the mdf and ldf files. 在mdf和ldf文件上运行此命令。

Another option is to try to Detach the files from Enterprise Manager or Sql Management Studio and then reattach the db. 另一种选择是尝试从Enterprise Manager或Sql Management Studio中分离文件,然后重新附加数据库。 You can try this before running unlocker to see if sql server will just release the mdf and ldf files. 您可以在运行unlocker之前尝试此操作,以查看sql server是否只是释放mdf和ldf文件。

CAUTION: If you kill the process you might lose data or the data might get corrupted so use this only if you are trying to get rid of it and you have a good and tested backup. 注意:如果您终止进程,可能会丢失数据或数据可能已损坏,因此只有在您尝试删除它并且拥有良好且经过测试的备份时才使用此数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM