Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening a file's Shadow Copy if the current copy is in use

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.

like image 865
Malfist Avatar asked Mar 18 '09 20:03

Malfist


People also ask

How do I open a shadow copy?

Windows operating system allows you to access the 'Shadow Copies' by right-clicking on the file/folder/drive, choosing 'Properties' and then 'Previous Versions'.

How do I restore a file using shadow copy?

Click Restore my files. Click Browse for files or Browse for folders. Select the items that you want to back up, and then click Next. Select the destination path, and then click Restore.

How do I enable previous versions in shadow copies?

Right-click the parent folder with the file you want to restore and select the Properties option. Click the Previous Versions tab. Under the “File versions” section, you will find a list of the different times where a shadow copy was created that allows you to recover a file (or folder). Select the content.


1 Answers

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

like image 105
Tom Avatar answered Oct 16 '22 14:10

Tom