打开 SQL Server .bak 文件(不恢复!)

发布于 2024-12-21 04:55:25 字数 739 浏览 0 评论 0原文

我一直在阅读大量关于如何从 .bak 文件恢复 SQL Server 中的数据库的 google 帖子和 StackOverflow 问题。

但他们都没有说明如何读取数据库备份中的表。 (无论如何我都找不到?)

我只想查看一些现在已被删除的旧信息,而不实际恢复完整的数据库。 这可能吗?

编辑:

我只是想发布我的 T-SQL 解决方案来解决这个问题,这样其他人就可以使用它,我可以回去查找它;)

首先我创建了一个名为 backup_lookup 的新数据库 并将其离线。 此后,我可以将旧数据库 mydb 恢复到新数据库,而无需触及原始数据库。

USE master
GO
RESTORE DATABASE backup_lookup
 FROM DISK = 'D:\backup\mydb.bak'
WITH REPLACE,
 MOVE 'mydb' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\backup_lookup.mdf',
 MOVE 'mydb_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\backup_lookup_log.ldf'
GO

我希望这有帮助:)

I have been reading a LOT of google posts and StackOverflow questions about how to restore a database in SQL Server from a .bak file.

But none of them states how to just READ the tables in the database-backup.
(None that I could find anyway?)

I just want to check out some old information which now has been deleted, without actually restoring the full database.
Is this possible?

.

EDIT:

I just wanted to post my T-SQL solution to the problem, so others may use it and I can go back and look it up ;)

First I created a new database called backup_lookup and took it offline.
After this I could restore my old database mydb to the new one, without ever touching my original.

USE master
GO
RESTORE DATABASE backup_lookup
 FROM DISK = 'D:\backup\mydb.bak'
WITH REPLACE,
 MOVE 'mydb' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\backup_lookup.mdf',
 MOVE 'mydb_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\backup_lookup_log.ldf'
GO

I hope this helps :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

舂唻埖巳落 2024-12-28 04:55:25

从 SQL Server 2008 SSMS (SQL Server Management Studio) 中,只需:

  1. 连接到您的数据库实例(例如,“localhost\sqlexpress”)
  2. 或者:

    • a) 选择要恢复到的数据库;或者,另一种选择
    • b) 只需创建一个新的空数据库即可恢复。
  3. 右键单击、任务、还原、数据库

  4. 设备、[...]、添加、浏览到您的 .bak 文件
  5. 选择备份。
    在选项下选择“overwrite=Y”。
    恢复数据库
  6. 它应该显示“100% 完成”,并且您的数据库应该在线。

PS:我再次强调:您可以轻松地在“临时数据库”上执行此操作 - 您不需要需要覆盖当前数据库。但您确实需要恢复

PPS:如果您希望编写脚本,您也可以使用 T-SQL 命令完成同样的事情。

From SQL Server 2008 SSMS (SQL Server Management Studio), simply:

  1. Connect to your database instance (for example, "localhost\sqlexpress")
  2. Either:

    • a) Select the database you want to restore to; or, alternatively
    • b) Just create a new, empty database to restore to.
  3. Right-click, Tasks, Restore, Database

  4. Device, [...], Add, Browse to your .bak file
  5. Select the backup.
    Choose "overwrite=Y" under options.
    Restore the database
  6. It should say "100% complete", and your database should be on-line.

PS: Again, I emphasize: you can easily do this on a "scratch database" - you do not need to overwrite your current database. But you do need to RESTORE.

PPS: You can also accomplish the same thing with T-SQL commands, if you wished to script it.

很酷又爱笑 2024-12-28 04:55:25

唯一可行的解​​决方案是恢复.bak 文件。这些文件的内容和结构没有记录,因此,实际上没有办法(除了可怕的黑客)让它工作 - 绝对不值得您花时间和精力!

据我所知,唯一可以在不恢复 .bak 文件的情况下理解它们的工具是 Red-Gate SQL Compare Professional(以及随附的 SQL 数据比较),它允许您将数据库结构与 .bak 文件。 Red-Gate 工具绝对棒极了 - 强烈推荐,而且物有所值!

我刚刚检查了他们的网站 - 看来您确实可以使用 SQL Compare Pro 从 .bak 文件中恢复单个表! :-)

The only workable solution is to restore the .bak file. The contents and the structure of those files are not documented and therefore, there's really no way (other than an awful hack) to get this to work - definitely not worth your time and the effort!

The only tool I'm aware of that can make sense of .bak files without restoring them is Red-Gate SQL Compare Professional (and the accompanying SQL Data Compare) which allow you to compare your database structure against the contents of a .bak file. Red-Gate tools are absolutely marvelous - highly recommended and well worth every penny they cost!

And I just checked their web site - it does seem that you can indeed restore a single table from out of a .bak file with SQL Compare Pro ! :-)

べ繥欢鉨o。 2024-12-28 04:55:25

没有标准方法可以做到这一点。您需要使用第 3 方工具,例如 ApexSQL RestoreSQL 虚拟恢复。这些工具并不真正直接读取备份文件。他们让 SQL Server 将备份文件“视为”实时数据库。

There is no standard way to do this. You need to use 3rd party tools such as ApexSQL Restore or SQL Virtual Restore. These tools don’t really read the backup file directly. They get SQL Server to “think” of backup files as if these were live databases.

漫漫岁月 2024-12-28 04:55:25

只是添加我的 TSQL 脚本解决方案:

首先;添加一个名为 backup_lookup 的新数据库。
然后只需运行此脚本,插入您自己的数据库的根路径和备份文件路径

USE [master]
GO
RESTORE DATABASE backup_lookup
 FROM DISK = 'C:\backup.bak'
WITH REPLACE,
 MOVE 'Old Database Name' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\backup_lookup.mdf',
 MOVE 'Old Database Name_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\backup_lookup_log.ldf'
GO

Just to add my TSQL-scripted solution:

First of all; add a new database named backup_lookup.
Then just run this script, inserting your own databases' root path and backup filepath

USE [master]
GO
RESTORE DATABASE backup_lookup
 FROM DISK = 'C:\backup.bak'
WITH REPLACE,
 MOVE 'Old Database Name' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\backup_lookup.mdf',
 MOVE 'Old Database Name_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\backup_lookup_log.ldf'
GO
好听的两个字的网名 2024-12-28 04:55:25

单独使用 SQL Server 2008 似乎不可能。您将需要第三方工具的帮助。

它将帮助您使 .bak 像实时数据库一样运行:

http: //www.red-gate.com/products/dba/sql-virtual-restore/

It doesn't seem possible with SQL Server 2008 alone. You're going to need a third-party tool's help.

It will help you make your .bak act like a live database:

http://www.red-gate.com/products/dba/sql-virtual-restore/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文