简体   繁体   中英

Restore file group backup of a database on to another existing database in same server

I have taken file group backup of SampleDB database and I want to restore it on to a different existing empty database RestoreDB . I was able to restore a full backup but I am having problem while restoring a file group backup.

Here is what i have tried so far.

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'

Using the above code I was able to restore a full backup but I am not able to restore a file group backup.

Any ideas on how to achieve this?

Use the keyword PARTIAL to restore the PRIMARY filegroup and all filegruops you need, then restore the filegroup.

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

I tried it also:

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'

But I get an error :

The supplied backup is not on the same recovery path as the database, and is ineligible for use for an online file restore.

I didn't know, because never had to do it, but it is not possible to move it, Paul Randal answers this one here : http://www.sqlservercentral.com/Forums/Topic412470-357-1.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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