我在使用 VSS 和 C++ 进行备份作业时遇到问题。它现在正处于工作和备份文件的阶段,但是当我调用 BackupComplete()
并返回结果 VSS_E_BAD_STATE
时它失败了,所以我希望熟悉 VSS 的人提供一些信息关于我的流程是否正确。我目前正在做以下事情:
if( !CHECK_HRESULT(::CreateVssBackupComponents(&m_pBackupComponents)) )
{
throw;
}
if( !CHECK_HRESULT((hr = m_pBackupComponents->InitializeForBackup())) )
{
throw;
}
WCHAR wszVolumePathName[MAX_PATH];
GUID snapshotId;
BOOL supported = TRUE;
HRESULT hr;
SnapshotMap::iterator it;
BOOL bWorked = ::GetVolumePathName(path.c_str(), wszVolumePathName, MAX_PATH);
if( !bWorked )
{
throw;
}
if( !CHECK_HRESULT((hr = m_pBackupComponents->IsVolumeSupported(GUID_NULL, wszVolumePathName, &supported))) || !supported )
{
throw;
}
GUID snapshotSetId;
if( !CHECK_HRESULT((hr = m_pBackupComponents->StartSnapshotSet(&snapshotSetId))) )
{
throw;
}
m_SnapshotIdList.push_back(snapshotId);
if( !CHECK_HRESULT((hr = m_pBackupComponents->AddToSnapshotSet(wszVolumePathName, GUID_NULL, &snapshotId))) )
{
throw;
}
if( !CHECK_HRESULT((hr = m_pBackupComponents->SetBackupState(FALSE, FALSE, VSS_BT_COPY, FALSE))) )
{
throw;
}
CComPtr<IVssAsync> pPrepareForBackupResults;
if( !CHECK_HRESULT((hr = m_pBackupComponents->PrepareForBackup(&pPrepareForBackupResults))) )
{
throw;
}
if( !CHECK_HRESULT((hr = pPrepareForBackupResults->Wait())) )
{
pPrepareForBackupResults.Release();
throw;
}
HRESULT hrPrepareForBackupResults;
if( !CHECK_HRESULT((hr = pPrepareForBackupResults->QueryStatus(&hrPrepareForBackupResults, NULL))) )
{
pPrepareForBackupResults.Release();
throw;
}
pPrepareForBackupResults.Release();
if( hrPrepareForBackupResults != VSS_S_ASYNC_FINISHED )
{
throw;
}
CComPtr<IVssAsync> pDoSnapshotSetResults;
if( !CHECK_HRESULT((hr = m_pBackupComponents->DoSnapshotSet(&pDoSnapshotSetResults))) )
{
throw;
}
m_VssSyncList.push_back(pDoSnapshotSetResults);
VSS_SNAPSHOT_PROP snapshotProperties;
if( !CHECK_HRESULT((hr = m_pBackupComponents->GetSnapshotProperties(snapshotId, &snapshotProperties))) )
{
throw;
}
TSTRING newPath(snapshotProperties.m_pwszSnapshotDeviceObject);
m_SnapshotMap.insert(SnapshotMap_Entry(TSTRING(wszVolumePathName), newPath));
newPath.append(path.substr(2));
<Backup files here>
::VssFreeSnapshotProperties(&snapshotProperties);
for( SnapshotIdList::iterator it = m_SnapshotIdList.begin(); it != m_SnapshotIdList.end(); it++ )
{
LONG cDeletedSnapshots;
GUID nonDeletedSnapshotId;
m_pBackupComponents->DeleteSnapshots(*it, VSS_OBJECT_SNAPSHOT_SET, TRUE, &cDeletedSnapshots, &nonDeletedSnapshotId);
}
m_SnapshotIdList.clear();
for( VssSyncList::iterator it = m_VssSyncList.begin(); it != m_VssSyncList.end(); it++ )
{
(*it).Release();
}
m_VssSyncList.clear();
CComPtr<IVssAsync> pBackupCompleteResults;
if( !CHECK_HRESULT((hr = m_pBackupComponents->BackupComplete(&pBackupCompleteResults))) )
{
throw;
}
else
{
if( !CHECK_HRESULT((hr = pBackupCompleteResults->Wait())) )
{
throw;
}
HRESULT hrBackupCompleteResults;
if( CHECK_HRESULT(pBackupCompleteResults->QueryStatus(&hrBackupCompleteResults, NULL)) )
{
if( hrBackupCompleteResults != VSS_S_ASYNC_FINISHED )
{
throw;
}
}
pBackupCompleteResults.Release();
}
m_SnapshotMap.clear();
似乎我正在调用的东西顺序错误,但查看文档和各种来源我无法弄清楚顺序错误的是什么。
有什么我错过的非常明显的事情吗?
最佳答案
您是否在处理完每个组件之后调用 BackupComplete 之前调用 SetBackupSucceeded??
关于c++ - VSS 备份的正确流程 - VSS_E_BAD_STATE 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5662674/