Restore Databases Instantly with SQL Virtual Restore - Red Gate ...
Restore Databases Instantly with SQL Virtual Restore - Red Gate ...
Restore Databases Instantly with SQL Virtual Restore - Red Gate ...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>Restore</strong> <strong>Databases</strong><br />
<strong>Instantly</strong> <strong>with</strong><br />
<strong>SQL</strong> <strong>Virtual</strong> <strong>Restore</strong>
Background<br />
<strong>SQL</strong> <strong>Virtual</strong> <strong>Restore</strong> allows users to restore<br />
databases <strong>with</strong>out allocating the storage space that<br />
would usually be required, creating a fully-functional<br />
database which uses the backup file or files as the<br />
primary data source. <strong>SQL</strong> <strong>Virtual</strong> <strong>Restore</strong> works<br />
<strong>with</strong> <strong>SQL</strong> Server native backups (both compressed<br />
and uncompressed), and <strong>with</strong> backups created<br />
using <strong>Red</strong> <strong>Gate</strong>’s <strong>SQL</strong> Backup Pro or <strong>SQL</strong><br />
HyperBac. <strong>SQL</strong> <strong>Virtual</strong> <strong>Restore</strong> runs through the<br />
HyperBac engine.<br />
You do not need to alter or otherwise configure your<br />
backup operations. This is the case whether you’re<br />
taking native backups or making backups <strong>with</strong> <strong>Red</strong><br />
<strong>Gate</strong>’s tools.<br />
A distinct advantage of <strong>SQL</strong> <strong>Virtual</strong> <strong>Restore</strong> is that<br />
it can be used for backup verification, as well as<br />
1<br />
object level recovery and disaster recovery. Backup<br />
verification <strong>with</strong> <strong>SQL</strong> <strong>Virtual</strong> <strong>Restore</strong> involves a<br />
comprehensive test of a backup file, by creating a<br />
virtual restore in the background and performing a<br />
full integrity and consistency check on the resultant<br />
virtualized database using DBCC CHECKDB. This<br />
process checks the physical integrity of the pages<br />
in the backup file and the logical integrity of each<br />
object in the database; a RESTORE VERIFYONLY of<br />
the backup set alone checks only that all pages are<br />
contained in the backup file.<br />
There are a number of advantages to backup<br />
verification <strong>with</strong> <strong>SQL</strong> <strong>Virtual</strong> <strong>Restore</strong>:<br />
• It takes much less time than an equivalent full<br />
restore and DBCC CHECKDB, fitting comfortably in<br />
most maintenance windows.<br />
• It requires a near-zero data footprint.<br />
• It’s fully scriptable using native T-<strong>SQL</strong> commands,<br />
making it an easy addition to any backup/<br />
maintenance program.<br />
• The entire verification process can be offloaded<br />
to a second server, removing any maintenance<br />
overhead from the production server.<br />
Backup verification is only one of many uses for<br />
<strong>SQL</strong> <strong>Virtual</strong> <strong>Restore</strong>, but it’s a particularly important<br />
one for early detection of production integrity issues<br />
and to ensure successful disaster recovery.<br />
Moreover, performing best practice backup<br />
verification prepares your backup files so that you<br />
can restore them as fully-functional, fully-available,<br />
completely-recovered databases instantly, at any<br />
point in the future.<br />
<strong>Restore</strong> <strong>Databases</strong> <strong>Instantly</strong><br />
A backup verification operation using <strong>SQL</strong> <strong>Virtual</strong><br />
<strong>Restore</strong> involves the same set of steps needed to<br />
make a backup file instantly available in the future.<br />
When performing a virtual restore, the native <strong>SQL</strong><br />
Server RESTORE DATABASE sequence is<br />
completed. This includes the recovery phase, where<br />
changes made during the backup process are<br />
applied to the virtual database, so that it includes<br />
an exact representation of the data as it existed at<br />
the end of the backup. <strong>SQL</strong> <strong>Virtual</strong> <strong>Restore</strong> creates<br />
several files during this process:<br />
• ‘<strong>Virtual</strong>’ data and log files (.vmdf, .vdnf, .vldf)<br />
These files are used by <strong>SQL</strong> Server during recovery<br />
and for any write activity to the virtual restore.<br />
• <strong>Virtual</strong> restore index files<br />
The backup file is indexed during the virtual restore<br />
process, so that data can be quickly accessed from<br />
the backup when the virtually restored database is<br />
online.<br />
These files have a minimal data footprint, in many<br />
cases just a few MB. Along <strong>with</strong> the backup file<br />
itself (or backup files, if you are striping backups),<br />
these files provide you <strong>with</strong> all the necessary<br />
components to restore your database instantly, <strong>with</strong><br />
1 Object level recovery is the process of extracting data (rows or entire tables or views), discrete objects, or object definitions from backup archives<br />
<strong>with</strong>out performing a full RESTORE operation.<br />
2
no background recovery or population methods<br />
necessary.<br />
An Example<br />
This example assumes <strong>SQL</strong> <strong>Virtual</strong> <strong>Restore</strong> is<br />
installed <strong>with</strong> the default configuration.<br />
Start by performing a backup. In this example, we<br />
are using <strong>SQL</strong> Server 2008’s native compressed<br />
backup format:<br />
BACKUP DATABASE AdventureWorks<br />
TO DISK = ‘C:\MS<strong>SQL</strong>\Backup\AdventureWorks_Native_Compressed_Backup.<br />
bak’<br />
WITH COMPRESSION<br />
Optionally, you can perform a RESTORE<br />
VERIFYONLY at this stage, but we will skip this for<br />
the purpose of this example.<br />
Now perform a virtual restore:<br />
RESTORE DATABASE [AdventureWork_<strong>Virtual</strong>]<br />
FROM<br />
DISK = ‘C:\MS<strong>SQL</strong>\Backup\Adventure-<br />
Works_Native_Compressed_Backup.bak’<br />
WITH MOVE ‘AdventureWork_Data’ TO<br />
‘C:\MS<strong>SQL</strong>\Backup\AdventureWork_AdventureWorks_<strong>Virtual</strong>.vmdf’<br />
MOVE ‘AdventureWork_Log’ TO<br />
‘C:\MS<strong>SQL</strong>\Backup\AdventureWork_1_AdventureWorks_<strong>Virtual</strong>.vldf’<br />
NORECOVERY, STATS=1<br />
GO<br />
RESTORE DATABASE [AdventureWork_<strong>Virtual</strong>]<br />
WITH RECOVERY, RESTRICTED_USER<br />
GO<br />
Note that this is a native T-<strong>SQL</strong> RESTORE<br />
statement. The only directives for the underlying<br />
virtual restore product are the .vmdf and .vldf file<br />
extensions for the data and log file. In this case,<br />
our virtual files were created in the backup<br />
directory, but they can be stored in any location.<br />
The virtualized database is brought online in<br />
RESTRICTED_USER mode to prevent any other<br />
access during the verification process.<br />
The name of the virtualized database is arbitrary as<br />
long as it does not conflict <strong>with</strong> the source<br />
database name. If you use your own scripts and<br />
assign a uniquely identifiable name for your<br />
backups (such as a name which includes a<br />
timestamp), consider using this name for the<br />
virtualized database and datafiles (e.g. Adventure-<br />
Works_Full_1212112100_<strong>Virtual</strong>). This makes the<br />
files and database easily recognizable to any other<br />
user and makes the process of association easier.<br />
A virtualized database viewed from <strong>SQL</strong> Server<br />
Management Studio<br />
<strong>Virtual</strong> data and log files<br />
3
The relevant HyperBac index files can be picked out<br />
by the timestamp which coincides <strong>with</strong> the time the<br />
virtual restore was initiated. These files are located<br />
in the HyperBac\indexes directory. All files <strong>with</strong> this<br />
timestamp are associated <strong>with</strong> the virtually restored<br />
database:<br />
These files will also need to be moved, if you<br />
transfer a virtual restore to a remote server.<br />
You can now perform the DBCC CHECKDB<br />
operation against the virtually restored database to<br />
fully validate the backup file. This step is not<br />
technically necessary for an instant restore:<br />
DBCC CHECKDB ([AdventureWorks_<strong>Virtual</strong>])<br />
Now, rather than dropping the virtualized database,<br />
detach it:<br />
EXEC master.dbo.sp_detach_db @dbname =<br />
N‘AdventureWorks_<strong>Virtual</strong>’<br />
All of the necessary components are now in place<br />
to instantly access the backup file at any point in<br />
the future in a fully-recovered, operational state.<br />
The additional files we have created so we can do<br />
this require only a few MB of storage, so the<br />
overheads are negligible. As an example, we’ll bring<br />
the database online <strong>with</strong> its original name:<br />
USE [master]<br />
GO<br />
CREATE DATABASE [AdventureWorks] ON<br />
(FILENAME = N‘C:\MS<strong>SQL</strong>\Backup\AdventureWorks_AdventureWorks_<strong>Virtual</strong>.<br />
vmdf’),<br />
(FILENAME = N‘C:\MS<strong>SQL</strong>\Backup\AdventureWorks_1__AdventureWorks_<strong>Virtual</strong>.<br />
vldf’)<br />
FOR ATTACH<br />
GO<br />
The database is available instantly, in a fullyrecovered<br />
state:<br />
sp_helpdb ‘AdventureWorks’ produces the<br />
output below:<br />
4
Conclusion<br />
<strong>SQL</strong> <strong>Virtual</strong> <strong>Restore</strong> can easily be embedded into<br />
any environment, providing comprehensive backup<br />
verification and allowing you to instantly restore<br />
databases for object level recovery or disaster<br />
recovery. These operations can be performed on<br />
local or remote (UNC-based) backups, and the<br />
process can be offloaded to a different server, to<br />
eliminate the performance overheads of the<br />
RESTORE and DBCC CHECKDB processes or<br />
work around short maintenance windows.<br />
This is also possible for instant restore operations;<br />
simply move the files associated <strong>with</strong> a virtual<br />
restore to a remote server and perform the attach<br />
operation there.<br />
To try it out, download a free trial of <strong>SQL</strong> <strong>Virtual</strong><br />
<strong>Restore</strong> today.<br />
5