简体   繁体   English

是否可以在sql server 2005中恢复Sql Server 2008备份

[英]Is it possible to restore Sql Server 2008 backup in sql server 2005

Is it possible to restore a backup of a SQL Server 2008 database onto an instance of SQL Server 2005? 是否可以将SQL Server 2008数据库的备份还原到SQL Server 2005的实例上?

I need to work on an sample application for which database backup is in sql server 2008. But I'll not be able to install 2008. So is it possible to restore that back up in 2005? 我需要处理sql server 2008中数据库备份的示例应用程序。但是我将无法安装2008.那么有可能在2005年恢复备份吗?

No. It is not possible to restore a database from a backup of a newer version. 不可以。无法从较新版本的备份中恢复数据库。

If you are dead set on it, I think your best option is to selet the database in the Object Explorer in SQL 2008, right-click, select Tasks->Generate Scripts.In the options dialog emable about everything, including Script Data. 如果您已经死定,我认为您最好的选择是在SQL 2008中的对象资源管理器中选择数据库,右键单击,选择任务 - >生成脚本。在选项对话框中可以查看所有内容,包括脚本数据。

And make sure you select "Script for SQL 2005". 并确保选择“Script for SQL 2005”。

Source 资源

When importing the objects into your target server, if the objects are large you may find that you can't open the SQL file via Management Studio (with a completely useless "The operation could not be completed" error, no less). 将对象导入目标服务器时,如果对象很大,您可能会发现无法通过Management Studio打开SQL文件(完全没用“操作无法完成”错误,不会少)。 That's okay, just load the file via sqlcmd . 没关系,只需通过sqlcmd加载文件即可。

One important thing is missing in all answers and that is the fact that Generate Scripts in SSMS doesn't order the scripts correctly. 所有答案都缺少一个重要的事情,那就是SSMS中的Generate Scripts没有正确排序脚本。

Scripts have to be ordered in the correct dependency order so that child tables are created after parent tables and such. 必须以正确的依赖顺序对脚本进行排序,以便在父表等之后创建子表。

This is not an issue for small databases where its easy to reorder the scripts manually but it can be a huge issue when dealing with databases that have 100+ objects. 对于小型数据库而言,这不是一个问题,因为它很容易手动重新排序脚本,但在处理具有100多个对象的数据库时,这可能是一个巨大的问题。

My experience is that its most convenient to use third party tools that can read backup and generate scripts in the correct order. 我的经验是,使用第三方工具最方便,可以按正确顺序读取备份和生成脚本。 I'm using ApexSQL Diff and Data Diff from ApexSQL but you can't go wrong with any popular vendor. 我正在使用来自ApexSQL的ApexSQL Diff和Data Diff,但你不会对任何流行的供应商出错。

No, not directly. 不,不是直接的。 SQL Server 2008 database backups are not backward compatible with SQL Server 2005. However, with SQL Server 2008 Management Studio, you can script data and schemas in SQL Server 2005 mode. SQL Server 2008数据库备份不与SQL Server 2005向后兼容。但是,使用SQL Server 2008 Management Studio,您可以在SQL Server 2005模式下编写脚本数据和模式。 This article describes the process in detail. 本文详细介绍了该过程。

I have had this problem for a long while. 我有这个问题很长一段时间了。

You cannot restore SQL2008 backups onto an SQL2005 instance. 您无法将SQL2008备份还原到SQL2005实例上。

And for me, workarounds like import/export wizzard or to script the database from SQL2008 using the generate scripts with the for SQL2005 option won't work. 对我来说,导入/导出wizzard或使用带有for SQL2005选项的生成脚本从SQL2008编写脚本数据库的变通方法将无效。 Because simply, my databases cross-reference each other inside their views and stored procedures or udfs. 因为简单地说,我的数据库在它们的视图和存储过程或udfs中相互交叉引用。 They do not befall to my responsibility completely and so I cannot consolidate them into 1 database. 他们完全没有完全履行我的责任,因此我无法将它们整合到一个数据库中。 They are a set of 6 dbs that refer to each other directly inside their views and stored procedures. 它们是一组6个dbs,它们直接在视图和存储过程中相互引用。 When I transfer them from one SQL2005 instance onto another, I usually do full-backup/restore. 当我将它们从一个SQL2005实例传输到另一个SQL2005实例时,我通常会进行完全备份/恢复。

If I were to script them, even with the with dependencies option I would get errors at re-creation time as db1 will not find views inside db3 because it so happened that I executed the create db1 script first. 如果我要编写脚本,即使使用with dependencies选项,我也会在重新创建时遇到错误,因为db1将无法在db3中找到视图,因为碰巧我首先执行了create db1脚本。 If I tried db3 first I get similar exceptions. 如果我先尝试db3,我会得到类似的例外。

The only way to script them so that I won't have such dependency exceptions, is to figure out a sequence that works and script them partially in that manner: say: db1_tables followed by db2_tables followed by db2_views followed by db1_views, sp, udfs etc. 编写脚本以使我不会有这种依赖性异常的唯一方法是找出一个有效的序列,并以这种方式部分编写脚本:比如:db1_tables后跟db2_tables,后跟db2_views,后跟db1_views,sp,udfs等。

I have such a sequence. 我有这样一个序列。 And when I need to create a new set of such 6 dbs, I executed the smaller partial scripts in sequence. 当我需要创建一组这样的6个dbs时,我按顺序执行了较小的部分脚本。

This explains why the generate scripts, with dependencies and with data and set to SQL2005 version scripts, will just not work for me. 这解释了为什么生成具有依赖关系和数据并设置为SQL2005版本脚本的脚本对我来说不起作用。

The import/export wizzard is better in my case because it will copy tables and then you still have to script all views, sp, udfs etc. 导入/导出wizzard在我的情况下更好,因为它将复制表,然后你仍然需要脚本所有视图,sp,udfs等。

What I really need is a conversion tool for SQL2008 backup files, to convert them to SQL2005 format. 我真正需要的是SQL2008备份文件的转换工具,将它们转换为SQL2005格式。 Then my problem will go away. 然后我的问题就会消失。 Or some kind of a tool that would allow restore from SQL2008 full-backup files, without asking me too many questions. 或者某种工具可以从SQL2008完整备份文件中恢复,而不会问我太多问题。

If anyone knows such tools and have used them, let me know. 如果有人知道这些工具并使用过它们,请告诉我。

Yes it is possible 对的,这是可能的

Using the export in the SQL Server 2008. Go to All Programs --> Microsoft SQL Server 2008 --> Import and Export Data 使用SQL Server 2008中的导出。转到“ All Programs - >“ Microsoft SQL Server 2008 - >“ Import and Export Data

  • Then SQL Server Import AND Export Wizard window will be opened. 然后将打开SQL Server Import AND Export Wizard窗口。 Press Next Next

  • Choose a Data source (in your case from SQL Server 2008). 选择一个数据源(在您的情况下从SQL Server 2008)。 Choose a Destination( in your case from SQL Server 2005). 选择目标(在您的情况下从SQL Server 2005)。

  • Select Copy data from one or more tables or view 选择Copy data from one or more tables or view

  • Select the source's tables and destination's tables 选择源的表和目标表

  • Click Next & Finish 单击NextFinish

to complete. 去完成。

You can use DBSave , it's a great freeware tool to backup and restore ms sql server on different machines. 你可以使用DBSave ,它是一个很棒的免费工具,可以在不同的机器上备份和恢复ms sql server。 It's verry simple to setup and to use. 设置和使用非常简单。

Having had no luck with the Import/Export stuff (flat file exports failed on import claiming charset mapping issues [even though same charset used throughout] and/or truncation issues [even though source and destination had exact same structure]), and having had no luck with using the "generate scripts" option suggested by Garry Shutler (it generated a script with syntax errors), I was finally able to copy the big table I wanted to copy from 2008 to 2005 using the SQL Server bcp utility . 导入/导出的东西没有运气(平面文件导出失败导入声称字符集映射问题[即使整个使用相同的字符集]和/或截断问题[即使源和目标具有完全相同的结构]),并且已经使用Garry Shutler建议的“生成脚本”选项(它生成了一个语法错误的脚本)没有运气,我终于能够使用SQL Server bcp实用程序复制我想要从2008年到2005年复制的大表。 So that's another option for this situation, although for an entire database it would be table-by-table and probably doesn't help with views and such. 所以这是这种情况的另一个选择,虽然对于整个数据库来说,它将是逐个表的,并且可能对视图等没有帮助。

The steps I used: 我使用的步骤:

  1. On the source server, use "Script Table As...CREATE" to get the structure, run that on the target server. 在源服务器上,使用“Script Table As ... CREATE”获取结构,在目标服务器上运行该结构。

  2. On the target server, create a bcp format file using your newly-created table: 在目标服务器上,使用新创建的表创建bcp格式文件:

     bcp database.owner.table format nul -f table.fmt -n bcp database.owner.table格式为nul -f table.fmt -n 

    (If you're not using Windows auth, you may need the -U and -P options to specify username and password.) (如果您没有使用Windows身份验证,则可能需要-U-P选项来指定用户名和密码。)

  3. Copy that format file to the source server (if necessary). 将该格式文件复制到源服务器(如有必要)。

  4. Export the data to file on the source server: 将数据导出到源服务器上的文件:

     bcp database.owner.table out table.dat -f table.fmt bcp database.owner.table out table.dat -f table.fmt 

    (Again, possibly with -U and -P .) (同样,可能使用-U-P 。)

  5. Copy the data file to the target server (if necessary). 将数据文件复制到目标服务器(如有必要)。

  6. Import the data on the target server: 导入目标服务器上的数据:

     bcp database.owner.table in table.dat -f table.fmt table.dat -f table.fmt中的bcp database.owner.table 

    (Again, possibly with -U and -P .) (同样,可能使用-U-P 。)

In hopes that proves useful to someone else. 希望证明对别人有用。

不,你不能,但红门的SQL比较/数据比较等工具可以直接读取备份文件并将信息传输到实时数据库,处理SS2005上不兼容的任何语法或设置

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

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