C++ 中的 Windows VSS(卷影复制)

发布于 2024-11-01 14:54:18 字数 1081 浏览 5 评论 0原文

我需要一些帮助来让 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜光 2024-11-08 14:54:18

在 DoSnapshotset 之后,您必须调用以下函数

hr = pDoSnapshotSetResults->Wait();
if (!SUCCEEDED(hr)){ unLoadLibrary();返回1;一旦

    HRESULT hrDoSnapshotSetResults;

    hr = pDoSnapshotSetResults->QueryStatus(&hrDoSnapshotSetResults, NULL);
    if (!SUCCEEDED(hr)){    unLoadLibrary(); return 1;  }

此功能成功,您就可以获得快照属性。

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.

长亭外,古道边 2024-11-08 14:54:18

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文