我在VSS和C++中备份作业时遇到了问题。它现在正处于工作和备份文件的阶段,但是当我使用结果VSS_E_BAD_STATE调用BackupComplete()时,它会失败,所以我希望任何熟悉VSS_E_BAD_STATE的人都能提供一些关于我的流程是否正确的输入。我目前正在做以下工作:
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();似乎我调用的内容顺序错误,但查看文档和各种来源时,我找不到顺序错误的内容。
我有什么明显的遗漏吗?
发布于 2011-04-14 19:50:53
在处理完每个组件之后,在调用BackupComplete之前,是否调用SetBackupSucceeded?
发布于 2011-04-15 14:45:12
我在学习VSS时遇到过这个错误,主要是因为用CoInitialize()调用了VSS序列。请检查VSS序列前后是否有CoInitialize和CoUninitialize。
https://stackoverflow.com/questions/5662674
复制相似问题