简体   繁体   English

将分区数据库还原到多个文件组

[英]Restore Partitioned database into multiple filegroups

I need to restore a partitioned database that has multiple file groups. 我需要还原具有多个文件组的分区数据库。 In the restore option in the SSME I need to edit manually all the path of the filegroups restore as option it little bit tedious as it having more than 150 filegroups 在SSME的restore选项中,我需要手动编辑文件组的所有路径,将其还原为选项有点繁琐,因为它具有150多个文件组

eg:USE master
GO
-- First determine the number and names of the files in the backup.
RESTORE FILELISTONLY
   FROM MyNwind_1
-- Restore the files for MyNwind.
RESTORE DATABASE MyNwind
   FROM MyNwind_1
   WITH NORECOVERY,


      MOVE 'MyNwind_data_1' TO 'D:\MyData\MyNwind_data_1.mdf', 
       MOVE 'MyNwind_data_2' TO 'D:\MyData\MyNwind_data_2.ndf'

GO
-- Apply the first transaction log backup.
RESTORE LOG MyNwind
   FROM MyNwind_log1
   WITH NORECOVERY
GO
-- Apply the last transaction log backup.
RESTORE LOG MyNwind
   FROM MyNwind_log2
   WITH RECOVERY
GO

Here I need to specify multiple MOVE commands for all my filegroups, this is a tedious task when having 100s of filegroups 在这里,我需要为我的所有文件组指定多个MOVE命令,当有100个文件组时,这是一个繁琐的任务

   MOVE 'MyNwind_data_1' TO 'D:\MyData\MyNwind_data_1.mdf', 
           MOVE 'MyNwind_data_2' TO 'D:\MyData\MyNwind_data_2.ndf'

I need to move the files into the path I provided as a parameter. 我需要将文件移到作为参数提供的路径中。

You could generate the MOVE list with a query like: 您可以使用以下查询生成MOVE列表:

select 'MOVE ''' + name + ''' TO ''D:\MyData\' + name + '.mdf'','
from sys.filegroups

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

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