简体   繁体   English

无法访问卷影复制服务快照卷

[英]Unable to Access Volume Shadow Copy Service Snapshot Volume

Hi I am having trouble getting the volume shadow copy service to work for my program written in C++ with QT. 嗨,我很难让卷影复制服务对我用QT用C ++编写的程序起作用。 The snapshot is created successfully however I cannot access it either through my program or through the Windows run prompt (not sure if that's even possible in the first place). 快照创建成功,但是我无法通过程序或Windows运行提示符访问快照(不确定是否一开始就可以使用)。 I have tried accessing the snapshot using both \\\\?\\GLOBALROOT\\Device\\HarddiskVolumeShadowCopy27\\ and \\Device\\HarddiskVolumeShadowCopy28\\ as prefixes (as generated from my program with the right number on the end). 我尝试使用\\\\?\\ GLOBALROOT \\ Device \\ HarddiskVolumeShadowCopy27 \\和\\ Device \\ HarddiskVolumeShadowCopy28 \\作为前缀访问快照(由程序生成,末尾带有正确的数字)。 Also the snapshots look like they are differential snapshots even though I used VSS_BT_COPY and VSS_BT_FULL as the state. 即使我使用VSS_BT_COPY和VSS_BT_FULL作为状态,快照也看起来像是差异快照。 I had been trying VSS_CTX_NAS_ROLLBACK as the context which created persistent snapshots so I tried deleting them all before attempting to access the snapshots in the program once again but this time with context VSS_CTX_FILE_SHARE_BACKUP, without success. 我一直在尝试使用VSS_CTX_NAS_ROLLBACK作为创建持久快照的上下文,因此在尝试再次访问程序中的快照之前尝试删除所有快照,但这一次使用上下文VSS_CTX_FILE_SHARE_BACKUP,但没有成功。 Here's the snapshot creation code (error handling removed): 这是快照创建代码(已删除错误处理):

void Worker::setupVSS(BackupJob &job)
{
    HRESULT result;
    //backupComponents is a class member variable
    //IVssBackupComponents *backupComponents;

    result = CreateVssBackupComponents(&backupComponents);

    VSS_ID snapshotSetId;
    result = backupComponents->InitializeForBackup();

    //tried both of these
    //result = backupComponents->SetBackupState(FALSE, FALSE, VSS_BT_COPY);
    result = backupComponents->SetBackupState(FALSE, FALSE, VSS_BT_FULL);

    //tried both of these
    //result = backupComponents->SetContext(VSS_CTX_NAS_ROLLBACK);
    result = backupComponents->SetContext(VSS_CTX_FILE_SHARE_BACKUP);

    result = backupComponents->StartSnapshotSet(&snapshotSetId);

    VSS_ID snapshotId;
    wchar_t *source;
    //this line gets the drive letter with : and \
    QString driveLetter = job.getSource().mid(0,3);
    driveLetter.toWCharArray(source);
    //QString("D:\\").toWCharArray(source);
    result = backupComponents->AddToSnapshotSet(source, GUID_NULL, &snapshotId);

    IVssAsync *async;
    result = backupComponents->DoSnapshotSet(&async);

    result = async->Wait();
    async->Release();

    VSS_SNAPSHOT_PROP prop;
    result = backupComponents->GetSnapshotProperties(snapshotId, &prop);

    QString vssPrefix = QString::fromWCharArray(prop.m_pwszSnapshotDeviceObject);
    job.setVSSPrefix(vssPrefix);
}

And here's the file open code: 这是文件打开代码:

QString sourceFileString = job.getCurrentFileSource(fileCount);
if (job.getVSS())
{
    QString prefix = job.getVSSPrefix();
    //tried this comment to remove ? and globalroot from prefix without success
    //prefix = prefix.mid(prefix.indexOf("\\Device"));
    prefix.append("\\");
    prefix = QDir::fromNativeSeparators(prefix);
    sourceFileString.replace(0,3,prefix);
}
QFile sourceFile(sourceFileString);
if (!sourceFile.open(QIODevice::ReadOnly))
{
    updateStatus("<font color=\"red\">ERROR: Couldn't open source file " + QDir::toNativeSeparators(sourceFile.fileName()) + ".</font>");
    updateStatus("<font color=\"red\">ERROR: " + sourceFile.errorString() + "</font>");
    errorsFound = true;
    break;
}

Here are the errors QT gives me from the failed file open attempt: 这是QT从失败的文件打开尝试中给我的错误:

01-13-2017 01:42 PM ERROR: Couldn't open source file \\\\?\\GLOBALROOT\\Device\\HarddiskVolumeShadowCopy38\\Users\\Josh\\Desktop\\awef\\awef3\\awefawefawef - Copy (10)waefawefawefawefawefawef - Copyawefawefawefawefawefwefawefawef.docx. 2017年1月13日下午01:42错误:无法打开源文件\\\\?\\ GLOBALROOT \\ Device \\ HarddiskVolumeShadowCopy38 \\ Users \\ Josh \\ Desktop \\ awef \\ awef3 \\ awefawefawef-复制(10)waefawefawefawefawefawefef-Copyawefawefawefawefawefawefwefawefawefa。

01-13-2017 01:42 PM ERROR: The network path was not found. 2017年1月13日01:42 PM错误:找不到网络路径。

01-13-2017 01:44 PM ERROR: Couldn't open source file \\Device\\HarddiskVolumeShadowCopy40\\Users\\Josh\\Desktop\\awef\\awef3\\awefawefawef - Copy (10)waefawefawefawefawefawef - Copyawefawefawefawefawefwefawefawef.docx. 2017年1月13日下午01:44错误:无法打开源文件\\ Device \\ HarddiskVolumeShadowCopy40 \\ Users \\ Josh \\ Desktop \\ awef \\ awef3 \\ awefawefawefef-复制(10)waefawefawefawefawefawefef-Copyawefawefawefawefawefawefwefawefawef.docx。

01-13-2017 01:44 PM ERROR: The system cannot find the path specified. 2017年1月13日01:44 PM错误:系统找不到指定的路径。

When I try to open the same files from the run prompt it just says Windows cannot find filename etc.. 当我尝试从运行提示中打开相同的文件时,它只是说Windows无法找到文件名等。

I verified the snapshots are created using vssadmin list shadows with this output: 我验证了快照是使用vssadmin list shadow与以下输出创建的:

Contents of shadow copy set ID: {968d9034-3aee-494b-ae78-82af04a15686} Contained 1 shadow copies at creation time: 1/13/2017 1:40:09 PM Shadow Copy ID: {1109bad9-7d01-40f2-9141-cda25b313810} Original Volume: (C:)\\?\\Volume{b3fc9fb7-0000-0000-0000-100000000000}\\ Shadow Copy Volume: \\?\\GLOBALROOT\\Device\\HarddiskVolumeShadowCopy38 Originating Machine: joshdesktop10 Service Machine: joshdesktop10 Provider: 'Microsoft Software Shadow Copy provider 1.0' Type: FileShareRollback Attributes: No writers, Differential 卷影副本集ID的内容:{968d9034-3aee-494b-ae78-82af04a15686}在创建时包含1个卷影副本:2017年1月13日下午1:40:09卷影副本ID:{1109bad9-7d01-40f2-9141- cda25b313810}原始卷:(C:)\\?\\卷{b3fc9fb7-0000-0000-0000-100000000000} \\卷影副本卷:\\?\\ GLOBALROOT \\ Device \\ HarddiskVolumeShadowCopy38原始计算机:joshdesktop10服务计算机:joshdesktop10提供程序:'Microsoft软件卷影复制提供程序1.0'类型:FileShareRollback属性:无编写器,有差异

Contents of shadow copy set ID: {d6519b09-8325-4c1c-90bc-935a39f2189a} Contained 1 shadow copies at creation time: 1/13/2017 1:44:07 PM Shadow Copy ID: {21e1b83e-db79-4a29-95b0-65cc5c7d08a8} Original Volume: (C:)\\?\\Volume{b3fc9fb7-0000-0000-0000-100000000000}\\ Shadow Copy Volume: \\?\\GLOBALROOT\\Device\\HarddiskVolumeShadowCopy40 Originating Machine: joshdesktop10 Service Machine: joshdesktop10 Provider: 'Microsoft Software Shadow Copy provider 1.0' Type: FileShareRollback Attributes: No writers, Differential 卷影副本集ID的内容:{d6519b09-8325-4c1c-90bc-935a39f2189a}创建时包含1个卷影副本:1/13/2017 1:44:07 PM卷影副本ID:{21e1b83e-db79-4a29-95b0- 65cc5c7d08a8}原始卷:(C:)\\?\\ Volume {b3fc9fb7-0000-0000-0000-100000000000} \\卷影副本卷:\\?\\ GLOBALROOT \\ Device \\ HarddiskVolumeShadowCopy40原始计算机:joshdesktop10服务计算机:joshdesktop10提供程序:'Microsoft软件卷影复制提供程序1.0'类型:FileShareRollback属性:无编写器,有差异

As you can see they are differential backups ... could this be the problem? 如您所见,它们是差异备份...这可能是问题所在吗?

Any ideas?? 有任何想法吗?? Thanks! 谢谢!

Google has enlightened me... as here you cannot access VSS snapshot volumes without using the Win32 API functions FindFirstFile/FindNextFile. Google启发了我...因为在这里您必须使用Win32 API函数FindFirstFile / FindNextFile才能访问VSS快照卷。 There is a workaround ... mount the snapshot volume as a symbolic link and use the link to access the files. 有一种解决方法...将快照卷作为符号链接安装,然后使用该链接访问文件。 Here's the code I used: 这是我使用的代码:

VSS_SNAPSHOT_PROP prop;
result = backupComponents->GetSnapshotProperties(snapshotId, &prop);    
wchar_t *snapVol = prop.m_pwszSnapshotDeviceObject;
wcsncat(snapVol, L"\\", 1);
if (QDir("C:\\repVSSVol").exists())
    RemoveDirectory(L"C:\\repVSSVol");
if (CreateSymbolicLink(L"C:\\repVSSVol", snapVol, SYMBOLIC_LINK_FLAG_DIRECTORY) == 0)
    win32Error(TEXT("CreateSymbolicLink"));

Also be careful removing symbolic directory links as explained here . 另外要小心删除符号目录链接作为解释在这里

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

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