Shadow Copy Creation Details
In general, how a shadow copy is created depends on the type of shadow copy to be created, its context, and the role accorded to writers in the shadow copy operation. (See Shadow Copy Context Configurations for more information.)
The shadow copy context is set by calling the IVssBackupComponents::SetContext method. Before calling the IVssBackupComponents::DoSnapshotSet method to create a shadow copy, requesters must call the IVssBackupComponents methods in the order specified in the following sections.
Regardless of the level of writer participation, the creation of any shadow copy will always require the requestor be initialized with calls to IVssBackupComponents::InitializeForBackup and IVssBackupComponents::StartSnapshotSet.
If this call is not made, the IVssBackupComponents::DoSnapshotSet method will return an error.
If the shadow copy context specifies writer participation (that is, IVssBackupComponents::SetContext is called with VSS_CTX_BACKUP, or VSS_CTX_APP_ROLLBACK):
- Requesters must always call IVssBackupComponents::GatherWriterMetadata when the shadow copy context supports writer participation. If the shadow copy context supports writer participation and IVssBackupComponents::GatherWriterMetadata is not called prior to IVssBackupComponents::DoSnapshotSet, an error will be returned.
- If a requester wants to select specific writer components, it must call IVssBackupComponents::AddComponent before calling StartSnapshotSet to create the shadow copy set.
- StartSnapshotSet must be called to create the shadow copy set.
- Requesters may add one or more volumes to the shadow copy set by calling AddToSnapshotSet. Some writer components may not specify any affected volumes. In this case, it is acceptable for a snapshot set to be empty (that is, to contain no volumes).
- To guarantee the consistency of writer metadata, a requester should always call IVssBackupComponents::PrepareForBackup even if no components are selected. This causes VSS to generate a PrepareForBackup event, in which VSS calls the CVssWriter::OnPrepareBackup method for each participating writer.
- VSS will generate PrepareForSnapshot and Freeze events before creating the shadow copy in response to IVssBackupComponents::DoSnapshotSet. Writers will handle the events with CVssWriter::OnPrepareSnapshot and CVssWriter::OnFreeze.
- VSS will generate Thaw events and PostSnapshot events after creating a shadow copy in response to IVssBackupComponents::DoSnapshotSet. Writers will handle the events with CVssWriter::OnThaw and CVssWriter::OnPostSnapshot.
Creating shadow copies without writer participation is discouraged for standard backup applications (see Backups without Writer Participation).
There are uses, such as fast backups of a disk to provide a safety net against accidental file corruption, which can be conducted without explicit writer participation. Such a shadow copy would have a context of either VSS_CTX_FILE_SHARE_BACKUP or VSS_CTX_NAS_ROLLBACK.
For this type of shadow copy, note the following:
- Requesters must still call the required methods listed in Prerequisites for All Shadow Copies.
- Requesters may call IVssBackupComponents::GatherWriterMetadata, but this is not required.
- If requesters call IVssBackupComponents::AddComponent, IVssBackupComponents::PrepareForBackup, or IVssBackupComponents::BackupComplete, an error will be returned.
- Providers will not generate PrepareForSnapshot, Freeze, Thaw, or PostSnapshot events for this type of shadow copy.