如果当前副本正在使用中,则打开文件的卷影副本

发布于 2024-07-15 05:31:23 字数 116 浏览 8 评论 0原文

我正在尝试备份服务器上的文件,但其中一些文件正在使用中且无法打开。 相反,如果当前副本正在使用中,我想打开其卷影副本。 我怎样才能做到这一点?

作为参考,我使用的是 C# .net 3.5。

I'm trying to backup files on a server, but some of them are in use and cannot be opened. Instead, I'd like to open their shadow copy if the current copy is in use. How can I do this?

For reference, I'm using C# .net 3.5.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

殤城〤 2024-07-22 05:31:23

这个问题已经很老了,所以我的答案可能对你没有多大用处,但作为一个问答网站,也许它仍然可以帮助其他人。

我不能/不想放下整个实现,但过程是这样的:

  1. 您通过卷影服务提供程序为要读取的文件所在的驱动器创建卷影副本位于(MSDN 上有详细记录,还有一个示例客户端可以创建这些卷影副本,并且很可能足以满足您的需要)

  2. 要么创建一个持久卷影副本,要么使用“回调”机制(调用您的应用程序)

  3. 通过 UNC 路径和 CreateFile 打开所需的文件(UNC 看起来像这样:
    \\?\GlobalRoot\Devices\HarddiskVolumeShadowCopyXZY\yourpath\yourfile.yourextension)

  4. 对文件执行任何您想要的操作

  5. 如果您创建了持久 VSC,则应使用示例客户端来 在此处完成

更多信息后将其删除:http: //technet.microsoft.com/en-us/library/cc785914%28WS.10%29.aspx
在这里: http://msdn.microsoft.com/ en-us/library/bb968832%28VS.85%29.aspx

This question is quite old already, so my answer might not be of much use to you, but SO being a Q&A site maybe it still helps someone else.

I can't / don't want to put down the entire implementation, but the procedure is goes something like this:

  1. You create a Volume Shadow Copy via the Volume Shadow Service Provider for the drive where your file to be read is located(this is well documented on MSDN, also there is a sample client that creates these shadow copies and will most likely be sufficient for you)

  2. Either make a persistent one, or use the "callback" mechanism (calls your app)

  3. Open the desired file via UNC paths and CreateFile (the UNC looks something like this:
    \\?\GlobalRoot\Devices\HarddiskVolumeShadowCopyXZY\yourpath\yourfile.yourextension)

  4. Do whatever you want with the file

  5. If you made a persistent VSC you should use the sample client to delete it after you're done

more info here: http://technet.microsoft.com/en-us/library/cc785914%28WS.10%29.aspx
and here: http://msdn.microsoft.com/en-us/library/bb968832%28VS.85%29.aspx

最笨的告白 2024-07-22 05:31:23

我实际上无法判断,但有以下第 9 频道的视频。

Windows Vista " 《Time Warp》:了解 Vista 的备份和恢复技术

其中有一些实现细节以及一些有关 API 结构的内容。 我相信请记住他们提到了卷影副本如何映射到文件系统中。

I cannot actually tell, but there is the following Channel 9 video.

Windows Vista "Time Warp": Understanding Vista's Backup and Restore Technologies

There are some implementation details and a bit about the API structure. And I believe to remember that they mentioned how the shadow copies are mapped into the file system.

听不够的曲调 2024-07-22 05:31:23

如果您控制第一个进程,则可以指定文件句柄共享类型

string contents1;
string contents2;
using (FileStream fs1 = new FileStream("test.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
    using (var tr1 = new StreamReader(fs1))
    {
        using (FileStream fs2 = new FileStream("test.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
        {
            using (var tr2 = new StreamReader(fs2))
            {
                contents2 = tr2.ReadToEnd();
                contents1 = tr1.ReadToEnd();
            }
        }
    }
}

Console.WriteLine(contents1);
Console.WriteLine(contents2);

If you have control of the first process you can specify file handle share type

string contents1;
string contents2;
using (FileStream fs1 = new FileStream("test.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
    using (var tr1 = new StreamReader(fs1))
    {
        using (FileStream fs2 = new FileStream("test.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
        {
            using (var tr2 = new StreamReader(fs2))
            {
                contents2 = tr2.ReadToEnd();
                contents1 = tr1.ReadToEnd();
            }
        }
    }
}

Console.WriteLine(contents1);
Console.WriteLine(contents2);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文