WITH NORECOVERY, STOPAT = 'Oct 26, 2005 11:00 PM'
WITH RECOVERY, STOPAT = 'Oct 26, 2005 11:00 PM'
C:\SQLServer\Data C:\SQLServer\Logs C:\SQLServer\Backups
CREATE DATABASE [FGRestoreTEST] ON PRIMARY ( NAME = N'FGRestoreTEST', FILENAME = N'C:\SQLServer\Data\FGRestoreTEST.mdf' , SIZE = 5120KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ), FILEGROUP [FG2010] ( NAME = N'FG2010', FILENAME = N'C:\SQLServer\Data\FG2010.ndf' , SIZE = 5120KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ), FILEGROUP [FG2011] ( NAME = N'FG2011', FILENAME = N'C:\SQLServer\Data\FG2011.ndf' , SIZE = 5120KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ), FILEGROUP [FG2012] ( NAME = N'FG2012', FILENAME = N'C:\SQLServer\Data\FG2012.ndf' , SIZE = 5120KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ), FILEGROUP [FG2013] ( NAME = N'FG2013', FILENAME = N'C:\SQLServer\Data\FG2013.ndf' , SIZE = 5120KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ), FILEGROUP [FG2014] ( NAME = N'FG2014', FILENAME = N'C:\SQLServer\Data\FG2014.ndf' , SIZE = 5120KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ) LOG ON ( NAME = N'FGRestoreTEST_log', FILENAME = N'C:\SQLServer\Logs\FGRestoreTEST_log.ldf' , SIZE = 2048KB , MAXSIZE = 2048GB , FILEGROWTH = 10%) GO
USE [FGRestoreTEST]; GO CREATE TABLE [PRIMARY_TABLE] (ID INT, NAME CHAR(4)) ON [PRIMARY]; CREATE TABLE [FG2010_TABLE] (ID INT, NAME CHAR(4)) ON [FG2010]; CREATE TABLE [FG2011_TABLE] (ID INT, NAME CHAR(4)) ON [FG2011]; CREATE TABLE [FG2012_TABLE] (ID INT, NAME CHAR(4)) ON [FG2012]; CREATE TABLE [FG2013_TABLE] (ID INT, NAME CHAR(4)) ON [FG2013]; CREATE TABLE [FG2014_TABLE] (ID INT, NAME CHAR(4)) ON [FG2014]; GO
INSERT INTO [PRIMARY_TABLE] SELECT 1, 'TEST' GO 100 INSERT INTO [FG2010_TABLE] SELECT 1, 'TEST' GO 100 INSERT INTO [FG2011_TABLE] SELECT 1, 'TEST' GO 100 INSERT INTO [FG2012_TABLE] SELECT 1, 'TEST' GO 100 INSERT INTO [FG2013_TABLE] SELECT 1, 'TEST' GO 100 INSERT INTO [FG2014_TABLE] SELECT 1, 'TEST' GO 100
ALTER DATABASE [FGRestoreTEST] MODIFY FILEGROUP [FG2010] READ_ONLY; ALTER DATABASE [FGRestoreTEST] MODIFY FILEGROUP [FG2011] READ_ONLY; ALTER DATABASE [FGRestoreTEST] MODIFY FILEGROUP [FG2012] READ_ONLY; ALTER DATABASE [FGRestoreTEST] MODIFY FILEGROUP [FG2013] READ_ONLY; GO
USE [master]; GO BACKUP DATABASE [FGRestoreTEST] TO DISK = N'C:\SQLServer\Backups\FGRestoreTEST.BAK'; GO
RESTORE DATABASE [FGRestoreTEST_Dev] FROM DISK = N'C:\SQLServer\Backups\FGRestoreTEST.BAK' WITH MOVE 'FGRestoreTEST' TO 'C:\SQLServer\Data\FGRestoreTEST_Dev.mdf', MOVE 'FG2010' TO 'C:\SQLServer\Data\FG2010_Dev.ndf', MOVE 'FG2011' TO 'C:\SQLServer\Data\FG2011_Dev.ndf', MOVE 'FG2012' TO 'C:\SQLServer\Data\FG2012_Dev.ndf', MOVE 'FG2013' TO 'C:\SQLServer\Data\FG2013_Dev.ndf', MOVE 'FG2014' TO 'C:\SQLServer\Data\FG2014_Dev.ndf', MOVE 'FGRestoreTEST_log' TO 'C:\SQLServer\Logs\FGRestoreTEST_Dev_log.ldf', RECOVERY,STATS=5; GO
--http://msdn.microsoft.com/en-us/library/ms189906.aspx BACKUP DATABASE [FGRestoreTEST] FILEGROUP = 'PRIMARY' TO DISK = 'C:\SQLServer\Backups\FGRestoreTEST_PRIMARY.bak'; BACKUP DATABASE [FGRestoreTEST] FILEGROUP = 'FG2010' TO DISK = 'C:\SQLServer\Backups\FGRestoreTEST_FG2010.bak'; BACKUP DATABASE [FGRestoreTEST] FILEGROUP = 'FG2011' TO DISK = 'C:\SQLServer\Backups\FGRestoreTEST_FG2011.bak'; BACKUP DATABASE [FGRestoreTEST] FILEGROUP = 'FG2012' TO DISK = 'C:\SQLServer\Backups\FGRestoreTEST_FG2012.bak'; BACKUP DATABASE [FGRestoreTEST] FILEGROUP = 'FG2013' TO DISK = 'C:\SQLServer\Backups\FGRestoreTEST_G2013.bak'; BACKUP DATABASE [FGRestoreTEST] FILEGROUP = 'FG2014' TO DISK = 'C:\SQLServer\Backups\FGRestoreTEST_FG2014.bak'; GO
USE [FGRestoreTEST]; GO INSERT INTO [PRIMARY_TABLE] SELECT 1, 'TEST' GO 100 TRUNCATE TABLE [FG2014_TABLE]; GO
BACKUP DATABASE [FGRestoreTest] FILEGROUP = 'PRIMARY' TO DISK = 'C:\SQLServer\Backups\FGRestoreTest_PRIMARYDIFF.bak' WITH DIFFERENTIAL; BACKUP DATABASE [FGRestoreTest] FILEGROUP = 'FG2014' TO DISK = 'C:\SQLServer\Backups\FGRestoreTest_FG2014DIFF.bak' WITH DIFFERENTIAL; GO
USE [FGRestoreTEST]; GO INSERT INTO [PRIMARY_TABLE] SELECT 1, 'TEST' GO 100 INSERT INTO [FG2014_TABLE] SELECT 1, 'NEW' GO 300
USE [master]; GO BACKUP LOG [FGRestoreTEST] TO DISK = 'C:\SQLServer\Backups\FGRestoreTest_LogBackup.trn'; GO
BACKUP LOG [FGRestoreTEST_Dev] TO DISK = 'C:\SQLServer\Backups\FGRestoreTest_TailLogBackup.trn' WITH NORECOVERY; GO
--http://msdn.microsoft.com/en-us/library/aa337540.aspx --Restore primary filegroup RESTORE DATABASE [FGRestoreTEST_Dev] FILEGROUP = 'PRIMARY' FROM DISK = 'C:\SQLServer\Backups\FGRestoreTEST_PRIMARY.bak' WITH NORECOVERY; GO --Restore FG2014 filegroup RESTORE DATABASE [FGRestoreTEST_Dev] FILEGROUP = 'FG2014' FROM DISK = 'C:\SQLServer\Backups\FGRestoreTEST_FG2014.bak' WITH NORECOVERY; GO
--Restore PRIMARY differential backup RESTORE DATABASE [FGRestoreTEST_Dev] FILEGROUP = 'PRIMARY' FROM DISK = 'C:\SQLServer\Backups\FGRestoreTest_PRIMARYDIFF.bak' WITH NORECOVERY; GO --Restore FG2014 differential backup RESTORE DATABASE [FGRestoreTEST_Dev] FILEGROUP = 'FG2014' FROM DISK = 'C:\SQLServer\Backups\FGRestoreTest_FG2014DIFF.bak' WITH NORECOVERY; GO
RESTORE LOG [FGRestoreTEST_Dev] FROM DISK = 'C:\SQLServer\Backups\FGRestoreTest_LogBackup.trn' WITH NORECOVERY; GO
RESTORE DATABASE [FGRestoreTest_DEV] WITH RECOVERY; GO
USE [FGRestoreTEST_Dev]; GO SELECT COUNT(*) AS [PRIMARY_TABLE] FROM [PRIMARY_TABLE]; SELECT COUNT(*) AS [FG2010_TABLE] FROM [FG2010_TABLE]; SELECT COUNT(*) AS [FG2011_TABLE] FROM [FG2011_TABLE]; SELECT COUNT(*) AS [FG2012_TABLE] FROM [FG2012_TABLE]; SELECT COUNT(*) AS [FG2013_TABLE] FROM [FG2013_TABLE]; SELECT COUNT(*) AS [FG2014_TABLE] FROM [FG2014_TABLE]; SELECT TOP (1) * FROM [FG2014_TABLE]; GO