Restore Scenarios What to keep in mind Pedro A. Lopes PFE
Backup types Full Backup Differential Backup (Database or FG) Transaction Log Backup (Tail of the Log) Partial Backup (Piecemeal - Filegroup) Mirrored Backup (from 2005 onwards) Copy-only Backup (from 2005 onwards) 2
Restore The restore operation will depend on the strategy followed and the recovery model. Usually the restore operation consists of multiple backup files that are restored one after another to: Place a database in a particular state. Ensure recovery of the maximum amount of data. 3
Restore Types Full database restores Piecemeal restores (Using differential database or file restores) File or Filegroup restores. Page level restores (from 2005 onwards) Transaction log restores for point in time recovery Revert a database to the point in time captured by a database snapshot (from 2005 onwards)
Restore Steps Restoring a database file consists of two steps: Creating any missing database files. Copying the data from the backup devices to the database files. 5
Restore Steps (Cont.) Restoring a database or differential backup consists of four steps: Creating the database and transaction log files if they do not already exist. Copying all the data, log, and index pages from the backup media of a database to the database files. Applies the transaction log up to the recovery point (redo). If at this point, a database has uncommitted transactions then it starts recovery. The undo phase is part of the recovery phase. This rolls back any uncommitted transactions and makes the database available to users. After recovery, subsequent backups cannot be restored. 6
Restore Steps (Cont.) Applying a transaction log backup consists of: Copying data from the backup devices to the transaction log file. Start the redo phase, which applies the logged transactions to roll forward the data to the recovery point. This point in time is generally the last operation that was executed against the database. However you can select a different point: A transaction log backup contains a sequence of transactions identified by an LSNs. Transactions can also be explicitly named by placing a mark in the transaction log. 7
Restore - Comparison of RECOVERY and NORECOVERY Roll back is controlled by the RESTORE statement through the [RECOVERY NORECOVERY] options: NORECOVERY specifies that roll back not occur. In this case, the restore sequence can restore other backups and roll them forward. RECOVERY (the default) indicates that roll back should be performed after roll forward is completed for the current backup. 8
Restore You can restore a database to a particular LSN, named transaction, or point in time. STOPAT = { 'datetime' @datetime_var } STOPATMARK = { 'lsn:lsn_number' } [ AFTER 'datetime'] STOPBEFOREMARK = { 'lsn:lsn_number ' } [ AFTER 'datetime'] Usually used when restoring a database that has become corrupted, or a major change has to be rolled back. 9
Demo Marked Trans 10
Page Restore Restore damaged pages without restoring the whole database. Typically, pages candidates for restore are marked as "suspect" because of an error when accessing the page. Suspect pages are identified in the suspect_pages table in the msdb database. Useful if you have to restore no more than a few pages in a file. Syntax: RESTORE DATABASE database_name PAGE = 'file:page [,...n ]' [,...n ] FROM <backup_device> [,...n ] WITH NORECOVERY
Page Restore (Cont.) - Limitations Only database pages can be restored. Page restore cannot be used to restore the following: Transaction log Allocation pages: GAM, SGAM and PFS pages. Page 0 of all data files (the file boot page). Page 1:9 (the database boot page). Full-text catalog. If an individual page cannot be restored, you must use the existing full database backup or full file or filegroup backup.
Page Restore (Cont.) - Requirements A page restore is subject to the following requirements: Databases must be in full or bulk-logged recovery model. Pages in read-only filegroups cannot be restored. The restore sequence must start with a full, file, or filegroup backup. Requires an unbroken chain of log backups up to the current log file, and they must all be applied so that the page is brought up to date with the current log file. A database backup cannot be run at the same time.
Database Recovery Advisor The Database Recovery Advisor is a new SQL Server 2012 feature to easily allow SSMS users to do pointin-time database restore and Database Page restores from the GUI.
Database Recovery Advisor Although this improvement is called Database Recovery Advisor, these improvements are available via the Restore Database dialog and new Page Restore dialog. Available even if you don t have any msdb backup history.
Demo Recovery Advisor 16
Piecemeal Restore Allows partial database availability during restore, unlike in SQL 2000. Based on file / filegroup backup. Works with all recovery models, but is more flexible for the full and bulk-logged models. Supported only for databases with multiple filegroups. Filegroups must be recovered to a consistent point. All editions of SQL Server support offline piecemeal restores. In SQL Server 2005 Enterprise Edition and later versions, a piecemeal restore can be either online or offline.
Piecemeal Restore Starts with an initial restore sequence called the partial-restore sequence. Minimally, the partial-restore sequence restores and recovers the primary filegroup and, under the simple recovery model, all read/write filegroups. During the piecemeal-restore sequence, the whole database must go offline. Thereafter, the database is online and restored filegroups are available.
Piecemeal Restore scenarios Offline: Database is online after the partial-restore sequence. Filegroups that have not yet been restored remain offline, but they can be restored as you need them after taking the database offline. Simple RM supports this scenario only. Online: After the partial-restore sequence, the database is online, and the primary filegroup and any recovered secondary filegroups are available. Filegroups that have not yet been restored remain offline, but they can be restored as needed while the database remains online.
Piecemeal Restore of Database In this example, database is restored to a new computer after a disaster. Before the disaster, all the filegroups are online: Filegroups [Primary], [ONLINE_FG] and [RO_FG] are read/write. Filegroup [RO_FG] became read-only after the full file backup, which contains the primary filegroup and the read/write secondary filegroups. After filegroup [RO_FG] became read-only, a separate partial file backup of read-write filegroups was taken. After filegroup [RO_FG] became read-only, a separate file backup of filegroup [RO_FG] was taken.
Demo PiecMeal Restore 21
Questions? 22
Visit http://blogs.msdn.com/b/blogdo ezequiel/ for more insights on SQL Server. 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION