简体   繁体   English

使用 FullTextSearch 将数据库恢复到不同的数据库相同的服务器

[英]Restoring a DB with FullTextSearch To a Different DB same server

I need to make a copy of a production Database and restore it to a different database on the same production server.我需要制作生产数据库的副本并将其还原到同一生产服务器上的不同数据库。 I do not have a development SQL Server to practice on.我没有一个开发 SQL 服务器来练习。 The DB to be copied has Full Text Search enabled.要复制的数据库已启用全文搜索。 The problem I am encountering is the restore of the NDF has the same name as the Original production database.我遇到的问题是 NDF 的还原与原始生产数据库具有相同的名称。 This is shown below using SSMS.这在下面使用 SSMS 显示。

相同的 NDF 文件名

The ndf file has the same name. ndf 文件具有相同的名称。 It seems to contain a GUID as part of the name.它似乎包含一个 GUID 作为名称的一部分。 Whereas the mdf's and ldf's names use the database name.而 mdf 和 ldf 的名称使用数据库名称。

How do I restore the backup of the database to a different database on the same server without causing an error?如何将数据库的备份还原到同一服务器上的不同数据库而不导致错误?

Here is my attempt to do it in code.这是我尝试在代码中做到这一点。 Since I do not have a development server, will this work?由于我没有开发服务器,这可以吗?

USE [master]
Declare @newNDF as varchar(100) = 'E:\DATA\ftrow_FTC_titles{' + cast(NewID() as varchar(100)) +'}.ndf'

RESTORE DATABASE [Data]

FROM DISK = N'E:\Backup\Data_02 Aug 8 2022.bak' WITH FILE = 1, 

     MOVE N'Data_02' TO N'E:\DATA\Data.mdf', 
     MOVE N'Data_02_log' TO N'E:\DATA\Data_log.ldf',
     Move N'ftrow_FTC_titles{4E13037C-2F3F-49A3-B194-228F86A4F958}.ndf' to @NewNdf,
 NOUNLOAD,
 REPLACE,
 STATS = 5;
GO

Since SSMS uses the same file name in the restore, does this imply that there is only one ndf that services every database on this server?由于 SSMS 在还原中使用相同的文件名,这是否意味着只有一个 ndf 为该服务器上的每个数据库提供服务? Won't I get a File Name (ndf) in use error?我不会收到文件名 (ndf) 使用中的错误吗?

Can I just rename the NDF?我可以重命名 NDF 吗? Does it have to contain a GUID?它是否必须包含 GUID? If so how do I make that happen in SSMS?如果是这样,我如何在 SSMS 中实现这一点? Is it better to use Code as shown above?使用如上所示的代码更好吗?

Here is what worked for me.这对我有用。

  1. Used RESTORE FILESONLY to obtain the Logical Names (First part of each Move Line in restore) and Physical Name of the.ndf so it can be modified.使用 RESTORE FILESONLY 来获取 .ndf 的逻辑名称(恢复中每个移动线的第一部分)和物理名称,以便对其进行修改。 RESTORE FILELISTONLY FROM DISK = '\\SqlServerName\E$\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Backup\Data_02Aug_15_2022.bak
  2. Obtained new GUID for.ndf so the name does not conflict with existing database's.ndf.为.ndf 获得了新的 GUID,因此名称不会与现有数据库的.ndf 冲突。 Select newid() . Select newid()
  3. Ensured the new database did not exist on the server.确保服务器上不存在新数据库。 I had to delete it.我不得不删除它。
  4. Used the Restore below with the substituted GUID to perform the restore.使用下面的还原和替换的 GUID 来执行还原。

USE [master]使用 [主]

RESTORE DATABASE [Data]恢复数据库 [数据]

FROM DISK = N'\SQLServerName\E$\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Backup\Data_02Aug_15_2022.bak' WITH FILE = 1, FROM DISK = N'\SQLServerName\E$\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Backup\Data_02Aug_15_2022.bak' WITH FILE = 1,

 MOVE N'Data_02' TO N'E:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\Data.mdf', 

 MOVE N'Data_02_log' TO N'E:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\Data_log.ldf',

 Move N'ftrow_FTC_titles' to N'E:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\ftrow_FTC_titles{C5DFD204-0159-4EBD-945B-A31EB8672118}.ndf',

NOUNLOAD,名词加载,

REPLACE,代替,

STATS = 5;统计 = 5;

GO GO

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

相关问题 将复制的数据库还原到其他服务器上 - Restoring replicated DB onto a different server SQL Server 2005 - 在其他服务器上还原加密的数据库 - SQL Server 2005 - Restoring an encrypted DB on a different server SMO:恢复到不同的DB,为什么db为null? - SMO: restoring to a different DB, why db is null? 还原SQL Server数据库,替换现有数据库 - Restoring SQL Server DB, replacing the existing one 在Docker容器上还原SQL Server数据库时遇到问题 - Trouble restoring sql server DB on docker container SQL Server:通过链接服务器还原数据库-数据库间歇性地停留在还原状态(即使使用RECOVERY选项) - SQL Server: Restoring DB via linked server - Database intermittently stuck in restoring state (even with RECOVERY option) 在Sql Server 2012中还原数据库后如何正确运行查询? - How to run queries properly after restoring a db in Sql Server 2012? mssql_connect 不会连接同一个 SQL Server 上的不同数据库 - mssql_connect will not connect different DB on same SQL Server 使用sp_addlinkedserver访问同一服务器上的数据库-但使用不同的用户 - Using sp_addlinkedserver to access a db on the same server - but with a different user 将不同数据库表中的数据插入同一服务器中的另一个数据库 - Inserting data from different dbs table to another db in the same server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM