将数据库的文件组备份还原到同一服务器中的另一个现有数据库

时间:2013-11-13 12:07:07

标签: sql sql-server database-backups database-restore

我已经对SampleDB数据库进行了文件组备份,我想将其还原到另一个现有的空数据库RestoreDB。我能够恢复完整备份,但恢复文件组备份时遇到问题。

这是我到目前为止所尝试的内容。

RESTORE DATABASE RestoreDB
FROM DISK = 'D:\Sample\SampleDB_FileGroup.bak'
WITH    
    REPLACE,    -- Overwrite DB - if one exists
    NORECOVERY, -- Use if DIFFs / T/Logs to recover
--  RECOVERY,   -- Use if NO more files to recover, database will be set ready to use
    STATS = 10, -- Show progress (every 10%)
MOVE 'SampleDB' TO 'D:\Sample\RestoreDB\RestoreDB.mdf', 
MOVE 'SampleDB_2' TO 'D:\Sample\RestoreDB\RestoreDB_2.ndf',
MOVE 'SampleDB_log' TO 'D:\Sample\RestoreDB\RestoreDB_log.ldf'

使用上面的代码我能够恢复完整备份,但我无法恢复文件组备份。

关于如何实现这一目标的任何想法?

2 个答案:

答案 0 :(得分:0)

使用关键字PARTIAL还原所需的PRIMARY文件组和所有文件库,然后还原文件组。

RESTORE DATABASE RestoreDB
FROM DISK = 'D:\Sample\SampleDB_FileGroup.bak'
WITH    
    REPLACE,    -- Overwrite DB - if one exists
    NORECOVERY, -- Use if DIFFs / T/Logs to recover
    STATS = 10, -- Show progress (every 10%)
    MOVE 'SampleDB' TO 'D:\Sample\RestoreDB\RestoreDB.mdf', 
    MOVE 'SampleDB_2' TO 'D:\Sample\RestoreDB\RestoreDB_2.ndf',
    MOVE 'SampleDB_log' TO 'D:\Sample\RestoreDB\RestoreDB_log.ldf',
    PARTIAL

答案 1 :(得分:0)

我也试过了:

CREATE DATABASE [SampleDB] ON  PRIMARY 
( NAME = N'SampleDB', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\SampleDB.mdf' , SIZE = 3072KB , FILEGROWTH = 1024KB ), 
 FILEGROUP [FG2] 
( NAME = N'F2', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\F2.ndf' , SIZE = 3072KB , FILEGROWTH = 1024KB )
 LOG ON 
( NAME = N'SampleDB_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\SampleDB_log.ldf' , SIZE = 1024KB , FILEGROWTH = 10%)
GO

BACKUP DATABASE SampleDB
TO DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\BACKUP\backup1.bak' WITH INIT

BACKUP DATABASE SampleDB FILEGROUP = N'FG2'
TO DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\BACKUP\backup2.bak'

RESTORE DATABASE RestoreDB
FILEGROUP = N'PRIMARY'
FROM DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\BACKUP\backup1.bak'
WITH 
    MOVE N'SampleDB' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\RestoreDB.mdf',
    MOVE N'SampleDB_log' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\RestoreDB_log.ldf'    

RESTORE DATABASE RestoreDB
FILEGROUP = N'FG2'
FROM DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\BACKUP\backup2.bak'
WITH 
    MOVE N'F2' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\RestoreDB2.ndf'

但是我收到了一个错误:

  

提供的备份与数据库不在同一个恢复路径上,不符合用于在线文件还原的条件。

我不知道,因为从来没有这样做,但是不可能移动它,Paul Randal在这里回答这个问题:http://www.sqlservercentral.com/Forums/Topic412470-357-1.aspx