简体   繁体   English

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

[英]Windows VSS (Volume Shadow Copy) in C++

I need some help with getting VSS to work in C++. 我需要一些帮助使VSS在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. 我的基本目的是扫描文件夹中的更改文件(按更改日期),然后使用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快照并复制文件。 VSS snapshot is discarded or released (or whatever). VSS快照被丢弃或释放(或任何其他方式)。

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 谢谢,J

EDIT: Updated to show new method which stops at GetSnapshotProperties() 编辑:更新以显示在GetSnapshotProperties()处停止的新方法

After DoSnapshotset yu have to call the following function 在DoSnapshotset yu之后,必须调用以下函数

hr = pDoSnapshotSetResults->Wait(); hr = pDoSnapshotSetResults-> Wait(); if (!SUCCEEDED(hr)){ unLoadLibrary(); 如果(!SUCCEEDED(hr)){unLoadLibrary(); return 1; 返回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(). 通过调用GetSnapshotProperties()检索VSS_SNAPSHOT_PROP实例。 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. 您需要通过调用StartSnapshotSet()创建一个新集,然后在获取属性之前通过AddToSnapshotSet()将卷添加到快照集中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM