This action might not be possible to undo. Are you sure you want to continue?
Pagina 1 di 6
United States - English http://technet.microsoft.com/en-us/magazine/cc296584.asp~~~mic
Current Issue [ http://technet.microsoit.com/en-us/magazine/hh307891.aspx I TechNet Magazine [ http://technet.microsoit.com/en-us/magazine/ee721042.aspx I > Home [http://technet.microsoit.com/enus/magazine/ee721042.aspx I > Issues[http://technet.microsoit.com/en-us/magazine/bb978517.aspx I > 2009 [http://technet.microsoit.com/enus/magazine/dd353269.aspx I > November [ http://technet.microsoit.com/en-us/magazine/ee835503.aspx I > TechNet Magazine
SQL Server Disaster Recovery
Software Platform Fully IntegrateCl8liarePoi ntInfrastructure Management
SQL Server: Recovering from Disasters Using Backups
Paul S. Randal
T here isn't
much point taking SQL Server backups unless you know how to restore them. If you more complicated than just a full database backup, you're going to need to know restore your database to the desired point in time . database layout or a complex backup strategy or take advantage of
some RESTORE options to be able to successfully
This is even more the case if you have a complicated partial database availability. As long as you have an effective Objective
and you want to be able to restore, for example, a single file or filegroup, backup strategy
Everything to, Know About
and your backups are valid, you should be able to (RTO) and to your Recovery Point series, I discussed the various types of backups
recover from a disaster within your Recovery Time Objective (RPO). In the first article in this three-part
\'Vindows PowerS hell
By Jeffrey Hicks
Microsoft MVP, MCSE. MCSA, MCT __ ~
and how to formulate a backup strategy (see "Understanding SQL Server Backups" [ http://technet.microsoft.com/en-us/magazine/dd939132.aspx
the July 2009 issue). restore such
In this article, I'll explain how restore works and how to perform some of the more common operations. mentioned
It will be helpful if you've read the backup article, and the background material I in that article's introduction. I'm also going to explain a few more tricky operations, restore and an online piecemeal
as doing a point-in-time
restore with partial database availability.
Just as in the previous article on BACKUP, I'm not going to explain how the RESTORE syntax works or go through the specific steps of all restore operations. SQL Server Books Online does an excellent job of that. See "RESTORE (Transact-SQL) [ http://msdn.microsoft.com/enus/library/ms186858.aspx
Tip of the Day [http://technet.microsoft
Understand and Use the Exchange Control Panel [ http://technet.microsoft.com/magazine/b0856fbC -gee4-45a7-9f2c-2af99593a9aO.aspx I Get an overview of the Exchange Control Panel and how you can use it to manage Exchange from just about anywhere.
for more info, especially the examples spread throughout
There are actually so many options to RESTORE that it's a whole other topic to explain them! "Backing Up and Restoring How-to Topics (SQL Server Management Studio) [ http://msdn.microsoft.com/en-us/library/ms186858.aspx perform restores.
how to use the tools to
The Four Phases of Restore
Let's start with how restore actually works. A restore operation has up to four phases:
TechNet ON: Previous Issues
SQL Azure: Cloud Database Security (July 25, 2011) [ http://technet.microsoft.com/enus/magazine/hh352139.aspx I Deploy Windows 7 Your Way (July 11, 2011) [ http://technet.microsoft.com/enus/magazine/hh273489.aspx I System Center 2012 Deep Dive (June 27, 2011) [ http://technet.microsoft.com/enus/magazine/hh320997.aspx I • Windows Phone 7: Managing Mobility (June 13,2011) Integrate It All with Windows Server (May 30,2011) Best of TechEd 2011 (May 16, 2011) Build and Manage VMs in the Cloud (May 2, 2011) Lync Every Office (Apr 18,2011) Manage Progress with Project Server (Apr 4, 2011) Refresh Your IT SKills for the Cloud (Mar 21, 2011) Remove Desktop Deployment 14,2011) Stress (Mar
1. File creation and initialization
2. Data and/or transaction 3. REDO phase of recovery 4. UNDO phase of recovery One of the primary goals of disaster recovery is to bring the database online as quickly as possible. If your disaster-recovery plan involves restoring backups (instead of, say, failing over to a database mirror), you're going to want the restore process to be as fast as possible. With each of the four restore steps in mind, is there anything you can do to speed them up? The first step can be essentially skipped if the data and log files already exist. This means that if you're going to overwrite an existing database, don't drop the database before doing the restore. Instead, use the WITH REPLACE option on the first restore operation to tell SQL Server to use the existing files. If the files don't exist, they will be created and then initialized. Creating the files is very fast, but the process of zero-initializing them can be very slow. You can enable instant file log copy
For security reasons, and by default, all database files are zero-initialized.
initialization for the SQL Server instance, which skips the zeroing process for data file create and grow operations, including those required during a restore -- possibly saving hours of downtime, even if the data files are only gigabytes in size. Transaction log itself. log files are always zero-initialized because of the circular nature of the transaction
You can read more about all of this, with references to Books Online, in my "Instant Initialization" category. You may be wondering about the second phase -- why does the item say "and/or transaction log"? If you read the previous article, you'll remember that all full and differential backups also include some transaction log records, to enable the database to be restored to a transactionally consistent point in time. Phase two is a pure copy operation -- no processing of the data is performed -- so the main way to speed this up is to have a better-performing I/O subsystem. This is one of the few times when it's acceptable to "throw hardware at the problem." [ http://sqlskills.com/BLOGS/PAUL/category/lnstant-Initialization.aspx
• Windows Azure Security Essentials (Feb 21, 2011) Go Virtual to Cut Costs and Carbon (Feb 7, 2011) System Center in the Cloud (Jan 24, 2011)
You can find more information Performance in the Books Online topic "Optimizing Backup and Restore ".aspx?vid=78] and listen to a TechNet Radio interview from earlier this year where I discuss database corruption (direct download links are here [ http://sqlskills. 2010) Internet & Intranet with SharePoint (Nov 29. it can be very difficult to figure out what needs to be restored and from what point in time. I discussed a solution for this in the previous article -.the more complex it can be the more time that passes before you are made aware of the problem to recover.com/emea/teched2008/itpro/tv/default. This can vastly reduce the time it takes to restore the database.microsoft.aspx 14/08/2011 . You might get lucky using standard reports from the default trace where the DDL operation is still available or the DELETE statement was caught by your own logging -.com/BLOGS/PAUL/post/TechNet-Radio-interview).2010) SQL Server 2008 R2 Migration 2010) Virtualization (Oct 18. but at the expense of a slightly more complicated backup strategy.com/feeds/f. page checksum failures or a tornpage detection error).microsoft. but you can watch a 2008 titled "Corruption ". and can be used in a restore operation database backup.2010) Green IT (July 6.aspx] ".02. as a first step if the database is running in the FULL recovery model and the transaction undamaged. An explanation of consistency checking is beyond the scope of this article.2010) Best Practices (Sept 20. of what What Are You Able to Restore? is to restore the fewest possible backups.to a point in time a week ago.microsoft. Desktop Security Primer (Oct 4. 2010) SharePoint Workflows and Productivity 26. as I'll explain later. I explained the details of recovery in the February 2009 article "Understanding Logging and Recovery in SQL Server [ http://technet. that page-read errors occurred (for instance. Simply put. Accelerating Windows 7 Deployments 1.com/en-us/magazine/ee677581(printer). log files. there's only one restore option -. losing all work since then. include: database (for instance. as I discussed in the previous article. This "final" transaction log backup will have everything up until the time of the disaster and can be used to bring the database being restored as far as possible.microsoft. For storage media failure. In a nutshell. the longer the restore will take. 2010) General IT. Skills Curriculum (Aug 23. http://technet.com/subscriptio Database tables (or data from them) are often accidentally or careless Transact-SQL statements server" scenario).2010) Building BI into Your Organization 2010) (Nov 15.com/ff819857. (Nov transactionally consistent point in time. 2010) Cloud Security (June 14.com/enus/cc543196. you need to work out what you have to restore.com/enus/magazine/2009.com/subscriptio pv=36:137] • See the entire list.aspx] Disasters are not limited to I/O subsystem applications Become a subscriber today [ http://technet. through You can ascertain the damage by looking through the SQL Server error log for notifications that file (s) are inaccessible.. 2010) [ http://technet.aspx] to the entire data file and it was damaged). database. Phases three and four are about running recovery on the transaction log to bring the database to a Maximizing Windows Server 2008 (Dec 13. MSDN Magazine [ http://msdn. So.com/subscriptio pv=36:350] • Internet Explorer 8 [ http://technet. at the expense of a small amount of CPU resources. or the database was a Resources TechNet Flash Newsletter [ http://technet.microsoft. Note that phase four is optional. of the copy phase are reading from the backup media and writing technology. for instance.com/enus/magazine/default.aspx] What Do You Need to Restore? as this is When disaster strikes.. operation If damage occurred.com/subscriptio pv=36:342] • Windows Server 2008 R2 [ http://technet. whatever was storing the database was destroyed. while also allowing you to meet your RPO.com/enus/aa570311. This means that if. especially if no one owns up to making the mistake.microsoft. [ http://technet.social. such as: • Windows 7 [ http://technet. of a multi-filegroup filegroup.microsoft.adding differential A differential transactions backups into a full-plus-log backup strategy. deleted by poorly programmed realize I was on the production (the "I didn't on-database-corruption. the first thing you need to do is work out what has been damaged. the longer you wait to recover -. you have a full database backup from a week ago and hourly transaction log backups since then. Suffice it to say that the more transaction log that needs to be recovered during a restore.SQL server: recovering from Disasters Using Backups Pagina 2 di 6 The other way to speed up the copy phase is to use some kind of backup compression either native to SQL Server 2008 or through one of the various third-party solutions. the possibilities Damage single Damage Damage Damage Damage going to dictate the actions you must take to recover from the disaster. If The two parts • Security and Management 10. or server failures -.microsoft. The aim of any restore operation is as fast as possible and completes The main question to ask here is "What backups do I have?" If the only backup you have is a full database backup from a week ago and the whole database has been lost. Then it becomes a question you are able to restore. Not a TechNet Subscriber? video of a presentation I made at the Tech-Ed IT Forum in November Survival Techniques [http://www. In such cases. possibly up-tothe-minute. I'll discuss recovering from this situation in more detail later.2011) Converge (Jan out to the data and/or you can do fewer reads (using compressed backup media).but often there's no record of who did what to the database.microsoft. perform a tail-of-the-Iog backup to ensure that all transactions log is up to the point of the disaster are backed up.microsoft.logging.there's also human error to consider.com/en-us/library/ms190954. the database.microsoft. to a single to a single to a single spread filegroup file of a multi-file page in the database. your backup strategy should always ensure that you are able to restore what you need to in the event of a disaster.or -. so the restore operation within your RTO. Regardless of who performed the accidental data deletion or when it happened.microsoft. you can speed up the overall process. it is usual to get an idea of how pervasive practice to run the DBCC CHECKDB consistency-checking the damage is.2010) Silverlight @ Work (Sep 6. in SQL Server [ http://msdn. 2010) Office & Share Point 2010 Deployment Guide (June 28.com/su bscriptions/buj and get early access to thousands of Microsoft products.microsoft. 2010) Email in the Cloud (Aug 9.microsoft. the restore process will essentially replay all the transactions from the last week before completing. or that general corruption was encountered.aspx ] (July database backup contains all the datafile pages that have changed since the last full to avoid having to replay all the that occurred in the period between the full database backup and the differential database backup.aspx] MSDN Flash Newsletter [ http://msdn.aspx] TechNet News Feed [ http://services.
L7 and L8). unless the previous full database backup is database backup Dl is deleted very If the differential as soon as D2 completes. differential and transaction log log backups. This is possible only as long as backups Dl. time than all the previous transaction Primary II nclud II 8!. This will display the contents of the backup file's header. the database will not be recoverable.com/en-us/magazine/ee677581(printer). because the differential database backup D2 brings the database to a more recent point in log backups. If a system crash occurs and the data files are damaged. then it's up to you. In this case. L5. up' to the time of '" !'ille1 jl"ttle2 <= IFill e . you can find out what a backup file contains using the RESTORE HEADERONLY command. type of backup.com/en-us/library/ms188653. and depends on the backup strategy you have and how much disk space is required. If a single transaction log backup from the was taken. date and time so that the backup can be identified at a glance. es . you can query that various backup history tables in the msdb database. L6. the shortest and fastest restore sequence is the most recent full database backup (F). up rc the ttme cf the dieasten I nctud Figure 2: Restore Sequence with a Damage Differential Database BackUp In this scenario.che nges from t. unneeded transaction log backups to be restored. essentially the meta data that describes the backup itself. The restore sequence may be as simple asjust one full backup (of a database. or a complicated set of full. then the scenario in Figure 2 will not be possible.3 Log the disaster. you are trying to work out the restore sequence to use to restore the damaged or deleted data. the shortest and fastest restore sequence is the most recent full database backup (F). If you haven't done this. As far as the backups themselves are concerned. These tables contain a record of all backups that have been taken in the SQL Server instance since the last time the backup history tables were cleared out.aspx 1 ". if the full database backup F is damaged. a restore sequence is finding the earliest required One of the tricky problems when planning transaction log backup to restore (sometimes called finding the "minimum-LSN. the next most recent differential database backup (Dl. In the example in Figure 1. For instance. the most recent differential database backup (D2). otherwise you could run into problems during a disaster. che nges from IL.Continuing my example. A restore sequence is a set of backups that must be restored and the appropriate order in which to restore them. differential or file). don't immediately delete previous backups as soon as a rid new one is taken. it's best to keep at least one or two complete cycles of backups before getting of older backups. It is important that you do not delete backups too soon. This raises the question of "When should you delete your previous backups?" The answer is definitely "It depends!" If you don't have a legal obligation to keep your backups around for a certain length of time. and the restore sequence will involve all transaction log backups since the full database backup -. up to and including the tail-of-the-Iog backup (L7 and L8).a potentially long restore sequence. but they will not be used and essentially just waste disaster-recovery time. filegroup backups. For transaction log backups. and then all subsequent transaction log backups. Ideally. Using either method. imagine a scenario where the backup strategy database and transaction involves full database.aspx 14/08/2011 .microsoft.microsoft. You can read more in the Books Online topic "Viewing Information About Backups [ http://msdn. what is the restore sequence? Figure 1 illustrates this example.SQL server: recovering from Disasters Using Backups Pagina 3 di 6 So how can you determine what backups you have available? First. as that is the final fall-back http://technet. and then all subsequent transaction log backups (L4. still available. For instance." or "minimum-Log Sequence Number"). Regardless. you should test your backups before removing older ones. Figure 1: Example Restore Sequence SQL Server will allow previous. L5 and L6 are still available. what would happen if the differential database backup D2 was damaged or missing? Figure 2 shows this case. only transaction log backups L7 and L8 are required.). L4. it is a best practice to name backup files to include the database. in general you must have all of them since the last full database backup restore sequence.
com/en-us/magazine/ee677581(printer).the equivalent of using the WITH RECOVERY option on the RESTOREstatement. You must be very careful to use the right option. For instance. STOPAT = '2009-05-1701:45:00. but it keeps a note of what it did (in an "undo" file whose name and path you specify) and then allows read-only access to the database. unfortunately.bak' WITH REPLACE. although directly. is to run the UNDO phase of recovery -. an interesting option which kind of does that -. If you decide to continue.aspx Books 1 ". When restoring multiple backups. You can find more details on figuring out what you're able to restore in the comprehensive Online topic "Working with Restore Sequences for SQL Server Databases [ http://msdn. completes and there is something you need to be aware of if you're going to use RESTORE commands When a backup is restored. but you have the ability to continue with the restore sequence. In fact. State 1. verifying the integrity can't proceed past the gap. using the Transact-SQL example above. As each successive backup in the restore sequence is but the UNDO phase cannot be performed until the very last backup in the transaction log backup chain has been restored. the following backup cannot be restored because no files are ready to rollforward. You can do this through SQL Server Management Studio (SSMS) or through Transact-SQL. the REDO phase of recovery is always performed. Msg 3013. you may is restore. In that case you can use the WITH STOPAT option to prevent transaction log restore from going past the time you know the table was deleted. There are several ways to do this. GO RESTORE LOG DBMaint2008 FROM DISK = 'C:\SQLskills\DBMaint2008_Log_051709_0200. If the disaster you're recovering want to do a point-in-time from involves accidental deletion of a table. no further transaction log backups can be applied.there's no way to undo recovery once it's completed.microsoft. they all relate to the UNDO phase of recovery. Line 1 RESTORE LOG is terminating abnormally. NORECOVERY.bak' WITH NORECOVERY. you must be careful that each one specifies WITH NORECOVERY. I could use the following syntax on the second RESTORE LOG statement: RESTORE LOG DBMaint2008 FROM DISK = 'C:\SQLskills\DBMaint2008_Log_051709_0200. Here is some example Transact-SQL code to restore a full database backup and two transaction log backups. for instance. GO http://technet. but the most common where you want to restore the database but ensure that recovery does not proceed past a certain time.m. State 1.com/en-us/library/ms187486. Notice that I also used the CHECKSUM option on the restore of the full database backup to ensure as they are restored.CHECKSUM. Line 1 The log or differential on the first RESTORE statement. There is. the UNDO is reversed (using the contents of the undo file) and then the next transaction log file is restored. GO RESTORE LOG DBMaint2008 FROM DISK = 'C:\SQLskills\DBMaint2008_Log_051709_0100. error is that any page checksums present in the database being restored are verified If WITH NORECOVERY was not specified returned: Msg 3117.bak' WITH NORECOVERY. so all restores in the restore sequence must specify not to run the UNDO phase of recovery. and then manually complete recovery afterward. the safest way is to use the WITH NORECOVERY option on all restores in the restore sequence.000'. It works by running the UNDO phase of recovery. Example Restore Scenarios The most common restore scenario involves a full database backup and then one or more transaction log backups to bring the database forward in time.SQL server: recovering from Disasters Using Backups Pagina 4 di 6 transaction log backup "chain" is missing or damaged. there are three options for how the restore operation restored. The default. and then manually complete FROM recovery to bring the database online: RESTORE DATABASE DBMaint2008 DISK = 'C:\SQLskills\DBMaint2008_Full_051709_0000.the WITH STANDBY option. if I wanted to prevent the database from being restored past 1:45 a. the restore operation in the previous article. Level 16. This is because as soon as recovery is completed.aspx 14/08/2011 . This is useful in two database and for looking at scenarios: for allowing read-only access to a log-shipping secondary the contents of the database during the restore sequence.microsoft. As I mentioned of your backups is a key part of being able to restore successfully. This is the last of three options I mentioned earlier. Level 16.. however.bak' WITH NORECOVERY. GO RESTORE DATABASE DBMaint2008 GO WITH RECOVERY. The database is transactionally consistent. otherwise you risk having to start a long restore sequence again -.
d m_db_persisted_sku_featu res and adjust your disaster-recovery plan accordingly. but this feature allows a very large database to be split into separate filegroups for easier and faster recoverability. Windows on.microsoft. if not. if SQL may be added Agent jobs and DTSjSSIS The master database is different. that was the correct point in time and if you don't know what log backup with a time a few seconds later and so on. Server • instance . You may also find that your backup strategy does not allow you to recover within your business requirements. or maybe you forgot database encryption to back up the server certificate used to enable in SQL Server 2008. this is not an issue. maybe your log backups are accidentally overwriting transparent each other.microsoft. are some features Edition that. you need to practice to make sure you know what to do. can be found in the Books Online topic "RESTORE Arguments us/library/ms178615. you can dive into some of the Books Online and blog links for deeper information. but with a different make changes to elements and anything like DTS/SSIS packages. and with the same name. procedures may be missing. In SQL Server In SQL Server 2008.aspx?videoid=57] watching. application strings If the database is being restored on a different complicated: The SQL Server SQL log ins will be different packages or may not exist. instance on the same server.microsoft. You can tell whether any of these features are being used in the database using the DMV sys.com/BLOGS/PAUL/category/BackupRestore." data capture data encryption list is: Transparent Data compression Partitioning All of these require sysadmin privileges to enable except data compression. but it may be the only solution discussion of these and other options for the RESTORE statement (Transact-SQL) ". on an instance stored The SQL Server instance is being so there may be client connectivity server.microsoft. As you move further away from that scenario. and to have a set of scripts that will help identify what backups exist and the order in which to restore them. issues. I always like to say that this should be written team and tested by the most junior by the most senior DBA on the DBA -. restore the same transaction kind of operation time an operation A comprehensive took place. Considerations When Restoring to a Different Location The simplest restore scenario is when the database is being restored on the same SQL Server instance to which it is usually attached.com/en-us/magazine/ee677581(printer). This feature allows a multi-filegroup database to be online and available as long as at least the primary filegroup is online.com/mbpa65. you may need to plans. You can also find a lot of information on my blog [ http://sqlskills. You don't want to be learning the syntax for the RESTORE command during a high-pressure disaster-recovery situation. data in any offline filegroups can't be accessed. name restored so any user-defined will be different. everything If the database on a different security issues as Windows consideration accounts is the edition may be different. 2000 make the database "Enterprise-only" -. while the rest of the database is being used for processing. of SQL Server and they the database may be in a different is being restored One other used in the database. Tripp delivering a Tech-Ed EMEA session titled "SQL Server 2005 VLDB Availability and Recovery Strategies " that is well worth [ http://www. there are lots of facets of restore operations that I didn't have space to cover. the feature 2005. SQL Server 2005 SQL Server Technical Article titled "Microsoft Partial Database Availability" with some extensive examples available at tinyurl.it cannot be restored on a Standard (or lower) In SQL Server database Change and earlier. If the database is being restored on the same instance. The main takeaway I'd like you to gain from this article is that to successfully recover a database using backups.com/en- One of the coolest new features introduced in SQL Server 2005 Enterprise Edition was partial database availability.starting with the Backup/Restore By far the best way to prepare for disaster is to have a restore plan that lists the steps to go through. as long as the database has been architected You'll find an excellent. . This becomes very tedious. There's also a 75-minute recording of Kimberly L. There but there domain.aspx] ''. Maybe the backups take too long to restore. however. things get a lot more name. if table or index partitioning is used. Now that you know the basics.aspx 14/08/2011 .aspx] category. by a table owner. listed applies. will be different or may not exist. in-depth that way and the correct backups exist. The best place to start in Books Online is the topic "Restore and Recovery Overview (SQL Server) [ http://msdn. the is "Enterprise-only.aspx] [ http://msdn. Obviously. a single filegroup from a multi-filegroup database) online.com/emea/spotlight/sessionh. the aftermath of the restore operation becomes more complicated. Another Enterprise-only feature that was added is the ability to perform piecemeal restores (for instance. These two features combined enable some quite sophisticated and efficient restore scenarios. database maintenance that relies on a database name. thus potentially breaking a disaster-recovery plan involving which can be enabled restoring to a Standard Edition instance.SQL server: recovering from Disasters Using Backups Pagina 5 di 6 I could even combine STOPAT and STANDBY to see whether then.to ensure that everyone can follow the steps safely. http://technet.com/enus/library/ms191253. Dig Deeper Just as with the first article in the series on backups.
This action might not be possible to undo. Are you sure you want to continue?
We've moved you to where you read on your other device.
Get the full title to continue reading from where you left off, or restart the preview.