Logo
HOW TO
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
 
 
Windows Server

SQL server 2008 R2 : Reverting to a Database Snapshot for Recovery

7/25/2013 6:17:49 PM

If you have a database snapshot defined for a source database, you can use that snapshot to revert the source database to that snapshot’s point-in-time milestone. In other words, you consciously overlay a source database with the point-in-time representation of that database (which you got when you created a snapshot). You must remember that you will lose all data changes that occurred from that point-in-time moment and the current state of the source database. However, this may be exactly what you intend.

Reverting a Source Database from a Database Snapshot

Reverting is just a logical term for using the DATABASE RESTORE command with the FROM DATABASE_SNAPSHOT statement. It effectively causes the point-in-time database snapshot to become the source database. Under the covers, much of this is managed from the system catalog metadata level. However, the results are that the source database will be in exactly the same state as the database snapshot. When you use a database snapshot as the basis of a database restore, all other database snapshots that have the same source database must first be dropped. Again, to see what database snapshots may be defined for a particular database, you can execute the following query:

Use [master]
go
SELECT name,
       database_id,
       source_database_id, — source DB of the snapshot
       create_date,
       snapshot_isolation_state_desc
FROM sys.databases
Go

This query shows the existing source database and the newly created database snapshot, as follows:

name             database_id source_database_id  create_date  snapshot_isolation_
                                                                state_desc
----------------------------------------------------------------------------------
                                                                -------------
AdventureWorks             7       NULL         2009-02-17 23:37:02.763
                                                                OFF
SNAP_AdventureWorks_6AM   9          7         2009-12-05 06:01:36.597
                                                                ON
SNAP_AdventureWorks_12PM  10          7          2009-12-05 12:00:36.227
                                                                ON


					  

In this example, there are two snapshots against the AdventureWorks database. The one you don’t want to use when reverting must be dropped first. Then you can proceed to restore the source database with the remaining snapshot that you want. These are the steps:

1.
Drop the unwanted snapshot(s):

Use [master]
go
DROP DATABASE SNAP_AdventureWorks_12PM
   go

2.
Issue the RESTORE DATABASE command with the remaining snapshot:

USE [master]
go
RESTORE DATABASE AdventureWorks FROM DATABASE_SNAPSHOT =
'SNAP_AdventureWorks_6AM'
   go

When this process is complete, the source database and snapshot are essentially the same point-in-time database. But the source database quickly diverges, as updates begin to flow in again.

Using Database Snapshots with Testing and QA

Reverting to a “golden” copy of a database via a database snapshot is going to be popular going forward because of the simplicity that creating and reverting provides. Testing and QA groups will thrive on this feature, and this will directly affect the velocity of testing in your organization. With the increase in the frequency and stability of your testing and QA environments, a direct improvement in the quality of your application should be attainable. Essentially, these are the steps:

1.
Create the golden database snapshot before you run your testing:

Use [master]
go
CREATE DATABASE SNAP_AdventureWorks_GOLDEN
ON ( NAME = AdventureWorks_Data, FILENAME= 'C:\Program Files\
    Microsoft SQL Server\ MSSQL10.SQL08DE01\MSSQL\DATA\
              SNAP_AdventureWorks_data_GOLDEN.snap')
AS SNAPSHOT OF AdventureWorks
   Go

2.
Run tests or QA to your heart’s content.

3.
Revert to the golden copy when the testing is completed so that the process can be repeated again, regression testing can be run, stress testing can be done, performance testing can be started, or further application testing can be done:

USE [master]
go
RESTORE DATABASE AdventureWorks
FROM DATABASE_SNAPSHOT = 'SNAP_AdventureWorks_GOLDEN'
   go
Other -----------------
- SQL server 2008 R2 : Setup and Breakdown of a Database Snapshot
- Windows Home Server 2011 : Maintaining Windows Home Server - Checking Free Disk Space on the System Drive
- Windows Home Server 2011 : Maintaining Windows Home Server - Checking Your Hard Disk for Errors
- Windows Home Server 2011 : Maintaining Windows Home Server - Checking System Uptime
- HP ProLiant Servers AIS : How Memory Works
- HP ProLiant Servers AIS : Memory and Cache
- SQL Server 2008 R2 : A Performance Monitoring Approach (part 3) - Monitoring Memory, Monitoring the Disk System
- SQL Server 2008 R2 : A Performance Monitoring Approach (part 2) - Monitoring the Processors
- SQL Server 2008 R2 : A Performance Monitoring Approach (part 1)
- Microsoft Systems Management Server 2003 : The Four-Phase Patch Management Process (part 2) - The Evaluate & Plan Phase, The Deploy Phase
 
 
REVIEW
- First look: Apple Watch

- 10 Amazing Tools You Should Be Using with Dropbox

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
 
VIDEO TUTORIAL
- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
 
Popular tags
Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS
Popular keywords
HOW TO Swimlane in Visio Visio sort key Pen and Touch Creating groups in Windows Server Raid in Windows Server Exchange 2010 maintenance Exchange server mail enabled groups Debugging Tools Collaborating
Top 10
- Microsoft Excel : How to Use the VLookUp Function
- Fix and Tweak Graphics and Video (part 3) : How to Fix : My Screen Is Sluggish - Adjust Hardware Acceleration
- Fix and Tweak Graphics and Video (part 2) : How to Fix : Text on My Screen Is Too Small
- Fix and Tweak Graphics and Video (part 1) : How to Fix : Adjust the Resolution
- Windows Phone 8 Apps : Camera (part 4) - Adjusting Video Settings, Using the Video Light
- Windows Phone 8 Apps : Camera (part 3) - Using the Front Camera, Activating Video Mode
- Windows Phone 8 Apps : Camera (part 2) - Controlling the Camera’s Flash, Changing the Camera’s Behavior with Lenses
- Windows Phone 8 Apps : Camera (part 1) - Adjusting Photo Settings
- MDT's Client Wizard : Package Properties
- MDT's Client Wizard : Driver Properties
 
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
2015 Camaro