Windows VSS (Volume Shadow Copy) in C++
I need some help with getting VSS to work in C++. My basic aim is to scan a folder for changed files (by modified date) and then back them up to another device using VSS. The documentation is unclear (to me at least) on how I can do this and I cannot find any decent examples of how to do it.
My process should work like this:
Folder is scanned and a list of modified files is created. VSS snapshot is created and the files are copied. VSS snapshot is discarded or released (or whatever).
Here's what I have so far (error handling removed for brevity):
VSS_SNAPSHOT_PROP snapshotProperties;
::CoInitialize(NULL);
::CreateVssBackupComponents(&m_pBackupComponents);
m_pBackupComponents->InitializeForBackup();
m_pBackupComponents->StartSnapshotSet(&m_SnapshotSetId);
m_pBackupComponents->AddToSnapshotSet(wszVolumePathName, GUID_NULL, &snapshotId);
m_pBackupComponents->SetBackupState(TRUE, FALSE, VSS_BT_FULL, FALSE);
m_pBackupComponents->PrepareForBackup(&pPrepareForBackupResults);
pPrepareForBackupResults->Wait();
m_pBackupComponents->DoS开发者_如何学编程napshotSet(&pDoSnapshotSetResults);
m_pBackupComponents->GetSnapshotProperties(snapshotId, &snapshotProperties); <-- Never gets beyond here
Ok, that seems to be the correct method however, the copy thread freezes at the last line of code and never gets any further.
Thanks, J
EDIT: Updated to show new method which stops at GetSnapshotProperties()
After DoSnapshotset yu have to call the following function
hr = pDoSnapshotSetResults->Wait(); if (!SUCCEEDED(hr)){ unLoadLibrary(); return 1; }
HRESULT hrDoSnapshotSetResults;
hr = pDoSnapshotSetResults->QueryStatus(&hrDoSnapshotSetResults, NULL);
if (!SUCCEEDED(hr)){ unLoadLibrary(); return 1; }
once this function are sucessfull then you can get the snapshotproperties.
VSS_SNAPSHOT_PROP instances are retrieved via a call to GetSnapshotProperties(). You need to create a new set by calling StartSnapshotSet() and then add the volume to the snapshot set via AddToSnapshotSet() before getting the properties.
精彩评论