C++ 中的 Windows VSS(卷影复制)
我需要一些帮助来让 VSS 在 C++ 中工作。我的基本目标是扫描文件夹中是否有更改的文件(按修改日期),然后使用 VSS 将它们备份到另一台设备。该文档不清楚(至少对我来说)如何做到这一点,而且我找不到任何合适的示例来说明如何做到这一点。
我的流程应该是这样的:
扫描文件夹并创建修改文件的列表。 VSS 快照已创建并复制文件。 VSS 快照被丢弃或释放(或其他方式)。
这是我到目前为止所拥有的(为简洁起见,删除了错误处理):
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->DoSnapshotSet(&pDoSnapshotSetResults);
m_pBackupComponents->GetSnapshotProperties(snapshotId, &snapshotProperties); <-- Never gets beyond here
好的,这似乎是正确的方法,但是,复制线程冻结在代码的最后一行,并且永远不会再进一步。
谢谢, J
编辑:更新以显示在 GetSnapshotProperties()
处停止的新方法
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->DoSnapshotSet(&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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 DoSnapshotset 之后,您必须调用以下函数
hr = pDoSnapshotSetResults->Wait();
if (!SUCCEEDED(hr)){ unLoadLibrary();返回1;一旦
此功能成功,您就可以获得快照属性。
After DoSnapshotset yu have to call the following function
hr = pDoSnapshotSetResults->Wait();
if (!SUCCEEDED(hr)){ unLoadLibrary(); return 1; }
once this function are sucessfull then you can get the snapshotproperties.
VSS_SNAPSHOT_PROP 实例通过调用 GetSnapshotProperties() 来检索。您需要通过调用 StartSnapshotSet() 创建一个新集,然后在获取属性之前通过 AddToSnapshotSet() 将卷添加到快照集。
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.