RSS

Restoring File and FileGroups

08 Oct
  • Restoring file or filegroup restores enables you to restore a damaged file instead of restoring an entire database – minimizing the amount of recovery time needed.
  • If the damaged filegroup is not in your primary filegroup, then restoration of the damaged filegroup can be done while the otherfiles or filegrops are online.
  • By default, when a databae is online.then a filegroup restore will be an online operation. the file group that is being restored will remain offline until restoration is complete.

Execute the RESTORE DATABASE statement to restore the file and filegroup backup, specifying:

  • The name of the database to restore.
  • The backup device from where the full database backup will be restored.
  • The FILE clause for each file to restore.
  • The FILEGROUP clause for each filegroup to restore.
  • The NORECOVERY clause. If the files have not been modified after the backup was created, specify the RECOVERY clause.
  • If the files have been modified after the file backup was created, execute the RESTORE LOG statement to apply the transaction log backup, specifying
  • The name of the database to which the transaction log will be applied.
  • The backup device from where the transaction log backup will be restored.
  • The NORECOVERY clause if you have another transaction log backup to apply after the current one; otherwise, specify the RECOVERY clause.
  • The transaction log backups, if applied, must cover the time when the files and filegroups were backed up until the end of log (unless ALL database files are restored).

This example restores the files and filegroups for the MyNwind database. Two transaction logs will also be applied, to restore the database to the current time.

USE master
GO
-- Restore the files and filesgroups for MyNwind.
RESTORE DATABASE MyNwind
   FILE = 'MyNwind_data_1',
   FILEGROUP = 'new_customers',
   FILE = 'MyNwind_data_2',
   FILEGROUP = 'first_qtr_sales'
   FROM MyNwind_1
   WITH NORECOVERY
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


Source:
http://msdn.microsoft.com/en-us/library/ms178099.aspx
Pro SQL Server 2008 Administration - Ken Simmons and Sylvester Carstarphen
 

Leave a comment