- Overview
- Pre and Post Snapshot Scripts
Overview
When Macrium Reflect takes an image, it invokes Volume Shadow Copy Service (VSS). This is a Microsoft component that takes a point-in-time snapshot of a file system, ensuring that there is a consistent point in time that can be imaged. This snapshot remains active until the imaging completes. For the majority of data, this creates a backup that results in a consistent system upon restore.
However, database engines cache transactions for performance purposes. It is important, therefore, to force the engine to ensure that everything is on the disk and coherent before the snapshot is taken.
What Does VSS Aware Mean?
VSS-aware essentially means that an application can "interact" with VSS to ensure that its data is in a consistent state for image creation. This "interaction" is handled by a VSS writer; these components provide a mechanism for applications to be alerted to the creation of a snapshot, so they can prepare their data for snapshotting. VSS providers can notify VSS writers that a snapshot has been created, and the VSS writer can then perform the appropriate actions. Once the snapshot has been taken, the provider again notifies the writers, so they may let the applications resume.
MS SQL Server includes a VSS writer and automatically creates a coherent point-in-time snapshot. However, for databases that don't ship with a VSS writer, additional steps are required to ensure that the database(s) are in a consistent state for the image creation.
Pre and Post Snapshot Scripts
To ensure that the database is in a consistent state, the database service should be stopped while the VSS snapshot is created. To achieve this, whilst ensuring that the database service is not stopped for the duration of the entire backup, Macrium Reflect can make use of pre and post VSS snapshot creation scripts.
Note: Pre and post snapshot scripts are disabled by default and must be enabled using the following registry key:
| Key | HKEY_LOCAL_MACHINE\SOFTWARE\Macrium\Reflect\settings |
| Name | EnablePrePostScripts |
| Type | DWORD 32 bit |
| Value |
Off = 0, On = 1 |
| Description | Enables and disables pre and post snapshot scripting in Macrium Reflect. |
To automatically stop the database service before the snapshot is created, create a batch file with the following name in the same directory as where the XML backup definition file is located:
<XML File Name>_before_snapshot_wait.bat

This batch script can then be edited to include the relevant commands to pause the database service.
To automatically start the database service once the VSS snapshot creation has completed, create a second batch file in the same same directory as where the XML backup definition file is located and name it:
<XML File Name>_after_snapshot_wait.bat

This batch script can then be edited to include the relevant commands to start the database service again.