Creation of a Snapshot

Microsoft SQL Server Virtual Backup

Microsoft SQL Server Virtual Backup Device Specification

Creation of a Snapshot

The BACKUP command supports the 'WITH SNAPSHOT' option to be used with virtual devices. An application issues the BACKUP DATABASE command, and then interacts with the server through the Virtual Device Interface (VDI) to capture the backup set meta data and perform the snapshot. Only meta data is transferred to the application. Instead of receiving the data and log portions of the backup set, the application receives a command to perform the snapshot. To prevent torn pages, writes to the database files are suspended within Microsoft® SQL Server™ until this command completes or aborts. Upon successful completion of the snapshot, SQL Server will resume writing to the files. The meta data must be saved by the application, as it is required to restore the snapshot.

Note   When full database snapshot backups are being performed, all database and log files must reside on the volumes being captured.

The development kit contains a sample application (snapshot.cpp) that demonstrates how a snapshot is created.

Here are the basic steps for creating a snapshot:

  1. Create the VirtualDeviceSet.

    Setting the VDF_SnapshotPrepare configuration bit is optional. If omitted, SQL Server will not issue the VDC_PrepareToFreeze command during the process.

  2. Issue the BACKUP DATABASE command, including the WITH SNAPSHOT clause.

  3. Open the VirtualDevice.

    There may be only one VirtualDevice for each SNAPSHOT BACKUP command.

  4. Consume the MTF header data (a sequence of VDC_Write commands).

  5. If the VDF_SnapshotPrepare bit has been set (optional in SQL Server 2000 SP2), the VDC_PrepareToFreeze command is issued. The VDI application can coordinate actions prior to the database freeze at this point. For example, if multiple databases are hosted on a single volume, multiple BACKUP WITH SNAPSHOT commands can be issued, and the application can wait for the VDC_PrepareToFreeze from each of the active backup statements.

  6. When VDC_PrepareToFreeze is completed, the database files are frozen. Meta data describing the frozen state is collected and sent as a sequence of VDC_Write commands.

  7. The VDC_Snapshot command is issued.

    The snapshot is made stable (mirror split, etc.).

  8. When the VDC_Snapshot command is completed, the database files are unfrozen. The VirtualDeviceSet is closed and the BACKUP command returns a successful status code.

  9. When freezing the master database along with multiple other databases, always freeze the master database last. When finished with the snapshot, there is no need to serialize the completions of the VDC_Snapshot commands. All the databases should be unfrozen as quickly as possible by calling CompleteCommand for the VDC_Snapshot commands.

  10. When freezing multiple databases, there is a BACKUP statement active against each database. This consumes resources inside SQL Server. Thus there are limits to how many databases can be frozen at a time. We recommend that no more than a few databases be included in a joint snapshot.

See also

BACKUP statement

VDC_Snapshot