Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Server

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

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
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
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server