开发者

Correct flow of a VSS backup - VSS_E_BAD_STATE error

I'm having issues getting a backup job working in VSS and C++. It is now at the point of working and backing up files but it fails when I call BackupComplete() with the result VSS_E_BA开发者_开发技巧D_STATE so I would like some input from anyone familiar with VSS on whether my flow is correct. I'm currently doing the following:

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();

It seems that something I'm calling is in the wrong order but looking at the documentation and various sources I cannot figure out what is in the wrong order.

Is there anything blindingly obvious that I've missed?


Are you calling SetBackupSucceeded after each component has been processed and prior to calling BackupComplete??


I have been caught with this errors when I was learning VSS, mostly the error was due calling the VSS sequence with CoInitialize(). Please check whether you have CoInitialize and CoUninitialize before and after the VSS sequence.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜