Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Volume Shadow Copy using Java

I am currently creating a backup application where we need a way to read files that are in use by other applications and we also want to minimize the locking the we incur on the users' files. Using Window's Volume Shadow Copy Service seems to be perfect way for us to achieve this.

Our problem however is that we are using Java. Is there any easy way for us to implement this anyway (either using some library or possibly even some CLI)?

like image 284
Yrlec Avatar asked Mar 15 '12 21:03

Yrlec


2 Answers

I did this before.

The easiest way we found out was to build the 4 versions of vshadow.exe (demo tool for a quick start with VSS from Microsoft website): one for each target plaform within XP/later and x86/x64. VShadow basically allow to create or destroy snapshot and retrieve a Path that looks like:

\\\?\GLOBALROOT\Device\HarddiskVolumeShadowCopyXX that you can use to replace your drive letter (D: for instance) that works with the JAVA File API. The version of VShadow from VSS SDK is read and write, this is not the same version than the exe you can download directly wich is read only.

Then, in Java, it is easy to write two CLI wrappers with a unified interface (for handling the two different behaviour of VShadow between XP and Later).

Good luck.

like image 83
Renaud Avatar answered Sep 21 '22 06:09

Renaud


So, I don't know much about VSS, but in terms of accessing Windows native APIs from Java, I would check out JNA. You may well find somebody has already ported the relevant API definitions to JNA.

like image 26
dty Avatar answered Sep 20 '22 06:09

dty