Overview of Pre-Backup Tasks
Pre-backup tasks under VSS are focused on creating a shadow copy of the volumes containing data for backup. The backup application will save data from the shadow copy, not the actual volume. For more information, see Overview of Processing a Backup Under VSS.
Requesters typically wait for writers to prepare for backup and creating the shadow copy. The writer must determine if it is to participate in the backup and, if it is, configure its files and itself to be ready for backup and shadow copy. The following table shows the sequence of actions and events that are required to prepare for a backup operation.
|Requester action||Event||Writer action|
|The requester can set backup options (see IVssBackupComponents::SetBackupOptions)||None||None|
|Support incremental and differential backup operations by examining any stored backup stamps (see IVssComponent::GetBackupStamp, IVssBackupComponents::SetPreviousBackupStamp)||None||None|
|Notify writers to prepare for a backup operation using IVssBackupComponents::PrepareForBackup||PrepareForBackup||Writer preparations include determining if files are to be backed up, whether the writer will participate in the shadow copy freeze, as well as creating writer-specific metadata (see CVssWriter::OnPrepareBackup, CVssWriter::IsPathAffected, IVssWriterComponents, IVssComponent, IVssComponent::GetBackupOptions, CVssWriter::AreComponentsSelected, IVssComponent::SetBackupMetadata, and IVssComponent::GetPreviousBackupStamp.|
|The requester waits for writers to set up for backup using IVssAsync. It should also verify writer status (see IVssBackupComponents::GatherWriterStatus, IVssBackupComponents::GetWriterStatus)||None||None|
|Requester requests a shadow copy using IVssBackupComponents::DoSnapshotSet||None||None|
Put the writer into a shadow copy ready state.
Final setup before the shadow copy.
Normal functioning (including I/O) can resume.
Final clean ups of shadow copy preparations. See IVssComponent::AddDifferencedFilesByLastModifyTime and IVssComponent::SetBackupStamp.
|Requester waits for completion of shadow copy using:||None||None|
In addition, before creating a IVssBackupComponents::PrepareForBackup event, a requester may also set backup options for individual writers using IVssBackupComponents::SetBackupOptions depending on the specifics of each writer and whether a requester is aware of them.
To support incremental and differential operations, requesters may at this point choose to examine components for time stamps of earlier backup operation (using IVssComponent::GetBackupStamp) and use that information to set a previous time stamp for a writer to process (using IVssBackupComponents::SetPreviousBackupStamp). See Incremental and Differential Backups for more information.
A requester can now direct the system's writers to complete pre-backup preparations and to handle the creation of a shadow copy.
After all participating writers return from handling the PrepareForBackup event (which a requester determines by using the instance of the IVssAsync interface returned by PrepareForBackup), the requester can initiate the shadow copy by calling IVssBackupComponents::DoSnapshotSet, which, as it progresses, will generate PrepareForSnapshot, Freeze, Thaw, and PostSnapshot events for the writers to handle.
There are some cases where a requester may not need to create a shadow copy. Specifically, each file set managed by one of a given writer's components has a File Specification Backup mask (indicated by a bitwise OR of VSS_FILE_SPEC_BACKUP_TYPE values) set during the Identify event. This mask specifies, among other things, whether a file set requires the system to be shadow copied before its backup is performed.
If no file sets to be backed up on any volumes require a shadow copy, then IVssBackupComponents::DoSnapshotSet need not be called.
Writers can override this default implementation and use the handling to find information about the upcoming backup and take action.
A writer can determine information about the sort of backup operation contemplated by using the following methods:
A writer determines if the files it manages will be involved in the shadow copy by using CVssWriter::IsPathAffected.
More important, when VSS calls the CVssWriter::OnPrepareBackup method, it passes in an instance of the IVssWriterComponents interface, which allows direct access through the IVssComponent interface to those of its components explicitly included in the requester's Backup Components Document. The writer used the instances of the IVssComponent interface that define component sets to gain access to its implicitly included component (see Selectability and working with Component Properties).
- Adding partial files (if supported) by calling IVssComponent::AddPartialFile.
- Setting any private metadata that the writer will need to handle the restore.
- If the writer supports incremental and differential backups (see Incremental and Differential Backups), doing the following:
- Checking for previous backup time stamps by calling IVssComponent::GetPreviousBackupStamp.
- Adding any required differenced files by calling IVssComponent::AddDifferencedFilesByLastModifyTime.
- If the writer supports the VSS_BS_TIMESTAMPED schema, adding backup time-stamp strings in the writer's own format using IVssComponent::SetBackupStamp.
- Initiating very time-consuming asynchronous operations, such as synchronizing data across multiple disks. This will allow the writer to continue working while the operation is processed, including handling other VSS events. These operations must terminate before the Freeze event.
The requester's call to IVssBackupComponents::DoSnapshotSet initiates the shadow copy and generates the following events for the writers to handle:
Three of the writer's handlers—CVssWriter::OnPrepareSnapshot, CVssWriter::OnFreeze, and CVssWriter::OnThaw—are pure virtual methods, and each writer must implement them rather than relying on defaults. Depending on a writer's needs, they may be coded as dummy methods, simply returning TRUE.
Because there is typically a narrow time window between the issuing of a Freeze event and the issuing of a Thaw event, most of the major work in preparing for the shadow copy—such as shutting down processes, creating temporary files, or draining I/O queues—would be handled in CVssWriter::OnPrepareSnapshot.
How a writer might use CVssWriter::OnPrepareSnapshot to handle its I/O before the creation of a shadow copy is highly dependent on the writer's own architecture.
Writers that can afford to hold all writes and keep the data in an absolute consistent state before Freeze, should do so.
If the writer cannot freeze its I/O, then it should take actions to create a stable source for backup and to reduce the recovery time for a shadow copy. Examples of this might include queuing incoming I/O requests or generating a duplicate set of files in an alternate path to be used as the source of a backup.
The CVssWriter::OnFreeze method performs simple, short tasks such as verifying that the CVssWriter::OnPrepareSnapshot left I/O in the correct state, and that any asynchronous tasks started by CVssWriter::OnPrepareBackup completed. This method is a writer's last chance to veto a shadow copy if there are problems (see Writer Errors and Vetoes).
It is generally possible for a writer to resume normal operation following a Thaw event: a shadow copy may not be immediately ready for backup after the Thaw, but a writer should be able to resume normal operation. Therefore, typically CVssWriter::OnThaw is used by writers to return to a pre-freeze state. However, any temporary files created to support the shadow copy should be left in place until the PostSnapshot event. Typically, you would use CVssWriter::OnPostSnapshot for this sort of cleanup. Because many applications do not require this sort of cleanup, CVssWriter::OnPostSnapshot is a virtual method with a default implementation that simply returns TRUE. If an incremental or differential backup is being performed, the writer may call IVssComponent::GetPreviousBackupStamp and IVssComponent::SetBackupStamp. For more information, see Writer Role in Backing Up Complex Stores. Another method that can be called at this time is IVssComponent::AddDifferencedFilesByLastModifyTime.