Volume Shadow Copy using Java
Asked Answered
R

3

6

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)?

Rahel answered 15/3, 2012 at 21:23 Comment(2)
This is just an opinion, but what you are trying to do is a job for a "native" language, such as C++. It's a huge hassle to connect to OS APIs from Java and it's freaking slow.Pennyworth
JNI is'nt slow - and if it actually is for you ... well ... you most likely have major programming mistakes in your code. Its also no "hassle" to write native libraries for JNI but its rather .... inconvenient - if you never wrote C/C++ you most likely will have got a lot to learn and a few things to consider but thats just about it - theres also JNA which makes it a bit easier and less of a "hassle"Gabe
E
8

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.

Expunge answered 10/10, 2012 at 14:21 Comment(0)
G
2

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.

Garvey answered 15/3, 2012 at 21:25 Comment(0)
P
1

Hmm ... doing it via Java can be tricky and very error prone

One easy way to do it is writing a small native DLL which does what you want VSS to do using VSS APIs

And then using either C# pInvoke or C++/CLI ... and then you can use any other CLI compliant language

Passionate answered 15/3, 2012 at 22:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.