Hi,I'm playing around with file group backups a bit. Want to see if we can get our backups smaller/faster.And also trying to get maint jobs faster.So the plan is, is to create a separate file group/s for some databases to which we can move our archive data too. These file groups will only change once a month. So only needs to be backup monthly.The problem is, is that I can't get my restore sequences right. (Really feel stupid to struggle with a trivial thing like this)Below is some scripts that I'm using - with comments (and questions within those comments)For this script to work you need to create a directory structure like this:C:\Temp\TempDatabases_Tests\BackupsC:\Temp\TempDatabases_Tests\ActivePartitionsC:\Temp\TempDatabases_Tests\ArchiveDataFirst get the database created for the test:[code="sql"]/* Drop and create a blank database to do checks on.*/use mastergoIF EXISTS(SELECT TOP 1 * FROM SYS.databases WHERE name ='TestDatabasePartialRestore')BEGIN ALTER DATABASE TestDatabasePartialRestore SET SINGLE_USER WITH ROLLBACK IMMEDIATE DROP DATABASE TestDatabasePartialRestoreENDIF NOT EXISTS (SELECT TOP 1 * FROM SYS.databases WHERE name ='TestDatabasePartialRestore')BEGIN -- Create the database using default values (for size, growth etc.) Also - add diffent filegroups so that we can test filegroup restores. CREATE DATABASE [TestDatabasePartialRestore] ON PRIMARY ( NAME = N'TestDatabasePartialRestore', FILENAME = N'C:\Temp\TempDatabases_Tests\ActivePartitions\TestDatabasePartialRestore.mdf' ), FILEGROUP [ActivePrimary] ( NAME = N'TestDatabasePartialRestore_ActivePrimary', FILENAME = N'C:\Temp\TempDatabases_Tests\ActivePartitions\TestDatabasePartialRestore_ActivePrimary.ndf'), FILEGROUP [ArchiveData] ( NAME = N'TestDatabasePartialRestore_ArchiveData', FILENAME = N'C:\Temp\TempDatabases_Tests\ArchiveData\TestDatabasePartialRestore_ArchiveData.ndf' ) LOG ON ( NAME = N'TestDatabasePartialRestore_log', FILENAME = N'C:\Temp\TempDatabases_Tests\ActivePartitions\TestDatabasePartialRestore_log.ldf')END[/code]Create some tables within the file groups:[code ="sql"]gouse TestDatabasePartialRestorego-- Check what file groups are available.select * from sys.filegroups/* SHOULD BE: PRIMARY ActivePrimary ArchiveData*/go-- Create two tables - one on ActivePrimary, and one on ArchiveDataCreate table tblActivePrimary( rID int identity ,SomeTextData varchar(100)) on [ActivePrimary]GOCREATE TABLE tblArchiveData( rID int Identity ,SomeTextData varchar(100))on [ArchiveData]go-- Shows that the tables are created in the correct Filegroups SELECT tbl.name as TableName ,fg.name as FileGroupName FROM sys.tables tbl INNER JOIN SYS.indexes si ON si.object_id = tbl.object_id INNER JOIN sys.filegroups fg ON fg.data_space_id = si.data_space_idGO-- Insert some dataINSERT INTO tblActivePrimary( SomeTextData)select 'Before BACKUP';go INSERT INTO tblArchiveData( SomeTextData)SELECT 'Before Backup';go GOSELECT SomeTextData FROM tblActivePrimarySELECT SomeTextData FROM tblArchiveData[/code]Do a Full backup:[code = "sql"]BACKUP DATABASE [TestDatabasePartialRestore]TO DISK = 'C:\Temp\TempDatabases_Tests\Backups\TestDatabasePartialRestore_MonthlyFullBackup.bak'[/code]Do some TX backups:[code = "sql"]/* Do the Hourly TX backups*/BACKUP log [TestDatabasePartialRestore]TO DISK = 'C:\Temp\TempDatabases_Tests\Backups\TestDatabasePartialRestorelog 1.trn'GOBACKUP log [TestDatabasePartialRestore]TO DISK = 'C:\Temp\TempDatabases_Tests\Backups\TestDatabasePartialRestorelog 2.trn'GOBACKUP log [TestDatabasePartialRestore]TO DISK = 'C:\Temp\TempDatabases_Tests\Backups\TestDatabasePartialRestorelog 3.trn'GO[/code]Do a full FileGroup backup on the active file group:[code="sql"]/* Full FILE GROUP BACKUP - This will be done weekly.*/BACKUP DATABASE [TestDatabasePartialRestore]filegroup = 'ActivePrimary'TO DISK = 'C:\Temp\TempDatabases_Tests\Backups\TestDatabasePartialRestore_ActivePrimary_Full.fbak'[/code]More TX Backups:[code = "sql"]/* More Tx backups*/BACKUP log [TestDatabasePartialRestore]TO DISK = 'C:\Temp\TempDatabases_Tests\Backups\TestDatabasePartialRestorelog 4.trn'BACKUP log [TestDatabasePartialRestore]TO DISK = 'C:\Temp\TempDatabases_Tests\Backups\TestDatabasePartialRestorelog 5.trn'[/code]Then lastly do a Diff FileGroup backup:[code = "sql"]BACKUP DATABASE [TestDatabasePartialRestore]filegroup = 'ActivePrimary'TO DISK = 'C:\Temp\TempDatabases_Tests\Backups\TestDatabasePartialRestore_ActivePrimary_Diff.fdif'WITH DIFFERENTIAL[/code]Ok so for my first test, I want to restore up to the Full FileGroup backup. [code = "sql]RESTORE DATABASE [TestDatabasePartialRestore_FullFileGroupRestore] FROM DISK = N'C:\Temp\TempDatabases_Tests\Backups\TestDatabasePartialRestore_MonthlyFullBackup.bak' WITH FILE = 1, MOVE N'TestDatabasePartialRestore' TO N'C:\Temp\TempDatabases_Tests\ActivePartitions\TestDatabasePartialRestore_FullFileGroupRestore.mdf',MOVE N'TestDatabasePartialRestore_ActivePrimary' TO N'C:\Temp\TempDatabases_Tests\ActivePartitions\TestDatabasePartialRestore_FullFileGroupRestore_ActivePrimary.ndf',MOVE N'TestDatabasePartialRestore_ArchiveData' TO N'C:\Temp\TempDatabases_Tests\ArchiveData\TestDatabasePartialRestore_FullFileGroupRestore_ArchiveData.ndf',MOVE N'TestDatabasePartialRestore_log' TO N'C:\Temp\TempDatabases_Tests\ActivePartitions\TestDatabasePartialRestore_FullFileGroupRestore_log.ldf',NORECOVERYRESTORE DATABASE TestDatabasePartialRestore_FullFileGroupRestoreFROM DISK = 'C:\Temp\TempDatabases_Tests\Backups\TestDatabasePartialRestore_ActivePrimary_Full.fbak' with recovery[/code]Running the code above, will restore the fileGroup backup BUT - it still needs the transaction log backups (all of them) before I can bring the database online...Why?What am I missing here?
↧