Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


January 28, 2008

Express Essentials: Restoring Your Databases

RSS
Subscribe to Windows IT Pro | See More Backup and Recovery Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Although backups are an essential part of data protection, as I explained in "Backing Up Your Databases" at http://www.sqlmag.com/articles/index.cfm?articleid=98130, they are only half the story. The other half lies in the ability to restore the backups you've made--after all, what good is a backup if you can’t restore it?

If you’re doing simple full backups every night, the restore process is quite straightforward. You just use the T-SQL RESTORE DATABASE command with your last full backup to perform the restore. When the restore is finished, you’re good to go. For example, to restore a backup of the Northwind database, you'd use the code

RESTORE DATABASE Northwind
	FROM DISK = 'C:\BACKUPS\Northwind_Full.bak'
	WITH RECOVERY, REPLACE

where C:\BACKUPS\Northwind_Full.bak is the path to your most recent full backup of the database. Remember that the RESTORE DATABASE command returns your database to the state it was in at the time you performed the backup that you're restoring; any subsequent activity will need to be redone. If you’re running Windows Vista, you must also remember to use the Run as Administrator option when you do the restore so that you have the authority necessary to restore the database.

If you use transaction-log backups, you'll lose less data, of course, but the restore process is a bit more involved. First you need to restore the last full database backup. However, because you’ll subsequently restore transaction logs, you must use the RESTORE DATABASE command's NORECOVERY option:

RESTORE DATABASE Northwind
	FROM DISK = 'C:\BACKUPS\Northwind_Full.bak'  
	WITH NORECOVERY, REPLACE

The NORECOVERY clause tells SQL Server Express that you'll be performing subsequent restore operations. SQL Server Express does not allow the restored database to be used until you've performed the final restore, which you indicate by using the RECOVERY clause.

After you've restored your database backup, you’ll restore your transaction-log backups one at a time, in the order in which they were created. For all but the last transaction log, use the RESTORE LOG command with the NORECOVERY option:

RESTORE LOG Northwind
FROM DISK = 'C:\BACKUPS\Northwind_Log1.bak'
WITH NORECOVERY

When you restore the final transaction log, use the WITH RECOVERY option so that the database will be usable after you complete the restore process:

RESTORE LOG Northwind
FROM DISK = 'C:\BACKUPS\Northwind_Log2.bak'
WITH RECOVERY

This code assumes that you've performed transaction-log backups of the Northwind database to the files C:\BACKUPS\Northwind_Log1.bak and C:\BACKUPS\Northwind_Log2.bak. Restoring transaction logs returns your database to the state it was in when you backed up the final transaction log.

When discussing database backup and restore, it's important to remember that if your database backup contains sensitive data, you need to keep the backup in a secure location. Also, if you’re backing up to disk to protect against disk failure, save your backup to a drive other than the one that holds your SQL Server Express data and log files.

End of Article



Reader Comments

You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

WinInfo Short Takes: 4th of July Special Edition

An often irreverent look at some of the week's other news, including a shortened work week thanks to the 4th of July, expensive Windows 7 pricing, Bing's modest monthly gains, IE 8 heading to work, Steve Jobs back at Apple, and so much more ...

Google Wave Emulates Trends of Changing World

As collaboration continues to increase, the world and how individuals view information is evolving. What does that mean for IT? ...


Related Events WinConnections and Microsoft® Exchange Connections

DevConnections, Microsoft® ASP.NET Connections, SharePoint Connections and SQL Server Connections

SQL Server Unleashed EMEA

Check out our list of Free Email Newsletters!

SQL Server and Database eBooks Safeguarding Your Windows Servers

SQL Server Administration for Oracle DBAs

Taking Control: Monitoring the Windows Platform Proactively

Related SQL Server and Database Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format

Test Drive IT Solutions and Get Free Music Downloads
Solve your toughest IT problems with these free downloads and receive 5 free music downloads!


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home asp.netPRO Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement | Reprints and Licensing