forked from pquiring/javaforce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVSS.java
More file actions
107 lines (97 loc) · 3.24 KB
/
Copy pathVSS.java
File metadata and controls
107 lines (97 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package javaforce.utils;
/** VSS - Volume Shadow Service command line API
*
* @author pquiring
*/
import javaforce.*;
import javaforce.jni.WinNative;
public class VSS {
public static void usage() {
System.out.println("Usage : VSS {command}");
System.out.println(" listvols : list volumes");
System.out.println(" listshadows : list shadows");
System.out.println(" createshadow {drive} [path] : create shadow (optional mount to path)");
System.out.println(" mountshadow {path} {shadow-vol} : mount shadow");
System.out.println(" unmountshadow {path} : unmount shadow");
System.out.println(" deleteshadow {shadow-id} : delete shadow (/all for all shadows)");
System.exit(1);
}
public static void main(String[] args) {
if (args.length == 0) usage();
if (!WinNative.vssInit()) {
JFLog.log("VSS Init Failed");
return;
}
switch (args[0]) {
case "listvols": listvols(args); break;
case "listshadows": listshadows(args); break;
case "createshadow": createshadow(args); break;
case "mountshadow": mountshadow(args); break;
case "unmountshadow": unmountshadow(args); break;
case "deleteshadow": deleteshadow(args); break;
default: usage();
}
}
public static void listvols(String[] args) {
String[] vols = WinNative.vssListVols();
for(String vol : vols) {
System.out.println("Volume : " + vol);
}
}
public static void listshadows(String[] args) {
String[][] shadows = WinNative.vssListShadows();
for(String[] shadow : shadows) {
System.out.println("GUID : " + shadow[0]);
System.out.println("Shadow Volume : " + shadow[1]);
System.out.println("Volume : " + shadow[2]);
}
}
public static void createshadow(String[] args) {
if (args.length < 2) usage();
if (args.length > 2) {
if (WinNative.vssCreateShadow(args[1], args[2])) {
System.out.println("Shadow creation and mount successful!");
} else {
System.out.println("Shadow creation failed!");
}
} else {
if (WinNative.vssCreateShadow(args[1])) {
System.out.println("Shadow creation successful!");
} else {
System.out.println("Shadow creation failed!");
}
}
}
public static void mountshadow(String[] args) {
if (args.length != 3) usage();
if (WinNative.vssMountShadow(args[1], args[2])) {
System.out.println("Shadow mount successful!");
} else {
System.out.println("Shadow mount failed!");
}
}
public static void unmountshadow(String[] args) {
if (args.length != 2) usage();
if (WinNative.vssUnmountShadow(args[1])) {
System.out.println("Shadow unmount successful!");
} else {
System.out.println("Shadow unmount failed!");
}
}
public static void deleteshadow(String[] args) {
if (args.length != 2) usage();
if (args[1].equals("/all")) {
if (WinNative.vssDeleteShadowAll()) {
System.out.println("Shadow deletion(s) successful!");
} else {
System.out.println("Shadow deletion(s) failed!");
}
} else {
if (WinNative.vssDeleteShadow(args[1])) {
System.out.println("Shadow deletion successful!");
} else {
System.out.println("Shadow deletion failed!");
}
}
}
}