简体   繁体   English

SQL Server备份还原问题?

[英]SQL Server backup restore issues?

Ok, so I'm having a bit of an issue - I executed some code on my SQL Server and didn't realize that I didn't have the WHERE bit selected. 好的,所以我遇到了一些问题 - 我在SQL Server上执行了一些代码,并没有意识到我没有选择WHERE位。 Of course, when I saw the "608 rows affected" rather than "1 row affected" , I freaked a bit. 当然,当我看到"608 rows affected"而非"1 row affected" ,我吓坏了一下。

Luckily, I have a backup saved, but for some reason, I'm getting a couple issues. 幸运的是,我保存了备份,但出于某种原因,我遇到了一些问题。 Now, I took the server down, so I know that it's not being used by anyone, but it's giving me the following error 现在,我把服务器关闭了,所以我知道它没有被任何人使用,但它给了我以下错误

"Restore failed for Server 'myserver'. “服务器'myserver'恢复失败。

System.Data.sqlclient.sqlerror: Exclusive access could not be obtained because the database is in use. System.Data.sqlclient.sqlerror:无法获取独占访问权限,因为数据库正在使用中。 (Microsoft.SqlServer.Smo)" (Microsoft.SqlServer.Smo)”

I saw something that stated I should be using 我看到了我应该使用的东西

Alter Database Databases
SET SINGLE_USER WITH ROLLBACK IMMEDIATE

RESTORE DATABASE PRODUCT
FROM DISK = ''

but I'm having three reservations about this code. 但我对这段代码有三个保留意见。 First, I'm completely unsure of how to turn multi_user back on. 首先,我完全不确定如何重新打开multi_user。 Second, I don't know where the program stores its backups. 其次,我不知道程序存储备份的位置。 Third, this SQL is a bit above my head - I'm relatively new to the language, honestly, so I'm not sure how this will affect things. 第三,这个SQL有点高于我的头 - 老实说,我对这门语言比较新,所以我不确定这会对事情产生什么影响。

Anyone have any answers to my troubles? 有人对我的烦恼有任何答案吗?

I might suggest instead of overwriting the existing database from the backup, that you instead recover the backup with a different database name... this way you can have the current and previous databases side-by-side. 我可能会建议您不要从备份中覆盖现有数据库,而是使用不同的数据库名称来恢复备份...这样您就可以并排使用当前和以前的数据库。

Then, you can simply write an update statement to recover the data from just that one specific table instead of resetting the whole database. 然后,您只需编写一个更新语句即可从该特定表中恢复数据,而不是重置整个数据库。

EDIT: The specifics would depend on your environment, but the restore would look something like this: 编辑:细节取决于您的环境,但恢复将看起来像这样:

restore database PRODUCT_OLD
from disk='C:\PRODUCT.bak'
with
    move 'PRODUCT_Data' to 'C:\PRODUCT_OLD_Data.MDF',
    move 'PRODUCT_Log' to 'C:\PRODUCT_OLD_Log.LDF'

And then the update statement would also be based on your specific table... 然后更新声明也将基于您的特定表...

在数据库上点击任务 - > takeoffline ,当它成功做同样的事情,但把它Bring Online然后尝试恢复你的数据库

Set the database to single user is correct. 将数据库设置为单个用户是正确的。 When you are complete with your restoration you'll execute this 当您完成修复后,您将执行此操作

alter database YourDb
set multi_user

As for where your .bak file resides, you'll have to find it prior to restoring. 至于.bak文件所在的位置,您必须在恢复之前找到它。

Scary. 害怕。

Ok, some things to check: 好的,有些事要检查:

  1. Make sure you are the only person connected to the server. 确保您是唯一连接到服务器的人。
  2. Make sure no other applications, web servers, app servers, etc. hold connections to your DB. 确保没有其他应用程序,Web服务器,应用程序服务器等与您的数据库保持连接。
  3. Make sure your SQL manager has no open windows to tables or other objects in your database. 确保您的SQL管理器没有打开数据库中的表或其他对象的窗口。

THEN you should be able to do the restore w/o single user stuff. 那么你应该能够用单个用户的东西进行恢复。

Go to the activity Monitor and see if users are still logged in then kill the process for that user using the respective db. 转到活动监视器,查看用户是否仍然登录,然后使用相应的数据库终止该用户的进程。 Then go ahead restore the backup 然后继续恢复备份

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

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