├── .gitignore
├── HVBackup.sln
├── HyperVBackup.Console
├── HVBackup.Console.csproj
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
├── app.config
└── packages.config
├── HyperVBackup.Engine
├── BackupCancelledException.cs
├── BackupManager.cs
├── BackupProgressEventArgs.cs
├── CSV.cs
├── EventAction.cs
├── HVBackup.Engine.csproj
├── HVBackup.Engine.csproj.user
├── NLog.config
├── Options.cs
├── Properties
│ └── AssemblyInfo.cs
├── VmNameType.cs
└── packages.config
├── LICENSE
├── Lib
├── SevenZipSharp.dll
├── x64
│ └── 7z.dll
└── x86
│ └── 7z.dll
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # This .gitignore file was automatically created by Microsoft(R) Visual Studio.
3 | ################################################################################
4 |
5 | /HyperVBackup.Console/bin
6 | /HyperVBackup.Console/obj
7 | /HyperVBackup.Engine/bin
8 | /HyperVBackup.Engine/obj
9 | /packages
10 | /.vs
11 | /.vs/HVBackup/v15/.suo
12 |
--------------------------------------------------------------------------------
/HVBackup.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26430.13
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HVBackup.Engine", "HyperVBackup.Engine\HVBackup.Engine.csproj", "{096F7CB1-EC67-4388-A7A4-1747EE09DB29}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HVBackup.Console", "HyperVBackup.Console\HVBackup.Console.csproj", "{15A16478-D2E8-431C-99BA-EAABE878B450}"
9 | EndProject
10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Lib", "Lib", "{84AD2C1E-E2F3-4D47-8E90-1A9C2FC39A38}"
11 | ProjectSection(SolutionItems) = preProject
12 | Lib\SevenZipSharp.dll = Lib\SevenZipSharp.dll
13 | EndProjectSection
14 | EndProject
15 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "x86", "x86", "{58B16447-86C0-49AC-A91E-A09102FA2FB7}"
16 | ProjectSection(SolutionItems) = preProject
17 | Lib\x86\7z.dll = Lib\x86\7z.dll
18 | EndProjectSection
19 | EndProject
20 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "x64", "x64", "{D3B4C643-CC63-4E0A-86CF-7AB4F80D22C0}"
21 | ProjectSection(SolutionItems) = preProject
22 | Lib\x64\7z.dll = Lib\x64\7z.dll
23 | EndProjectSection
24 | EndProject
25 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docs", "Docs", "{8ACEB569-DD44-4FF9-9BA5-4B8A2B33AAE7}"
26 | ProjectSection(SolutionItems) = preProject
27 | LICENSE = LICENSE
28 | README.md = README.md
29 | EndProjectSection
30 | EndProject
31 | Global
32 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
33 | Debug|Any CPU = Debug|Any CPU
34 | Debug|x64 = Debug|x64
35 | Debug|x86 = Debug|x86
36 | Release|Any CPU = Release|Any CPU
37 | Release|x64 = Release|x64
38 | Release|x86 = Release|x86
39 | EndGlobalSection
40 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
41 | {096F7CB1-EC67-4388-A7A4-1747EE09DB29}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
42 | {096F7CB1-EC67-4388-A7A4-1747EE09DB29}.Debug|Any CPU.Build.0 = Debug|Any CPU
43 | {096F7CB1-EC67-4388-A7A4-1747EE09DB29}.Debug|x64.ActiveCfg = Debug|x64
44 | {096F7CB1-EC67-4388-A7A4-1747EE09DB29}.Debug|x64.Build.0 = Debug|x64
45 | {096F7CB1-EC67-4388-A7A4-1747EE09DB29}.Debug|x86.ActiveCfg = Debug|Any CPU
46 | {096F7CB1-EC67-4388-A7A4-1747EE09DB29}.Release|Any CPU.ActiveCfg = Release|Any CPU
47 | {096F7CB1-EC67-4388-A7A4-1747EE09DB29}.Release|Any CPU.Build.0 = Release|Any CPU
48 | {096F7CB1-EC67-4388-A7A4-1747EE09DB29}.Release|x64.ActiveCfg = Release|x64
49 | {096F7CB1-EC67-4388-A7A4-1747EE09DB29}.Release|x64.Build.0 = Release|x64
50 | {096F7CB1-EC67-4388-A7A4-1747EE09DB29}.Release|x86.ActiveCfg = Release|x86
51 | {096F7CB1-EC67-4388-A7A4-1747EE09DB29}.Release|x86.Build.0 = Release|x86
52 | {15A16478-D2E8-431C-99BA-EAABE878B450}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
53 | {15A16478-D2E8-431C-99BA-EAABE878B450}.Debug|Any CPU.Build.0 = Debug|Any CPU
54 | {15A16478-D2E8-431C-99BA-EAABE878B450}.Debug|x64.ActiveCfg = Debug|x64
55 | {15A16478-D2E8-431C-99BA-EAABE878B450}.Debug|x64.Build.0 = Debug|x64
56 | {15A16478-D2E8-431C-99BA-EAABE878B450}.Debug|x86.ActiveCfg = Debug|x86
57 | {15A16478-D2E8-431C-99BA-EAABE878B450}.Debug|x86.Build.0 = Debug|x86
58 | {15A16478-D2E8-431C-99BA-EAABE878B450}.Release|Any CPU.ActiveCfg = Release|Any CPU
59 | {15A16478-D2E8-431C-99BA-EAABE878B450}.Release|Any CPU.Build.0 = Release|Any CPU
60 | {15A16478-D2E8-431C-99BA-EAABE878B450}.Release|x64.ActiveCfg = Release|x64
61 | {15A16478-D2E8-431C-99BA-EAABE878B450}.Release|x64.Build.0 = Release|x64
62 | {15A16478-D2E8-431C-99BA-EAABE878B450}.Release|x86.ActiveCfg = Release|x86
63 | {15A16478-D2E8-431C-99BA-EAABE878B450}.Release|x86.Build.0 = Release|x86
64 | EndGlobalSection
65 | GlobalSection(SolutionProperties) = preSolution
66 | HideSolutionNode = FALSE
67 | EndGlobalSection
68 | GlobalSection(NestedProjects) = preSolution
69 | {58B16447-86C0-49AC-A91E-A09102FA2FB7} = {84AD2C1E-E2F3-4D47-8E90-1A9C2FC39A38}
70 | {D3B4C643-CC63-4E0A-86CF-7AB4F80D22C0} = {84AD2C1E-E2F3-4D47-8E90-1A9C2FC39A38}
71 | EndGlobalSection
72 | EndGlobal
73 |
--------------------------------------------------------------------------------
/HyperVBackup.Console/HVBackup.Console.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | x86
6 | 8.0.30703
7 | 2.0
8 | {15A16478-D2E8-431C-99BA-EAABE878B450}
9 | Exe
10 | Properties
11 | HyperVBackup.Console
12 | HyperVBackup
13 | v4.6.1
14 | 512
15 | SAK
16 | SAK
17 | SAK
18 | SAK
19 |
20 | publish\
21 | true
22 | Disk
23 | false
24 | Foreground
25 | 7
26 | Days
27 | false
28 | false
29 | true
30 | 0
31 | 1.0.0.%2a
32 | false
33 | false
34 | true
35 |
36 |
37 | AnyCPU
38 | true
39 | full
40 | false
41 | bin\x86\Debug\
42 | DEBUG;TRACE
43 | prompt
44 | 4
45 | false
46 |
47 |
48 | x86
49 | pdbonly
50 | true
51 | bin\Release\x86\
52 | TRACE
53 | prompt
54 | 4
55 | false
56 |
57 |
58 | false
59 |
60 |
61 |
62 |
63 |
64 |
65 | true
66 | bin\x64\Debug\
67 | DEBUG;TRACE
68 | full
69 | AnyCPU
70 | prompt
71 | MinimumRecommendedRules.ruleset
72 | false
73 |
74 |
75 | bin\Release\x64\
76 | TRACE
77 | true
78 | pdbonly
79 | x64
80 | prompt
81 | MinimumRecommendedRules.ruleset
82 | false
83 |
84 |
85 | true
86 | bin\Debug\
87 | DEBUG;TRACE
88 | full
89 | AnyCPU
90 | prompt
91 | MinimumRecommendedRules.ruleset
92 | false
93 |
94 |
95 | bin\Release\
96 | TRACE
97 | true
98 | pdbonly
99 | AnyCPU
100 | prompt
101 | MinimumRecommendedRules.ruleset
102 | false
103 |
104 |
105 | HyperVBackup.Console.Program
106 |
107 |
108 |
109 | ..\packages\CommandLineParser.1.9.71\lib\net45\CommandLine.dll
110 | True
111 |
112 |
113 | ..\packages\NLog.4.4.9\lib\net45\NLog.dll
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 | False
129 | Microsoft .NET Framework 4.5.1 %28x86 and x64%29
130 | true
131 |
132 |
133 | False
134 | .NET Framework 3.5 SP1 Client Profile
135 | false
136 |
137 |
138 | False
139 | .NET Framework 3.5 SP1
140 | false
141 |
142 |
143 |
144 |
145 | {096f7cb1-ec67-4388-a7a4-1747ee09db29}
146 | HVBackup.Engine
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
161 |
--------------------------------------------------------------------------------
/HyperVBackup.Console/Program.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Cloudbase Solutions Srl + 2016 Coliseo Software srl
3 | *
4 | * This program is free software; you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation; either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with this program; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | using System;
20 | using System.Collections.Generic;
21 | using System.Diagnostics;
22 | using System.IO;
23 | using System.Linq;
24 | using System.Security.Principal;
25 | using System.Text;
26 | using CommandLine;
27 | using CommandLine.Text;
28 | using HyperVBackUp.Engine;
29 | using NLog;
30 |
31 | namespace HyperVBackup.Console
32 | {
33 | class Program
34 | {
35 | static volatile bool _cancel = false;
36 | static int _currentWidth = 0;
37 | static int _consoleWidth = 0;
38 | private static ILogger _logger;
39 |
40 | class Options
41 | {
42 | [Option('f', "file", HelpText = "Text file containing a list of VMs to backup, one per line. If not set all VM are included.", MutuallyExclusiveSet = "flax")]
43 | public string File { get; set; }
44 |
45 | [OptionList('l', "list", Separator = ',', HelpText = "List of VMs to backup, comma separated. If not set all VM are included.", MutuallyExclusiveSet = "flax")]
46 | public IList List { get; set; }
47 |
48 | [OptionList('x', "exclude", Separator = ',', HelpText = "List of VMs to exclude from backup, comma separated. Use when all VM are included.", MutuallyExclusiveSet = "flax")]
49 | public IList Exclude { get; set; }
50 |
51 | [OptionList('v', "vhdinclude", Separator = ',', HelpText = "List of VHDs file names to backup, comma separated.")]
52 | public IList VhdInclude { get; set; }
53 |
54 | [OptionList('i', "vhdignore", Separator = ',', HelpText = "List of VHDs file names to ignore, comma separated.")]
55 | public IList VhdIgnore { get; set; }
56 |
57 | [Option('n', "name", HelpText = "If set, VMs to backup are specified by name.", MutuallyExclusiveSet = "ng", DefaultValue = true)]
58 | public bool Name { get; set; }
59 |
60 | [Option('o', "output", Required = true, HelpText = "Backup ouput folder.")]
61 | public string Output { get; set; }
62 |
63 | [Option('p', "password", HelpText = "Secure the backup with a password.")]
64 | public string Password { get; set; }
65 |
66 | [Option('z', "zip", HelpText = "Use the zip format to store the backup insted of the 7zip format.", MutuallyExclusiveSet = "zd")]
67 | public bool ZipFormat { get; set; }
68 |
69 | [Option('d', "directcopy", HelpText = "Do not compress the output, just copy the files recreating the folder structure.", MutuallyExclusiveSet = "zd")]
70 | public bool DirectCopy { get; set; }
71 |
72 | [Option("outputformat", HelpText = "Backup archive name format. {0} is the VM's name, {1} the VM's GUID, {2} is the current date and time and {3} is the extension for the compression format (7z or zip). Default: \"{0}_{2:yyyyMMddHHmmss}{3}\"")]
73 | public string OutputFormat { get; set; } = "{0}_{2:yyyyMMddHHmmss}{3}";
74 |
75 | [Option('s', "singlevss", HelpText = "Perform one single snapshot for all the VMs.")]
76 | public bool SingleSnapshot { get; set; }
77 |
78 | [Option("compressionlevel", DefaultValue = -1, HelpText = "Compression level, between 0 (no compression, very fast) and 9 (max. compression, very slow).")]
79 | public int CompressionLevel { get; set; }
80 |
81 | [Option("cleanoutputbydays", DefaultValue = 0, HelpText = "Delete all files in the output folder older than x days. TOTALLY OPTIONAL. USE WITH CAUTION.")]
82 | public int CleanOutputDays { get; set; }
83 |
84 | [Option("cleanoutputbymb", DefaultValue = 0, HelpText = "Delete older files in the output folder if total size is bigger then x Megabytes. TOTALLY OPTIONAL. USE WITH CAUTION.")]
85 | public int CleanOutputMb { get; set; }
86 |
87 | [Option("onsuccess", HelpText = "Execute this program if backup completes correctly.")]
88 | public string OnSuccess { get; set; }
89 |
90 | [Option("onfailure", HelpText = "Execute this program if backup fails.")]
91 | public string OnFailure { get; set; }
92 |
93 | [Option("mt", HelpText = "Enable multi-threaded compression (only for 7zip format).")]
94 | public bool MultiThreaded { get; set; }
95 |
96 | [HelpOption(HelpText = "Display this help screen.")]
97 | public string GetUsage()
98 | {
99 | var header = new StringBuilder();
100 | header.AppendLine();
101 | header.AppendLine("Note: short switchs use one dash (-) / long switches use two dashes (--). Example: HyperVBackup -l \"Mail Server\" --compressionlevel 0");
102 | header.AppendLine();
103 |
104 | var help = new HelpText(header.ToString()) { AdditionalNewLineAfterOption = false };
105 | HandleParsingErrorsInHelp(help);
106 | help.AddOptions(this);
107 |
108 | return help.ToString();
109 | }
110 |
111 | private void HandleParsingErrorsInHelp(HelpText help)
112 | {
113 | var errors = help.RenderParsingErrorsText(this, 1);
114 | if (!string.IsNullOrEmpty(errors))
115 | {
116 | help.AddPreOptionsLine(string.Concat("ERROR: ", errors, Environment.NewLine));
117 | }
118 | }
119 | }
120 |
121 | private static void Main(string[] args)
122 | {
123 | _logger = LogManager.GetCurrentClassLogger();
124 | var options = new Options();
125 |
126 | try
127 | {
128 | var stopwatch = new Stopwatch();
129 | stopwatch.Start();
130 |
131 | System.Console.WriteLine("HyperVBackup 3");
132 | System.Console.WriteLine("Copyright (C) 2012 Cloudbase Solutions SRL");
133 | System.Console.WriteLine("Copyright (C) 2016/2017 Coliseo Software SRL");
134 |
135 | _logger.Info($"HyperVBackup started at {DateTime.Now}");
136 |
137 | if (!IsAdministrator())
138 | {
139 | throw new Exception("HyperVBackup requires administrator permissions");
140 | }
141 |
142 | var parser = new Parser(ConfigureSettings);
143 | if (parser.ParseArgumentsStrict(args, options, () => Environment.Exit(1)))
144 | {
145 | GetConsoleWidth();
146 | System.Console.WriteLine();
147 |
148 | var vmNames = GetVmNames(options);
149 |
150 | if (vmNames == null)
151 | {
152 | _logger.Info("Backing up all VMs on this server");
153 | }
154 |
155 | if (!Directory.Exists(options.Output))
156 | {
157 | throw new Exception($"The folder \"{options.Output}\" is not valid");
158 | }
159 |
160 | if (options.CleanOutputDays != 0)
161 | {
162 | CleanOutputByDays(options.Output, options.CleanOutputDays);
163 | }
164 |
165 | if (options.CleanOutputMb != 0)
166 | {
167 | CleanOutputByMegabytes(options.Output, options.CleanOutputMb);
168 | }
169 |
170 | var nameType = options.Name ? VmNameType.ElementName : VmNameType.SystemName;
171 |
172 | var mgr = new BackupManager();
173 | mgr.BackupProgress += MgrBackupProgress;
174 |
175 | System.Console.CancelKeyPress += Console_CancelKeyPress;
176 |
177 | var backupOptions = new HyperVBackUp.Engine.Options
178 | {
179 | CompressionLevel = options.CompressionLevel,
180 | Output = options.Output,
181 | OutputFormat = options.OutputFormat,
182 | SingleSnapshot = options.SingleSnapshot,
183 | VhdInclude = options.VhdInclude,
184 | VhdIgnore = options.VhdIgnore,
185 | Password = options.Password,
186 | ZipFormat = options.ZipFormat,
187 | DirectCopy = options.DirectCopy,
188 | MultiThreaded = options.MultiThreaded,
189 | Exclude = options.Exclude
190 | };
191 |
192 | var vmNamesMap = mgr.VssBackup(vmNames, nameType, backupOptions, _logger);
193 |
194 | var success = CheckRequiredVMs(vmNames, nameType, vmNamesMap);
195 |
196 | ShowElapsedTime(stopwatch);
197 |
198 | if (success)
199 | {
200 | if (!string.IsNullOrEmpty(options.OnSuccess))
201 | {
202 | _logger.Info("Executing OnSucess program");
203 | ExecuteProcess(options.OnSuccess, _logger);
204 |
205 | }
206 | }
207 | else
208 | {
209 | if (!string.IsNullOrEmpty(options.OnFailure))
210 | {
211 | _logger.Info("Executing OnFailure program");
212 | ExecuteProcess(options.OnFailure, _logger);
213 | }
214 | }
215 |
216 | _logger.Info($"HyperVBackup ended at {DateTime.Now}");
217 | }
218 | }
219 | catch (BackupCancelledException ex)
220 | {
221 | System.Console.Error.WriteLine(string.Format(ex.Message));
222 | _logger.Error(ex.ToString());
223 |
224 | if (!string.IsNullOrEmpty(options.OnFailure))
225 | {
226 | _logger.Info("Executing OnFailure program");
227 | ExecuteProcess(options.OnFailure, _logger);
228 | }
229 |
230 | Environment.Exit(3);
231 | }
232 | catch (Exception ex)
233 | {
234 | System.Console.Error.WriteLine($"Error: {ex.Message}");
235 | System.Console.Error.WriteLine(ex.StackTrace);
236 | _logger.Error(ex.ToString());
237 |
238 | if (!string.IsNullOrEmpty(options.OnFailure))
239 | {
240 | _logger.Info("Executing OnFailure program");
241 | ExecuteProcess(options.OnFailure, _logger);
242 | }
243 |
244 | Environment.Exit(2);
245 | }
246 |
247 | Environment.Exit(_cancel ? 3 : 0);
248 | }
249 |
250 | private static void ExecuteProcess(string fileName, ILogger logger)
251 | {
252 | if (string.IsNullOrEmpty(fileName))
253 | {
254 | return;
255 | }
256 |
257 | using (var process = new Process())
258 | {
259 | logger.Debug($"Executing program {fileName}");
260 |
261 | process.StartInfo.FileName = fileName;
262 | process.StartInfo.WorkingDirectory = Path.GetDirectoryName(fileName);
263 | process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
264 | process.StartInfo.UseShellExecute = false;
265 | process.StartInfo.RedirectStandardOutput = true;
266 | process.StartInfo.RedirectStandardError = true;
267 | process.StartInfo.CreateNoWindow = true;
268 |
269 | process.Start();
270 | process.WaitForExit();
271 |
272 | var output = process.StandardOutput.ReadToEnd();
273 | var error = process.StandardError.ReadToEnd();
274 | var exitCode = process.ExitCode;
275 |
276 | process.Close();
277 |
278 | logger.Info($"Exit code of executing program {fileName} is {exitCode}");
279 | logger.Debug($"Output of executing program {fileName} is {output}");
280 | logger.Debug($"Errors of executing program {fileName} are {error}");
281 | }
282 | }
283 |
284 | private static void CleanOutputByDays(string output, int days)
285 | {
286 | foreach (var file in Directory.GetFiles(output))
287 | {
288 | var fileInfo = new FileInfo(file);
289 | if (fileInfo.LastWriteTime < DateTime.Now.AddDays(days * -1))
290 | {
291 | _logger.Info($"Deleting file {fileInfo.Name}");
292 | fileInfo.Delete();
293 | }
294 | }
295 | }
296 |
297 | private static void CleanOutputByMegabytes(string output, int totalMb)
298 | {
299 | var dirInfo = new DirectoryInfo(output);
300 | var totalSize = dirInfo.EnumerateFiles().Sum(file => file.Length);
301 | var desiredMaxSize = (long)totalMb * 1024 * 1024;
302 |
303 | if (totalSize > desiredMaxSize)
304 | {
305 | _logger.Info($"Size of output folder is {totalSize / 1024 / 1024} Megabytes, deleting some files ...");
306 |
307 | var files = dirInfo.GetFiles();
308 | while (totalSize > desiredMaxSize && files.Length != 0)
309 | {
310 | var sortedFiles = files.OrderBy(f => f.LastWriteTime).ToList();
311 | var filetoDelete = sortedFiles[0].FullName;
312 | _logger.Info($"Deleting file {filetoDelete}");
313 |
314 | try
315 | {
316 | File.Delete(filetoDelete);
317 | }
318 | catch (Exception e)
319 | {
320 | _logger.Error($"Cannot delete file {filetoDelete} - {e}");
321 | }
322 |
323 | files = dirInfo.GetFiles();
324 | totalSize = files.Sum(file => file.Length);
325 | }
326 | }
327 | }
328 |
329 | private static void ConfigureSettings(ParserSettings settings)
330 | {
331 | settings.MutuallyExclusive = true;
332 | settings.HelpWriter = System.Console.Out;
333 | }
334 |
335 | private static void ShowElapsedTime(Stopwatch stopwatch)
336 | {
337 | stopwatch.Stop();
338 | var ts = stopwatch.Elapsed;
339 | _logger.Info(
340 | $"Elapsed time: {ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}.{ts.Milliseconds:000}");
341 | }
342 |
343 | private static bool CheckRequiredVMs(IEnumerable vmNames, VmNameType nameType, IDictionary vmNamesMap)
344 | {
345 | var withErrors = false;
346 |
347 | if (vmNames != null)
348 | {
349 | foreach (var vmName in vmNames)
350 | {
351 | if (nameType == VmNameType.SystemName && !vmNamesMap.Keys.Contains(vmName, StringComparer.OrdinalIgnoreCase) ||
352 | nameType == VmNameType.ElementName && !vmNamesMap.Values.Contains(vmName, StringComparer.OrdinalIgnoreCase))
353 | {
354 | _logger.Error($"\"{vmName}\" not found");
355 | withErrors = true;
356 | }
357 |
358 | }
359 | }
360 |
361 | return !withErrors;
362 | }
363 |
364 | private static void GetConsoleWidth()
365 | {
366 | try
367 | {
368 | _consoleWidth = System.Console.WindowWidth;
369 | }
370 | catch (Exception)
371 | {
372 | _consoleWidth = 80;
373 | }
374 | }
375 |
376 | private static ICollection GetVmNames(Options options)
377 | {
378 | ICollection vmNames = null;
379 |
380 | if (options.File != null)
381 | {
382 | vmNames = File.ReadAllLines(options.File);
383 | }
384 | else if (options.List != null)
385 | {
386 | vmNames = options.List;
387 | }
388 |
389 | if (vmNames != null)
390 | {
391 | vmNames = (from o in vmNames where o.Trim().Length > 0 select o.Trim()).ToList();
392 | }
393 |
394 | return vmNames;
395 | }
396 |
397 | static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e)
398 | {
399 | System.Console.Error.WriteLine();
400 | System.Console.Error.WriteLine("Cancelling backup...");
401 |
402 | // Avoid CTRL+C during VSS snapshots
403 | _cancel = true;
404 | e.Cancel = true;
405 | }
406 |
407 | static void MgrBackupProgress(object sender, BackupProgressEventArgs e)
408 | {
409 | switch (e.Action)
410 | {
411 | case EventAction.InitializingVss:
412 | _logger.Info("Initializing VSS");
413 | break;
414 |
415 | case EventAction.StartingSnaphotSet:
416 | _logger.Info("Starting snapshot set for:");
417 |
418 | foreach (var componentName in e.Components.Values)
419 | {
420 | _logger.Info(componentName);
421 | }
422 |
423 | _logger.Info("");
424 | _logger.Info("Volumes:");
425 | foreach (var volumePath in e.VolumeMap.Keys)
426 | {
427 | System.Console.WriteLine(volumePath);
428 | }
429 | break;
430 |
431 | case EventAction.DeletingSnapshotSet:
432 | _logger.Info("Deleting snapshot set");
433 | break;
434 |
435 | case EventAction.StartingArchive:
436 | _logger.Info("");
437 | _logger.Info($"Creating archive: \"{e.AcrhiveFileName}\"");
438 | break;
439 |
440 | case EventAction.StartingEntry:
441 | _logger.Info($"Compressing entry: \"{e.CurrentEntry}\"");
442 | _currentWidth = 0;
443 | break;
444 |
445 | //case EventAction.SavingEntry:
446 | // if (e.TotalBytesToTransfer > 0)
447 | // {
448 | // var width = (int)Math.Round(e.BytesTransferred * _consoleWidth / (decimal)e.TotalBytesToTransfer);
449 |
450 | // for (var i = 0; i < width - _currentWidth; i++)
451 | // {
452 | // System.Console.Write(".");
453 | // }
454 |
455 | // _currentWidth = width;
456 |
457 | // if (e.BytesTransferred == e.TotalBytesToTransfer)
458 | // {
459 | // System.Console.WriteLine();
460 | // }
461 |
462 | // System.Console.WriteLine($"{e.BytesTransferred * 100 / (decimal) e.TotalBytesToTransfer:0.#}%");
463 | // }
464 | // break;
465 |
466 | case EventAction.PercentProgress:
467 | var progressWidth = e.PercentDone * _consoleWidth / 100;
468 |
469 | for (var i = 0; i < progressWidth - _currentWidth; i++)
470 | {
471 | System.Console.Write(".");
472 | }
473 | _currentWidth = progressWidth;
474 |
475 | if (e.PercentDone == 100)
476 | {
477 | System.Console.WriteLine();
478 | }
479 |
480 | _logger.Debug($"Percent done: {e.PercentDone}%");
481 |
482 | break;
483 | }
484 |
485 | e.Cancel = _cancel;
486 | }
487 |
488 | public static bool IsAdministrator()
489 | {
490 | return (new WindowsPrincipal(WindowsIdentity.GetCurrent()))
491 | .IsInRole(WindowsBuiltInRole.Administrator);
492 | }
493 | }
494 | }
495 |
--------------------------------------------------------------------------------
/HyperVBackup.Console/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Cloudbase Solutions Srl
3 | *
4 | * This program is free software; you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation; either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with this program; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | using System.Reflection;
20 | using System.Runtime.CompilerServices;
21 | using System.Runtime.InteropServices;
22 |
23 | // General Information about an assembly is controlled through the following
24 | // set of attributes. Change these attribute values to modify the information
25 | // associated with an assembly.
26 | [assembly: AssemblyTitle("HyperVBackup Console")]
27 | [assembly: AssemblyDescription("")]
28 | [assembly: AssemblyConfiguration("")]
29 | [assembly: AssemblyCompany("Cloudbase Solutions Srl + Coliseo Software Srl")]
30 | [assembly: AssemblyProduct("HyperVBackup")]
31 | [assembly: AssemblyCopyright("Copyright © Cloudbase Solutions Srl 2012 + Coliseo Software Srl")]
32 | [assembly: AssemblyTrademark("")]
33 | [assembly: AssemblyCulture("")]
34 |
35 | // Setting ComVisible to false makes the types in this assembly not visible
36 | // to COM components. If you need to access a type in this assembly from
37 | // COM, set the ComVisible attribute to true on that type.
38 | [assembly: ComVisible(false)]
39 |
40 | // The following GUID is for the ID of the typelib if this project is exposed to COM
41 | [assembly: Guid("75a152b4-30a8-47b7-ab1f-59ed82206d9c")]
42 |
43 | // Version information for an assembly consists of the following four values:
44 | //
45 | // Major Version
46 | // Minor Version
47 | // Build Number
48 | // Revision
49 | //
50 | // You can specify all the values or you can default the Build and Revision Numbers
51 | // by using the '*' as shown below:
52 | // [assembly: AssemblyVersion("1.0.*")]
53 | [assembly: AssemblyVersion("3.0.0.0")]
54 | [assembly: AssemblyFileVersion("3.0.0.0")]
55 |
--------------------------------------------------------------------------------
/HyperVBackup.Console/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/HyperVBackup.Console/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/HyperVBackup.Engine/BackupCancelledException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace HyperVBackUp.Engine
4 | {
5 | public class BackupCancelledException : Exception
6 | {
7 | public BackupCancelledException() : base("Backup cancelled")
8 | {
9 | }
10 |
11 | public BackupCancelledException(string message) : base(message)
12 | {
13 | }
14 |
15 | public BackupCancelledException(string message, Exception innerException) : base(message, innerException)
16 | {
17 | }
18 |
19 | protected BackupCancelledException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context)
20 | {
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/HyperVBackup.Engine/BackupManager.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Cloudbase Solutions Srl + Coliseo Software Srl
3 | *
4 | * This program is free software; you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation; either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with this program; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | using System;
20 | using System.Collections.Generic;
21 | using System.Globalization;
22 | using System.IO;
23 | using System.Linq;
24 | using System.Management;
25 | using System.Text;
26 | using Alphaleonis.Win32.Vss;
27 | using Ionic.Zip;
28 | using NLog;
29 | using SevenZip;
30 | using Directory = Alphaleonis.Win32.Filesystem.Directory;
31 | using File = Alphaleonis.Win32.Filesystem.File;
32 | using Path = Alphaleonis.Win32.Filesystem.Path;
33 |
34 | namespace HyperVBackUp.Engine
35 | {
36 | public class BackupManager
37 | {
38 | public event EventHandler BackupProgress;
39 | private volatile bool _cancel = false;
40 |
41 | public IDictionary VssBackup(IEnumerable vmNames, VmNameType nameType, Options options,
42 | ILogger logger)
43 | {
44 | _cancel = false;
45 | var vmNamesMap = GetVMNames(vmNames, options.Exclude, nameType);
46 |
47 | if (vmNamesMap.Count > 0)
48 | {
49 | if (options.SingleSnapshot)
50 | {
51 | BackupSubset(vmNamesMap, options, logger);
52 | }
53 | else
54 | foreach (var kv in vmNamesMap)
55 | {
56 | var vmNamesMapSubset = new Dictionary { { kv.Key, kv.Value } };
57 | BackupSubset(vmNamesMapSubset, options, logger);
58 | }
59 | }
60 |
61 | return vmNamesMap;
62 | }
63 |
64 | private void BackupSubset(IDictionary vmNamesMapSubset, Options options, ILogger logger)
65 | {
66 | var vssImpl = VssUtils.LoadImplementation();
67 | using (var vss = vssImpl.CreateVssBackupComponents())
68 | {
69 | RaiseEvent(EventAction.InitializingVss, null, null);
70 |
71 | vss.InitializeForBackup(null);
72 | vss.SetBackupState(true, true, VssBackupType.Full, false);
73 | vss.SetContext(VssSnapshotContext.Backup);
74 |
75 | // Add Hyper-V writer
76 | var hyperVwriterGuid = new Guid("66841cd4-6ded-4f4b-8f17-fd23f8ddc3de");
77 | vss.EnableWriterClasses(new Guid[] { hyperVwriterGuid });
78 |
79 | vss.GatherWriterMetadata();
80 |
81 | IList components = new List();
82 | // key: volumePath, value: volumeName. These values are equivalent on a standard volume, but differ in the CSV case
83 | // StringComparer.InvariantCultureIgnoreCase requiered to fix duplicate Keys with different case error
84 | IDictionary volumeMap =
85 | new Dictionary(StringComparer.InvariantCultureIgnoreCase);
86 |
87 | var wm = vss.WriterMetadata.FirstOrDefault(o => o.WriterId.Equals(hyperVwriterGuid));
88 | foreach (var component in wm.Components)
89 | {
90 | if (vmNamesMapSubset.ContainsKey(component.ComponentName))
91 | {
92 | components.Add(component);
93 | vss.AddComponent(wm.InstanceId, wm.WriterId, component.Type, component.LogicalPath,
94 | component.ComponentName);
95 | foreach (var file in component.Files)
96 | {
97 | string volumeName;
98 | string volumePath;
99 |
100 | if (CSV.IsSupported() && CSV.IsPathOnSharedVolume(file.Path))
101 | {
102 | CSV.ClusterPrepareSharedVolumeForBackup(file.Path, out volumePath, out volumeName);
103 | }
104 | else
105 | {
106 | volumePath = Path.GetPathRoot(file.Path).ToUpper();
107 | volumeName = volumePath;
108 | }
109 |
110 | if (!volumeMap.ContainsKey(volumePath))
111 | {
112 | volumeMap.Add(volumePath, volumeName);
113 | }
114 | }
115 | }
116 | }
117 |
118 | if (components.Count > 0)
119 | {
120 | var vssSet = vss.StartSnapshotSet();
121 |
122 | // Key: volumeName, value: snapshotGuid
123 | IDictionary snapshots = new Dictionary();
124 |
125 | foreach (var volumeName in volumeMap.Values)
126 | snapshots.Add(volumeName, vss.AddToSnapshotSet(volumeName, Guid.Empty));
127 |
128 | vss.PrepareForBackup();
129 |
130 | RaiseEvent(EventAction.StartingSnaphotSet, components, volumeMap);
131 | vss.DoSnapshotSet();
132 | RaiseEvent(EventAction.SnapshotSetDone, components, volumeMap);
133 |
134 | // key: volumeName, value: snapshotVolumePath
135 | IDictionary snapshotVolumeMap = new Dictionary();
136 |
137 | foreach (var kv in snapshots)
138 | snapshotVolumeMap.Add(kv.Key, vss.GetSnapshotProperties(kv.Value).SnapshotDeviceObject);
139 |
140 | BackupFiles(components, volumeMap, snapshotVolumeMap, vmNamesMapSubset, options, logger);
141 |
142 | foreach (var component in components)
143 | vss.SetBackupSucceeded(wm.InstanceId, wm.WriterId, component.Type, component.LogicalPath,
144 | component.ComponentName, true);
145 |
146 | vss.BackupComplete();
147 |
148 | RaiseEvent(EventAction.DeletingSnapshotSet, components, volumeMap);
149 | vss.DeleteSnapshotSet(vssSet, true);
150 | }
151 | }
152 | }
153 |
154 | private void RaiseEvent(EventAction action, IList components,
155 | IDictionary volumeMap)
156 | {
157 | if (BackupProgress != null)
158 | {
159 | var ebp = new BackupProgressEventArgs()
160 | {
161 | Action = action
162 | };
163 |
164 | if (components != null)
165 | {
166 | ebp.Components = new Dictionary();
167 | foreach (var component in components)
168 | ebp.Components.Add(component.ComponentName, component.Caption);
169 | }
170 |
171 | if (volumeMap != null)
172 | {
173 | ebp.VolumeMap = new Dictionary();
174 | foreach (var volume in volumeMap)
175 | ebp.VolumeMap.Add(volume);
176 | }
177 |
178 | BackupProgress(this, ebp);
179 | if (ebp.Cancel)
180 | {
181 | throw new BackupCancelledException();
182 | }
183 | }
184 | }
185 |
186 | private static string _currentFile = string.Empty;
187 |
188 | private void BackupFiles(IList components, IDictionary volumeMap,
189 | IDictionary snapshotVolumeMap, IDictionary vmNamesMap,
190 | Options options, ILogger logger)
191 | {
192 | var streams = new List();
193 | try
194 | {
195 | foreach (var component in components)
196 | {
197 | string vmBackupPath;
198 |
199 | if (options.DirectCopy)
200 | {
201 | vmBackupPath = Path.Combine(options.Output,
202 | string.Format(options.OutputFormat, vmNamesMap[component.ComponentName],
203 | component.ComponentName,
204 | DateTime.Now, ""));
205 | }
206 | else
207 | {
208 | vmBackupPath = Path.Combine(options.Output,
209 | string.Format(options.OutputFormat, vmNamesMap[component.ComponentName],
210 | component.ComponentName,
211 | DateTime.Now,
212 | options.ZipFormat ? ".zip" : ".7z"));
213 | File.Delete(vmBackupPath);
214 | }
215 |
216 | var files = new Dictionary();
217 |
218 | foreach (var file in component.Files)
219 | {
220 | string path;
221 | if (file.IsRecursive)
222 | {
223 | path = file.Path;
224 | }
225 | else
226 | {
227 | path = Path.Combine(file.Path, file.FileSpecification);
228 | }
229 |
230 | // Get the longest matching path
231 | var volumePath = volumeMap.Keys.OrderBy(o => o.Length).Reverse()
232 | .First(o => path.StartsWith(o, StringComparison.OrdinalIgnoreCase));
233 | var volumeName = volumeMap[volumePath];
234 |
235 |
236 | // Exclude snapshots
237 | var fileName = Path.GetFileName(path.Substring(volumePath.Length)).ToUpperInvariant();
238 | var include = !path.EndsWith("\\*");
239 |
240 | var pathItems = path.Split(Path.DirectorySeparatorChar);
241 | if (pathItems.Length >= 2)
242 | {
243 | if (pathItems[pathItems.Length - 2].ToLowerInvariant() == "snapshots")
244 | {
245 | include = false;
246 | }
247 | }
248 |
249 | if (include && options.VhdInclude != null)
250 | {
251 | if (options.VhdInclude.Count(
252 | x => string.CompareOrdinal(x.ToUpperInvariant(), fileName) == 0) == 0)
253 | {
254 | include = false;
255 | }
256 | }
257 |
258 | if (include && options.VhdIgnore != null)
259 | {
260 | if (options.VhdIgnore.Count(
261 | x => string.CompareOrdinal(x.ToUpperInvariant(), fileName) == 0) != 0)
262 | {
263 | include = false;
264 | }
265 | }
266 |
267 | if (include)
268 | {
269 | if (options.DirectCopy)
270 | {
271 | DoDirectCopy(vmBackupPath, snapshotVolumeMap[volumeName], volumePath.Length, path);
272 | }
273 | else
274 | {
275 | AddPathToCompressionList(files, streams, snapshotVolumeMap[volumeName], volumePath.Length, path);
276 | }
277 | }
278 | else
279 | {
280 | var errorText = $"Ignoring file {path}";
281 | logger.Info(errorText);
282 | Console.WriteLine(errorText);
283 | }
284 | }
285 |
286 | if (!options.DirectCopy)
287 | {
288 | logger.Debug($"Start compression. File: {vmBackupPath}");
289 |
290 | if (options.ZipFormat)
291 | {
292 | if (options.CompressionLevel == -1)
293 | {
294 | options.CompressionLevel = 6;
295 | }
296 |
297 | using (var zf = new ZipFile(vmBackupPath))
298 | {
299 | zf.ParallelDeflateThreshold = -1;
300 | zf.UseZip64WhenSaving = Zip64Option.Always;
301 | zf.Encryption = EncryptionAlgorithm.WinZipAes256;
302 |
303 | switch (options.CompressionLevel)
304 | {
305 | case 0:
306 | zf.CompressionLevel = Ionic.Zlib.CompressionLevel.Level0;
307 | break;
308 | case 1:
309 | zf.CompressionLevel = Ionic.Zlib.CompressionLevel.Level1;
310 | break;
311 | case 2:
312 | zf.CompressionLevel = Ionic.Zlib.CompressionLevel.Level2;
313 | break;
314 | case 3:
315 | zf.CompressionLevel = Ionic.Zlib.CompressionLevel.Level3;
316 | break;
317 | case 4:
318 | zf.CompressionLevel = Ionic.Zlib.CompressionLevel.Level4;
319 | break;
320 | case 5:
321 | zf.CompressionLevel = Ionic.Zlib.CompressionLevel.Level5;
322 | break;
323 | case 6:
324 | zf.CompressionLevel = Ionic.Zlib.CompressionLevel.Level6;
325 | break;
326 | case 7:
327 | zf.CompressionLevel = Ionic.Zlib.CompressionLevel.Level7;
328 | break;
329 | case 8:
330 | zf.CompressionLevel = Ionic.Zlib.CompressionLevel.Level8;
331 | break;
332 | case 9:
333 | zf.CompressionLevel = Ionic.Zlib.CompressionLevel.Level9;
334 | break;
335 | }
336 |
337 | if (BackupProgress != null)
338 | {
339 | zf.SaveProgress += (sender, e) => ReportZipProgress(component, volumeMap, e);
340 | }
341 |
342 | if (!string.IsNullOrEmpty(options.Password))
343 | {
344 | zf.Password = options.Password;
345 | }
346 |
347 | foreach (var file in files)
348 | {
349 | logger.Debug($"Adding file: {file.Key}");
350 | zf.AddEntry(file.Key, file.Value);
351 | }
352 |
353 | zf.Save();
354 | }
355 | }
356 | else
357 | {
358 | if (options.CompressionLevel == -1)
359 | {
360 | options.CompressionLevel = 3;
361 | }
362 |
363 | SevenZipBase.SetLibraryPath(
364 | Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "7z.dll"));
365 |
366 | var sevenZip = new SevenZipCompressor
367 | {
368 | ArchiveFormat = OutArchiveFormat.SevenZip,
369 | CompressionMode = CompressionMode.Create,
370 | DirectoryStructure = true,
371 | PreserveDirectoryRoot = false
372 | };
373 |
374 | if (options.MultiThreaded)
375 | {
376 | sevenZip.CustomParameters.Add("mt", "on");
377 | }
378 |
379 | sevenZip.CustomParameters.Add("d", "24");
380 |
381 | switch (options.CompressionLevel)
382 | {
383 | case 0:
384 | sevenZip.CompressionLevel = CompressionLevel.None;
385 | break;
386 | case 1:
387 | case 2:
388 | sevenZip.CompressionLevel = CompressionLevel.Fast;
389 | break;
390 | case 3:
391 | case 4:
392 | case 5:
393 | sevenZip.CompressionLevel = CompressionLevel.Low;
394 | break;
395 | case 6:
396 | sevenZip.CompressionLevel = CompressionLevel.Normal;
397 | break;
398 | case 7:
399 | case 8:
400 | sevenZip.CompressionLevel = CompressionLevel.High;
401 | break;
402 | case 9:
403 | sevenZip.CompressionLevel = CompressionLevel.Ultra;
404 | break;
405 | }
406 |
407 | if (BackupProgress != null)
408 | {
409 | sevenZip.FileCompressionStarted += (sender, e) =>
410 | {
411 | var ebp = new BackupProgressEventArgs
412 | {
413 | AcrhiveFileName = e.FileName,
414 | Action = EventAction.StartingArchive
415 | };
416 |
417 | _currentFile = e.FileName;
418 |
419 | Report7ZipProgress(component, volumeMap, ebp);
420 |
421 | if (_cancel)
422 | {
423 | e.Cancel = true;
424 | }
425 | };
426 |
427 | sevenZip.FileCompressionFinished += (sender, e) =>
428 | {
429 | var ebp = new BackupProgressEventArgs
430 | {
431 | AcrhiveFileName = _currentFile,
432 | Action = EventAction.ArchiveDone
433 | };
434 |
435 | _currentFile = string.Empty;
436 |
437 | Report7ZipProgress(component, volumeMap, ebp);
438 | };
439 |
440 | sevenZip.Compressing += (sender, e) =>
441 | {
442 | var ebp = new BackupProgressEventArgs
443 | {
444 | AcrhiveFileName = _currentFile,
445 | Action = EventAction.PercentProgress,
446 | CurrentEntry = _currentFile,
447 | PercentDone = e.PercentDone
448 | };
449 |
450 | Report7ZipProgress(component, volumeMap, ebp);
451 | };
452 | }
453 |
454 | if (string.IsNullOrEmpty(options.Password))
455 | {
456 | sevenZip.CompressStreamDictionary(files, vmBackupPath);
457 | }
458 | else
459 | {
460 | sevenZip.CompressStreamDictionary(files, vmBackupPath, options.Password);
461 | }
462 | }
463 |
464 | logger.Debug("Compression finished");
465 |
466 | if (_cancel)
467 | {
468 | if (File.Exists(vmBackupPath))
469 | {
470 | File.Delete(vmBackupPath);
471 | }
472 | throw new BackupCancelledException();
473 | }
474 | }
475 | }
476 | }
477 | finally
478 | {
479 | // Make sure that all streams are closed
480 | foreach (var s in streams)
481 | {
482 | s.Close();
483 | }
484 | }
485 | }
486 |
487 | private static void AddPathToCompressionList(IDictionary files,
488 | ICollection streams, string snapshotPath, int volumePathLength, string vmPath)
489 | {
490 | var srcPath = Path.Combine(snapshotPath, vmPath.Substring(volumePathLength));
491 |
492 | if (Directory.Exists(srcPath))
493 | {
494 | foreach (var srcChildPath in Directory.GetFileSystemEntries(srcPath))
495 | {
496 | var srcChildPathRel =
497 | srcChildPath.Substring(snapshotPath.EndsWith(Path.PathSeparator.ToString(),
498 | StringComparison.CurrentCultureIgnoreCase)
499 | ? snapshotPath.Length
500 | : snapshotPath.Length + 1);
501 | var childPath = Path.Combine(vmPath.Substring(0, volumePathLength), srcChildPathRel);
502 | AddPathToCompressionList(files, streams, snapshotPath, volumePathLength, childPath);
503 | }
504 | }
505 | else if (File.Exists(srcPath))
506 | {
507 | var s = File.OpenRead(srcPath);
508 | files.Add(vmPath.Substring(volumePathLength), s);
509 | streams.Add(s);
510 | }
511 | else
512 | {
513 | var lowerPath = srcPath.ToLowerInvariant();
514 | var isIgnorable = lowerPath.EndsWith(".avhdx") || lowerPath.EndsWith(".vmrs") ||
515 | lowerPath.EndsWith(".bin") || lowerPath.EndsWith(".vsv");
516 |
517 | if (!isIgnorable)
518 | {
519 | throw new Exception($"Entry \"{srcPath}\" not found in snapshot");
520 | }
521 | }
522 | }
523 |
524 | private static void DoDirectCopy(string vmBackupPath, string snapshotPath, int volumePathLength, string vmPath)
525 | {
526 | var srcPath = Path.Combine(snapshotPath, vmPath.Substring(volumePathLength));
527 |
528 | if (Directory.Exists(srcPath))
529 | {
530 | foreach (var srcChildPath in Directory.GetFileSystemEntries(srcPath))
531 | {
532 | var srcChildPathRel =
533 | srcChildPath.Substring(snapshotPath.EndsWith(Path.PathSeparator.ToString(),
534 | StringComparison.CurrentCultureIgnoreCase)
535 | ? snapshotPath.Length
536 | : snapshotPath.Length + 1);
537 | var childPath = Path.Combine(vmPath.Substring(0, volumePathLength), srcChildPathRel);
538 | DoDirectCopy(vmBackupPath, snapshotPath, volumePathLength, childPath);
539 | }
540 | }
541 | else if (File.Exists(srcPath))
542 | {
543 | var outputName = Path.Combine(vmBackupPath, vmPath.Substring(volumePathLength));
544 | using (var s = File.OpenRead(srcPath))
545 | {
546 | var folder = Path.GetDirectoryName(outputName);
547 | if (!Directory.Exists(folder))
548 | {
549 | Directory.CreateDirectory(folder);
550 | }
551 |
552 | using (var ns = File.Create(outputName))
553 | {
554 | s.CopyTo(ns);
555 | }
556 | }
557 |
558 | }
559 | else
560 | {
561 | var lowerPath = srcPath.ToLowerInvariant();
562 | var isIgnorable = lowerPath.EndsWith(".avhdx") || lowerPath.EndsWith(".vmrs") ||
563 | lowerPath.EndsWith(".bin") || lowerPath.EndsWith(".vsv");
564 |
565 | if (!isIgnorable)
566 | {
567 | throw new Exception($"Entry \"{srcPath}\" not found in snapshot");
568 | }
569 | }
570 | }
571 |
572 | protected bool UseWMIV2NameSpace
573 | {
574 | get
575 | {
576 | var version = Environment.OSVersion.Version;
577 | return version.Major >= 6 && version.Minor >= 2;
578 | }
579 | }
580 |
581 | protected string GetWMIScope(string host = "localhost")
582 | {
583 | string scopeFormatStr;
584 | if (UseWMIV2NameSpace)
585 | scopeFormatStr = "\\\\{0}\\root\\virtualization\\v2";
586 | else
587 | scopeFormatStr = "\\\\{0}\\root\\virtualization";
588 |
589 | return (string.Format(scopeFormatStr, host));
590 | }
591 |
592 | IDictionary GetVMNames(IEnumerable vmNames, IList vmExclude, VmNameType nameType)
593 | {
594 | IDictionary d = new Dictionary();
595 |
596 | string query;
597 | string vmIdField;
598 |
599 | if (UseWMIV2NameSpace)
600 | {
601 | query =
602 | "SELECT VirtualSystemIdentifier, ElementName FROM Msvm_VirtualSystemSettingData WHERE VirtualSystemType = 'Microsoft:Hyper-V:System:Realized'";
603 | vmIdField = "VirtualSystemIdentifier";
604 | }
605 | else
606 | {
607 | query = "SELECT SystemName, ElementName FROM Msvm_VirtualSystemSettingData WHERE SettingType = 3";
608 | vmIdField = "SystemName";
609 | }
610 |
611 | var inField = nameType == VmNameType.ElementName ? "ElementName" : vmIdField;
612 |
613 | var scope = new ManagementScope(GetWMIScope());
614 |
615 | if (vmNames != null && vmNames.Any())
616 | query += $" AND ({GetORStr(inField, vmNames)})";
617 |
618 | using (var searcher = new ManagementObjectSearcher(scope, new ObjectQuery(query)))
619 | {
620 | using (var moc = searcher.Get())
621 | foreach (var mo in moc)
622 | using (mo)
623 | {
624 | if (vmExclude==null || !vmExclude.Contains((string) mo["ElementName"], StringComparer.Create(CultureInfo.InvariantCulture, true)))
625 | {
626 | d.Add((string) mo[vmIdField], (string) mo["ElementName"]);
627 | }
628 | }
629 | }
630 |
631 | return d;
632 | }
633 |
634 | private static string GetORStr(string fieldName, IEnumerable vmNames)
635 | {
636 | var sb = new StringBuilder();
637 | foreach (var vmName in vmNames)
638 | {
639 | if (sb.Length > 0)
640 | sb.Append(" OR ");
641 | sb.Append($"{fieldName} = '{EscapeWMIStr(vmName)}'");
642 | }
643 | return sb.ToString();
644 | }
645 |
646 | private static string EscapeWMIStr(string str)
647 | {
648 | return str?.Replace("'", "''");
649 | }
650 |
651 | private void Report7ZipProgress(IVssWMComponent component, IDictionary volumeMap,
652 | BackupProgressEventArgs ebp)
653 | {
654 | if (ebp == null)
655 | {
656 | return;
657 | }
658 |
659 | ebp.Components = new Dictionary { { component.ComponentName, component.Caption } };
660 |
661 | ebp.VolumeMap = new Dictionary();
662 | foreach (var volume in volumeMap)
663 | ebp.VolumeMap.Add(volume.Key, volume.Value);
664 |
665 | BackupProgress(this, ebp);
666 |
667 | if (ebp.Cancel)
668 | {
669 | _cancel = true;
670 | }
671 | }
672 |
673 | private void ReportZipProgress(IVssWMComponent component, IDictionary volumeMap,
674 | ZipProgressEventArgs e)
675 | {
676 | BackupProgressEventArgs ebp = null;
677 |
678 | if (e.EventType == ZipProgressEventType.Saving_Started)
679 | {
680 | ebp = new BackupProgressEventArgs()
681 | {
682 | AcrhiveFileName = e.ArchiveName,
683 | Action = EventAction.StartingArchive
684 | };
685 | }
686 | else if (e.EventType == ZipProgressEventType.Saving_BeforeWriteEntry ||
687 | e.EventType == ZipProgressEventType.Saving_EntryBytesRead)
688 | {
689 | var action = e.EventType == ZipProgressEventType.Saving_BeforeWriteEntry
690 | ? EventAction.StartingEntry
691 | : EventAction.SavingEntry;
692 |
693 | ebp = new BackupProgressEventArgs()
694 | {
695 | AcrhiveFileName = e.ArchiveName,
696 | Action = action,
697 | CurrentEntry = e.CurrentEntry.FileName,
698 | EntriesTotal = e.EntriesTotal,
699 | TotalBytesToTransfer = e.TotalBytesToTransfer,
700 | BytesTransferred = e.BytesTransferred
701 | };
702 | }
703 | else if (e.EventType == ZipProgressEventType.Saving_Completed)
704 | {
705 | ebp = new BackupProgressEventArgs()
706 | {
707 | AcrhiveFileName = e.ArchiveName,
708 | Action = EventAction.ArchiveDone
709 | };
710 | }
711 |
712 | if (ebp != null)
713 | {
714 | ebp.Components = new Dictionary
715 | {
716 | {component.ComponentName, component.Caption}
717 | };
718 | ebp.VolumeMap = new Dictionary();
719 | foreach (var volume in volumeMap)
720 | {
721 | ebp.VolumeMap.Add(volume.Key, volume.Value);
722 | }
723 |
724 | BackupProgress(this, ebp);
725 |
726 | // Close the zip file operation neatly and throw the exception afterwards
727 | e.Cancel = ebp.Cancel;
728 | }
729 | }
730 | }
731 | }
732 |
--------------------------------------------------------------------------------
/HyperVBackup.Engine/BackupProgressEventArgs.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace HyperVBackUp.Engine
5 | {
6 | public class BackupProgressEventArgs : EventArgs
7 | {
8 | public IDictionary Components { get; set; }
9 | public string AcrhiveFileName { get; set; }
10 | public long BytesTransferred { get; set; }
11 | public bool Cancel { get; set; }
12 | public string CurrentEntry { get; set; }
13 | public int EntriesTotal { get; set; }
14 | public int PercentDone { get; set; }
15 | public long TotalBytesToTransfer { get; set; }
16 | public EventAction Action { get; set; }
17 | public IDictionary VolumeMap { get; set; }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/HyperVBackup.Engine/CSV.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Cloudbase Solutions Srl + 2016 Coliseo Software srl
3 | *
4 | * This program is free software; you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation; either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with this program; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | using System;
20 | using System.ComponentModel;
21 | using System.Runtime.InteropServices;
22 | using System.Text;
23 |
24 | namespace HyperVBackUp.Engine
25 | {
26 | public class CSV
27 | {
28 | [DllImport("ResUtils.dll", CharSet = CharSet.Auto)]
29 | private static extern bool ClusterIsPathOnSharedVolume(string lpszPathName);
30 |
31 | [DllImport("ResUtils.dll", SetLastError = true, CharSet = CharSet.Auto)]
32 | private static extern bool ClusterGetVolumePathName(string lpszFileName, StringBuilder lpszVolumePathName, int cchBufferLength);
33 |
34 | [DllImport("ResUtils.dll", SetLastError = true, CharSet = CharSet.Auto)]
35 | private static extern bool ClusterGetVolumeNameForVolumeMountPoint(string lpszVolumeMountPoint, StringBuilder lpszVolumeName, int cchBufferLength);
36 |
37 | [DllImport("ResUtils.dll", CharSet = CharSet.Auto)]
38 | private static extern int ClusterPrepareSharedVolumeForBackup(string lpszFileName, StringBuilder lpszVolumePathName, ref int lpcchVolumePathName, StringBuilder lpszVolumeName, ref int lpcchVolumeName);
39 |
40 | [DllImport("ResUtils.dll", CharSet = CharSet.Auto)]
41 | private static extern int ClusterClearBackupStateForSharedVolume(string lpszVolumePathName);
42 |
43 | public static bool IsSupported()
44 | {
45 | // Note: should also check for Server edition
46 | return (Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version.Major >= 6 && Environment.OSVersion.Version.Minor >= 1);
47 | }
48 |
49 | public static bool IsPathOnSharedVolume(string path)
50 | {
51 | return ClusterIsPathOnSharedVolume(path);
52 | }
53 |
54 | public static string GetVolumeNameForMountPoint(string volumeMountPoint)
55 | {
56 | StringBuilder sb = new StringBuilder(2048);
57 | if (!ClusterGetVolumeNameForVolumeMountPoint(volumeMountPoint, sb, sb.Capacity))
58 | throw new Win32Exception(Marshal.GetLastWin32Error());
59 | return sb.ToString();
60 | }
61 |
62 | public static string GetVolumePath(string path)
63 | {
64 | StringBuilder sb = new StringBuilder(2048);
65 | if (!ClusterGetVolumePathName(path, sb, sb.Capacity))
66 | throw new Win32Exception(Marshal.GetLastWin32Error());
67 | return sb.ToString();
68 | }
69 |
70 | public static void ClusterPrepareSharedVolumeForBackup(string path, out string volumePath, out string volumeName)
71 | {
72 | StringBuilder sbVolumePath = new StringBuilder(2048);
73 | StringBuilder sbVolumeName = new StringBuilder(2048);
74 |
75 | int volumePathCapacity = sbVolumePath.Capacity;
76 | int volumeNameCapacity = sbVolumeName.Capacity;
77 |
78 | int err = ClusterPrepareSharedVolumeForBackup(path, sbVolumePath, ref volumePathCapacity, sbVolumeName, ref volumeNameCapacity);
79 | if (err != 0)
80 | throw new Win32Exception(err);
81 |
82 | volumePath = sbVolumePath.ToString();
83 | volumeName = sbVolumeName.ToString();
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/HyperVBackup.Engine/EventAction.cs:
--------------------------------------------------------------------------------
1 | namespace HyperVBackUp.Engine
2 | {
3 | public enum EventAction
4 | {
5 | InitializingVss,
6 | StartingSnaphotSet,
7 | SnapshotSetDone,
8 | StartingArchive,
9 | StartingEntry,
10 | SavingEntry,
11 | ArchiveDone,
12 | PercentProgress,
13 | DeletingSnapshotSet
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/HyperVBackup.Engine/HVBackup.Engine.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 8.0.30703
7 | 2.0
8 | {096F7CB1-EC67-4388-A7A4-1747EE09DB29}
9 | Library
10 | Properties
11 | HyperVBackUp.Engine
12 | HyperVBackUp.Engine
13 | v4.6.1
14 | 512
15 |
16 | SAK
17 | SAK
18 | SAK
19 | SAK
20 |
21 |
22 |
23 |
24 | true
25 | full
26 | false
27 | bin\Debug\
28 | DEBUG;TRACE
29 | prompt
30 | 4
31 | AnyCPU
32 | false
33 |
34 |
35 | pdbonly
36 | true
37 | bin\Release\
38 | TRACE
39 | prompt
40 | 4
41 | false
42 |
43 |
44 | false
45 |
46 |
47 |
48 |
49 |
50 |
51 | true
52 | bin\x64\Debug\
53 | DEBUG;TRACE
54 | full
55 | x64
56 | prompt
57 | MinimumRecommendedRules.ruleset
58 | false
59 |
60 |
61 | bin\Release\x64\
62 | TRACE
63 | true
64 | pdbonly
65 | x64
66 | prompt
67 | MinimumRecommendedRules.ruleset
68 | false
69 |
70 |
71 | true
72 | bin\x86\Debug\
73 | DEBUG;TRACE
74 | full
75 | x86
76 | prompt
77 | MinimumRecommendedRules.ruleset
78 |
79 |
80 | bin\Release\x86\
81 | TRACE
82 | true
83 | pdbonly
84 | x86
85 | prompt
86 | MinimumRecommendedRules.ruleset
87 |
88 |
89 |
90 | ..\packages\AlphaFS.2.1.3\lib\net452\AlphaFS.dll
91 |
92 |
93 | ..\packages\AlphaVSS.1.4.0\lib\net45\AlphaVSS.Common.dll
94 |
95 |
96 | ..\packages\DotNetZip.1.10.1\lib\net20\DotNetZip.dll
97 |
98 |
99 | ..\packages\NLog.4.4.10\lib\net45\NLog.dll
100 |
101 |
102 | False
103 | ..\Lib\SevenZipSharp.dll
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 | PreserveNewest
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
131 |
132 |
133 |
134 |
141 |
--------------------------------------------------------------------------------
/HyperVBackup.Engine/HVBackup.Engine.csproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ProjectFiles
5 |
6 |
--------------------------------------------------------------------------------
/HyperVBackup.Engine/NLog.config:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
7 |
9 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/HyperVBackup.Engine/Options.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace HyperVBackUp.Engine
4 | {
5 | public class Options
6 | {
7 | public string Password { get; set; }
8 | public bool SingleSnapshot { get; set; }
9 | public string Output { get; set; }
10 | public string OutputFormat { get; set; }
11 | public IList VhdInclude { get; set; }
12 | public IList VhdIgnore { get; set; }
13 | public IList Exclude { get; set; }
14 | public int CompressionLevel { get; set; }
15 | public bool ZipFormat { get; set; }
16 | public bool DirectCopy { get; set; }
17 | public bool MultiThreaded { get; set; }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/HyperVBackup.Engine/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Cloudbase Solutions Srl
3 | *
4 | * This program is free software; you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation; either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public License
15 | * along with this program; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | using System.Reflection;
20 | using System.Runtime.CompilerServices;
21 | using System.Runtime.InteropServices;
22 |
23 | // General Information about an assembly is controlled through the following
24 | // set of attributes. Change these attribute values to modify the information
25 | // associated with an assembly.
26 | [assembly: AssemblyTitle("HyperVBackup Engine")]
27 | [assembly: AssemblyDescription("")]
28 | [assembly: AssemblyConfiguration("")]
29 | [assembly: AssemblyCompany("Cloudbase Solutions Srl + Coliseo Software Srl")]
30 | [assembly: AssemblyProduct("HyperVBackup")]
31 | [assembly: AssemblyCopyright("Copyright © Cloudbase Solutions Srl 2012 + Coliseo Software Srl")]
32 | [assembly: AssemblyTrademark("")]
33 | [assembly: AssemblyCulture("")]
34 |
35 | // Setting ComVisible to false makes the types in this assembly not visible
36 | // to COM components. If you need to access a type in this assembly from
37 | // COM, set the ComVisible attribute to true on that type.
38 | [assembly: ComVisible(false)]
39 |
40 | // The following GUID is for the ID of the typelib if this project is exposed to COM
41 | [assembly: Guid("49db4682-1c5a-45c9-a90c-bed061ef0b81")]
42 |
43 | // Version information for an assembly consists of the following four values:
44 | //
45 | // Major Version
46 | // Minor Version
47 | // Build Number
48 | // Revision
49 | //
50 | // You can specify all the values or you can default the Build and Revision Numbers
51 | // by using the '*' as shown below:
52 | // [assembly: AssemblyVersion("1.0.*")]
53 | [assembly: AssemblyVersion("3.0.0.0")]
54 | [assembly: AssemblyFileVersion("3.0.0.0")]
55 |
--------------------------------------------------------------------------------
/HyperVBackup.Engine/VmNameType.cs:
--------------------------------------------------------------------------------
1 | namespace HyperVBackUp.Engine
2 | {
3 | public enum VmNameType
4 | {
5 | ElementName,
6 | SystemName
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/HyperVBackup.Engine/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 2.1, February 1999
3 |
4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc.
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | (This is the first released version of the Lesser GPL. It also counts
10 | as the successor of the GNU Library Public License, version 2, hence
11 | the version number 2.1.)
12 |
13 | Preamble
14 |
15 | The licenses for most software are designed to take away your
16 | freedom to share and change it. By contrast, the GNU General Public
17 | Licenses are intended to guarantee your freedom to share and change
18 | free software--to make sure the software is free for all its users.
19 |
20 | This license, the Lesser General Public License, applies to some
21 | specially designated software packages--typically libraries--of the
22 | Free Software Foundation and other authors who decide to use it. You
23 | can use it too, but we suggest you first think carefully about whether
24 | this license or the ordinary General Public License is the better
25 | strategy to use in any particular case, based on the explanations below.
26 |
27 | When we speak of free software, we are referring to freedom of use,
28 | not price. Our General Public Licenses are designed to make sure that
29 | you have the freedom to distribute copies of free software (and charge
30 | for this service if you wish); that you receive source code or can get
31 | it if you want it; that you can change the software and use pieces of
32 | it in new free programs; and that you are informed that you can do
33 | these things.
34 |
35 | To protect your rights, we need to make restrictions that forbid
36 | distributors to deny you these rights or to ask you to surrender these
37 | rights. These restrictions translate to certain responsibilities for
38 | you if you distribute copies of the library or if you modify it.
39 |
40 | For example, if you distribute copies of the library, whether gratis
41 | or for a fee, you must give the recipients all the rights that we gave
42 | you. You must make sure that they, too, receive or can get the source
43 | code. If you link other code with the library, you must provide
44 | complete object files to the recipients, so that they can relink them
45 | with the library after making changes to the library and recompiling
46 | it. And you must show them these terms so they know their rights.
47 |
48 | We protect your rights with a two-step method: (1) we copyright the
49 | library, and (2) we offer you this license, which gives you legal
50 | permission to copy, distribute and/or modify the library.
51 |
52 | To protect each distributor, we want to make it very clear that
53 | there is no warranty for the free library. Also, if the library is
54 | modified by someone else and passed on, the recipients should know
55 | that what they have is not the original version, so that the original
56 | author's reputation will not be affected by problems that might be
57 | introduced by others.
58 |
59 | Finally, software patents pose a constant threat to the existence of
60 | any free program. We wish to make sure that a company cannot
61 | effectively restrict the users of a free program by obtaining a
62 | restrictive license from a patent holder. Therefore, we insist that
63 | any patent license obtained for a version of the library must be
64 | consistent with the full freedom of use specified in this license.
65 |
66 | Most GNU software, including some libraries, is covered by the
67 | ordinary GNU General Public License. This license, the GNU Lesser
68 | General Public License, applies to certain designated libraries, and
69 | is quite different from the ordinary General Public License. We use
70 | this license for certain libraries in order to permit linking those
71 | libraries into non-free programs.
72 |
73 | When a program is linked with a library, whether statically or using
74 | a shared library, the combination of the two is legally speaking a
75 | combined work, a derivative of the original library. The ordinary
76 | General Public License therefore permits such linking only if the
77 | entire combination fits its criteria of freedom. The Lesser General
78 | Public License permits more lax criteria for linking other code with
79 | the library.
80 |
81 | We call this license the "Lesser" General Public License because it
82 | does Less to protect the user's freedom than the ordinary General
83 | Public License. It also provides other free software developers Less
84 | of an advantage over competing non-free programs. These disadvantages
85 | are the reason we use the ordinary General Public License for many
86 | libraries. However, the Lesser license provides advantages in certain
87 | special circumstances.
88 |
89 | For example, on rare occasions, there may be a special need to
90 | encourage the widest possible use of a certain library, so that it becomes
91 | a de-facto standard. To achieve this, non-free programs must be
92 | allowed to use the library. A more frequent case is that a free
93 | library does the same job as widely used non-free libraries. In this
94 | case, there is little to gain by limiting the free library to free
95 | software only, so we use the Lesser General Public License.
96 |
97 | In other cases, permission to use a particular library in non-free
98 | programs enables a greater number of people to use a large body of
99 | free software. For example, permission to use the GNU C Library in
100 | non-free programs enables many more people to use the whole GNU
101 | operating system, as well as its variant, the GNU/Linux operating
102 | system.
103 |
104 | Although the Lesser General Public License is Less protective of the
105 | users' freedom, it does ensure that the user of a program that is
106 | linked with the Library has the freedom and the wherewithal to run
107 | that program using a modified version of the Library.
108 |
109 | The precise terms and conditions for copying, distribution and
110 | modification follow. Pay close attention to the difference between a
111 | "work based on the library" and a "work that uses the library". The
112 | former contains code derived from the library, whereas the latter must
113 | be combined with the library in order to run.
114 |
115 | GNU LESSER GENERAL PUBLIC LICENSE
116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
117 |
118 | 0. This License Agreement applies to any software library or other
119 | program which contains a notice placed by the copyright holder or
120 | other authorized party saying it may be distributed under the terms of
121 | this Lesser General Public License (also called "this License").
122 | Each licensee is addressed as "you".
123 |
124 | A "library" means a collection of software functions and/or data
125 | prepared so as to be conveniently linked with application programs
126 | (which use some of those functions and data) to form executables.
127 |
128 | The "Library", below, refers to any such software library or work
129 | which has been distributed under these terms. A "work based on the
130 | Library" means either the Library or any derivative work under
131 | copyright law: that is to say, a work containing the Library or a
132 | portion of it, either verbatim or with modifications and/or translated
133 | straightforwardly into another language. (Hereinafter, translation is
134 | included without limitation in the term "modification".)
135 |
136 | "Source code" for a work means the preferred form of the work for
137 | making modifications to it. For a library, complete source code means
138 | all the source code for all modules it contains, plus any associated
139 | interface definition files, plus the scripts used to control compilation
140 | and installation of the library.
141 |
142 | Activities other than copying, distribution and modification are not
143 | covered by this License; they are outside its scope. The act of
144 | running a program using the Library is not restricted, and output from
145 | such a program is covered only if its contents constitute a work based
146 | on the Library (independent of the use of the Library in a tool for
147 | writing it). Whether that is true depends on what the Library does
148 | and what the program that uses the Library does.
149 |
150 | 1. You may copy and distribute verbatim copies of the Library's
151 | complete source code as you receive it, in any medium, provided that
152 | you conspicuously and appropriately publish on each copy an
153 | appropriate copyright notice and disclaimer of warranty; keep intact
154 | all the notices that refer to this License and to the absence of any
155 | warranty; and distribute a copy of this License along with the
156 | Library.
157 |
158 | You may charge a fee for the physical act of transferring a copy,
159 | and you may at your option offer warranty protection in exchange for a
160 | fee.
161 |
162 | 2. You may modify your copy or copies of the Library or any portion
163 | of it, thus forming a work based on the Library, and copy and
164 | distribute such modifications or work under the terms of Section 1
165 | above, provided that you also meet all of these conditions:
166 |
167 | a) The modified work must itself be a software library.
168 |
169 | b) You must cause the files modified to carry prominent notices
170 | stating that you changed the files and the date of any change.
171 |
172 | c) You must cause the whole of the work to be licensed at no
173 | charge to all third parties under the terms of this License.
174 |
175 | d) If a facility in the modified Library refers to a function or a
176 | table of data to be supplied by an application program that uses
177 | the facility, other than as an argument passed when the facility
178 | is invoked, then you must make a good faith effort to ensure that,
179 | in the event an application does not supply such function or
180 | table, the facility still operates, and performs whatever part of
181 | its purpose remains meaningful.
182 |
183 | (For example, a function in a library to compute square roots has
184 | a purpose that is entirely well-defined independent of the
185 | application. Therefore, Subsection 2d requires that any
186 | application-supplied function or table used by this function must
187 | be optional: if the application does not supply it, the square
188 | root function must still compute square roots.)
189 |
190 | These requirements apply to the modified work as a whole. If
191 | identifiable sections of that work are not derived from the Library,
192 | and can be reasonably considered independent and separate works in
193 | themselves, then this License, and its terms, do not apply to those
194 | sections when you distribute them as separate works. But when you
195 | distribute the same sections as part of a whole which is a work based
196 | on the Library, the distribution of the whole must be on the terms of
197 | this License, whose permissions for other licensees extend to the
198 | entire whole, and thus to each and every part regardless of who wrote
199 | it.
200 |
201 | Thus, it is not the intent of this section to claim rights or contest
202 | your rights to work written entirely by you; rather, the intent is to
203 | exercise the right to control the distribution of derivative or
204 | collective works based on the Library.
205 |
206 | In addition, mere aggregation of another work not based on the Library
207 | with the Library (or with a work based on the Library) on a volume of
208 | a storage or distribution medium does not bring the other work under
209 | the scope of this License.
210 |
211 | 3. You may opt to apply the terms of the ordinary GNU General Public
212 | License instead of this License to a given copy of the Library. To do
213 | this, you must alter all the notices that refer to this License, so
214 | that they refer to the ordinary GNU General Public License, version 2,
215 | instead of to this License. (If a newer version than version 2 of the
216 | ordinary GNU General Public License has appeared, then you can specify
217 | that version instead if you wish.) Do not make any other change in
218 | these notices.
219 |
220 | Once this change is made in a given copy, it is irreversible for
221 | that copy, so the ordinary GNU General Public License applies to all
222 | subsequent copies and derivative works made from that copy.
223 |
224 | This option is useful when you wish to copy part of the code of
225 | the Library into a program that is not a library.
226 |
227 | 4. You may copy and distribute the Library (or a portion or
228 | derivative of it, under Section 2) in object code or executable form
229 | under the terms of Sections 1 and 2 above provided that you accompany
230 | it with the complete corresponding machine-readable source code, which
231 | must be distributed under the terms of Sections 1 and 2 above on a
232 | medium customarily used for software interchange.
233 |
234 | If distribution of object code is made by offering access to copy
235 | from a designated place, then offering equivalent access to copy the
236 | source code from the same place satisfies the requirement to
237 | distribute the source code, even though third parties are not
238 | compelled to copy the source along with the object code.
239 |
240 | 5. A program that contains no derivative of any portion of the
241 | Library, but is designed to work with the Library by being compiled or
242 | linked with it, is called a "work that uses the Library". Such a
243 | work, in isolation, is not a derivative work of the Library, and
244 | therefore falls outside the scope of this License.
245 |
246 | However, linking a "work that uses the Library" with the Library
247 | creates an executable that is a derivative of the Library (because it
248 | contains portions of the Library), rather than a "work that uses the
249 | library". The executable is therefore covered by this License.
250 | Section 6 states terms for distribution of such executables.
251 |
252 | When a "work that uses the Library" uses material from a header file
253 | that is part of the Library, the object code for the work may be a
254 | derivative work of the Library even though the source code is not.
255 | Whether this is true is especially significant if the work can be
256 | linked without the Library, or if the work is itself a library. The
257 | threshold for this to be true is not precisely defined by law.
258 |
259 | If such an object file uses only numerical parameters, data
260 | structure layouts and accessors, and small macros and small inline
261 | functions (ten lines or less in length), then the use of the object
262 | file is unrestricted, regardless of whether it is legally a derivative
263 | work. (Executables containing this object code plus portions of the
264 | Library will still fall under Section 6.)
265 |
266 | Otherwise, if the work is a derivative of the Library, you may
267 | distribute the object code for the work under the terms of Section 6.
268 | Any executables containing that work also fall under Section 6,
269 | whether or not they are linked directly with the Library itself.
270 |
271 | 6. As an exception to the Sections above, you may also combine or
272 | link a "work that uses the Library" with the Library to produce a
273 | work containing portions of the Library, and distribute that work
274 | under terms of your choice, provided that the terms permit
275 | modification of the work for the customer's own use and reverse
276 | engineering for debugging such modifications.
277 |
278 | You must give prominent notice with each copy of the work that the
279 | Library is used in it and that the Library and its use are covered by
280 | this License. You must supply a copy of this License. If the work
281 | during execution displays copyright notices, you must include the
282 | copyright notice for the Library among them, as well as a reference
283 | directing the user to the copy of this License. Also, you must do one
284 | of these things:
285 |
286 | a) Accompany the work with the complete corresponding
287 | machine-readable source code for the Library including whatever
288 | changes were used in the work (which must be distributed under
289 | Sections 1 and 2 above); and, if the work is an executable linked
290 | with the Library, with the complete machine-readable "work that
291 | uses the Library", as object code and/or source code, so that the
292 | user can modify the Library and then relink to produce a modified
293 | executable containing the modified Library. (It is understood
294 | that the user who changes the contents of definitions files in the
295 | Library will not necessarily be able to recompile the application
296 | to use the modified definitions.)
297 |
298 | b) Use a suitable shared library mechanism for linking with the
299 | Library. A suitable mechanism is one that (1) uses at run time a
300 | copy of the library already present on the user's computer system,
301 | rather than copying library functions into the executable, and (2)
302 | will operate properly with a modified version of the library, if
303 | the user installs one, as long as the modified version is
304 | interface-compatible with the version that the work was made with.
305 |
306 | c) Accompany the work with a written offer, valid for at
307 | least three years, to give the same user the materials
308 | specified in Subsection 6a, above, for a charge no more
309 | than the cost of performing this distribution.
310 |
311 | d) If distribution of the work is made by offering access to copy
312 | from a designated place, offer equivalent access to copy the above
313 | specified materials from the same place.
314 |
315 | e) Verify that the user has already received a copy of these
316 | materials or that you have already sent this user a copy.
317 |
318 | For an executable, the required form of the "work that uses the
319 | Library" must include any data and utility programs needed for
320 | reproducing the executable from it. However, as a special exception,
321 | the materials to be distributed need not include anything that is
322 | normally distributed (in either source or binary form) with the major
323 | components (compiler, kernel, and so on) of the operating system on
324 | which the executable runs, unless that component itself accompanies
325 | the executable.
326 |
327 | It may happen that this requirement contradicts the license
328 | restrictions of other proprietary libraries that do not normally
329 | accompany the operating system. Such a contradiction means you cannot
330 | use both them and the Library together in an executable that you
331 | distribute.
332 |
333 | 7. You may place library facilities that are a work based on the
334 | Library side-by-side in a single library together with other library
335 | facilities not covered by this License, and distribute such a combined
336 | library, provided that the separate distribution of the work based on
337 | the Library and of the other library facilities is otherwise
338 | permitted, and provided that you do these two things:
339 |
340 | a) Accompany the combined library with a copy of the same work
341 | based on the Library, uncombined with any other library
342 | facilities. This must be distributed under the terms of the
343 | Sections above.
344 |
345 | b) Give prominent notice with the combined library of the fact
346 | that part of it is a work based on the Library, and explaining
347 | where to find the accompanying uncombined form of the same work.
348 |
349 | 8. You may not copy, modify, sublicense, link with, or distribute
350 | the Library except as expressly provided under this License. Any
351 | attempt otherwise to copy, modify, sublicense, link with, or
352 | distribute the Library is void, and will automatically terminate your
353 | rights under this License. However, parties who have received copies,
354 | or rights, from you under this License will not have their licenses
355 | terminated so long as such parties remain in full compliance.
356 |
357 | 9. You are not required to accept this License, since you have not
358 | signed it. However, nothing else grants you permission to modify or
359 | distribute the Library or its derivative works. These actions are
360 | prohibited by law if you do not accept this License. Therefore, by
361 | modifying or distributing the Library (or any work based on the
362 | Library), you indicate your acceptance of this License to do so, and
363 | all its terms and conditions for copying, distributing or modifying
364 | the Library or works based on it.
365 |
366 | 10. Each time you redistribute the Library (or any work based on the
367 | Library), the recipient automatically receives a license from the
368 | original licensor to copy, distribute, link with or modify the Library
369 | subject to these terms and conditions. You may not impose any further
370 | restrictions on the recipients' exercise of the rights granted herein.
371 | You are not responsible for enforcing compliance by third parties with
372 | this License.
373 |
374 | 11. If, as a consequence of a court judgment or allegation of patent
375 | infringement or for any other reason (not limited to patent issues),
376 | conditions are imposed on you (whether by court order, agreement or
377 | otherwise) that contradict the conditions of this License, they do not
378 | excuse you from the conditions of this License. If you cannot
379 | distribute so as to satisfy simultaneously your obligations under this
380 | License and any other pertinent obligations, then as a consequence you
381 | may not distribute the Library at all. For example, if a patent
382 | license would not permit royalty-free redistribution of the Library by
383 | all those who receive copies directly or indirectly through you, then
384 | the only way you could satisfy both it and this License would be to
385 | refrain entirely from distribution of the Library.
386 |
387 | If any portion of this section is held invalid or unenforceable under any
388 | particular circumstance, the balance of the section is intended to apply,
389 | and the section as a whole is intended to apply in other circumstances.
390 |
391 | It is not the purpose of this section to induce you to infringe any
392 | patents or other property right claims or to contest validity of any
393 | such claims; this section has the sole purpose of protecting the
394 | integrity of the free software distribution system which is
395 | implemented by public license practices. Many people have made
396 | generous contributions to the wide range of software distributed
397 | through that system in reliance on consistent application of that
398 | system; it is up to the author/donor to decide if he or she is willing
399 | to distribute software through any other system and a licensee cannot
400 | impose that choice.
401 |
402 | This section is intended to make thoroughly clear what is believed to
403 | be a consequence of the rest of this License.
404 |
405 | 12. If the distribution and/or use of the Library is restricted in
406 | certain countries either by patents or by copyrighted interfaces, the
407 | original copyright holder who places the Library under this License may add
408 | an explicit geographical distribution limitation excluding those countries,
409 | so that distribution is permitted only in or among countries not thus
410 | excluded. In such case, this License incorporates the limitation as if
411 | written in the body of this License.
412 |
413 | 13. The Free Software Foundation may publish revised and/or new
414 | versions of the Lesser General Public License from time to time.
415 | Such new versions will be similar in spirit to the present version,
416 | but may differ in detail to address new problems or concerns.
417 |
418 | Each version is given a distinguishing version number. If the Library
419 | specifies a version number of this License which applies to it and
420 | "any later version", you have the option of following the terms and
421 | conditions either of that version or of any later version published by
422 | the Free Software Foundation. If the Library does not specify a
423 | license version number, you may choose any version ever published by
424 | the Free Software Foundation.
425 |
426 | 14. If you wish to incorporate parts of the Library into other free
427 | programs whose distribution conditions are incompatible with these,
428 | write to the author to ask for permission. For software which is
429 | copyrighted by the Free Software Foundation, write to the Free
430 | Software Foundation; we sometimes make exceptions for this. Our
431 | decision will be guided by the two goals of preserving the free status
432 | of all derivatives of our free software and of promoting the sharing
433 | and reuse of software generally.
434 |
435 | NO WARRANTY
436 |
437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
446 |
447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
456 | DAMAGES.
457 |
458 | END OF TERMS AND CONDITIONS
459 |
460 | How to Apply These Terms to Your New Libraries
461 |
462 | If you develop a new library, and you want it to be of the greatest
463 | possible use to the public, we recommend making it free software that
464 | everyone can redistribute and change. You can do so by permitting
465 | redistribution under these terms (or, alternatively, under the terms of the
466 | ordinary General Public License).
467 |
468 | To apply these terms, attach the following notices to the library. It is
469 | safest to attach them to the start of each source file to most effectively
470 | convey the exclusion of warranty; and each file should have at least the
471 | "copyright" line and a pointer to where the full notice is found.
472 |
473 | {description}
474 | Copyright (C) {year} {fullname}
475 |
476 | This library is free software; you can redistribute it and/or
477 | modify it under the terms of the GNU Lesser General Public
478 | License as published by the Free Software Foundation; either
479 | version 2.1 of the License, or (at your option) any later version.
480 |
481 | This library is distributed in the hope that it will be useful,
482 | but WITHOUT ANY WARRANTY; without even the implied warranty of
483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
484 | Lesser General Public License for more details.
485 |
486 | You should have received a copy of the GNU Lesser General Public
487 | License along with this library; if not, write to the Free Software
488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
489 | USA
490 |
491 | Also add information on how to contact you by electronic and paper mail.
492 |
493 | You should also get your employer (if you work as a programmer) or your
494 | school, if any, to sign a "copyright disclaimer" for the library, if
495 | necessary. Here is a sample; alter the names:
496 |
497 | Yoyodyne, Inc., hereby disclaims all copyright interest in the
498 | library `Frob' (a library for tweaking knobs) written by James Random
499 | Hacker.
500 |
501 | {signature of Ty Coon}, 1 April 1990
502 | Ty Coon, President of Vice
503 |
504 | That's all there is to it!
505 |
506 |
--------------------------------------------------------------------------------
/Lib/SevenZipSharp.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ColiseoSoftware/hypervbackup/93fc8ecf0fae1e5e05c46d94408763c8cc3114fa/Lib/SevenZipSharp.dll
--------------------------------------------------------------------------------
/Lib/x64/7z.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ColiseoSoftware/hypervbackup/93fc8ecf0fae1e5e05c46d94408763c8cc3114fa/Lib/x64/7z.dll
--------------------------------------------------------------------------------
/Lib/x86/7z.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ColiseoSoftware/hypervbackup/93fc8ecf0fae1e5e05c46d94408763c8cc3114fa/Lib/x86/7z.dll
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # HyperVBackup
2 |
3 | HyperVBackup is, as you can guess, a utility that can perform backups of HyperV virtual machines. It uses Volume Shadow Services (VSS) so it can back up running virtual machines.
4 |
5 | It started as a fork of http://hypervbackup.codeplex.com, as it was evident that the original creators weren’t going to update it anymore. So we added some features that we and the community were needing.
6 |
7 | Beware that this project is a heavily modified version of the original source code with a lot of features added (7zip format support, individual files filter, updated to .Net Framework 4.6.1, etc.). If you want a closer version to the original code visit http://hypervbackup.codeplex.com/discussions/567463.
8 |
9 | Note: Version 3 includes a lot of breaking changes, if you are still using version 2 you can find the previous documentation
10 | in the Wiki (https://github.com/ColiseoSoftware/hypervbackup/wiki)
11 |
12 |
13 | You can see all options executing the program without arguments, currently those are:
14 |
15 | ```
16 | f, file Text file containing a list of VMs to backup, one per line.
17 | l, list List of VMs to backup, comma separated.
18 | x, exclude List of VMs to exclude from backup, comma seperated.
19 | v, vhdinclude List of VHDs file names to backup, comma separated.
20 | i, vhdignore List of VHDs file names to ignore, comma separated.
21 | a, all (Default: True) Is set, backup all VMs on this server.
22 | n, name (Default: True) If set, VMs to backup are specified by name.
23 | g, guid If set, VMs to backup are specified by guid.
24 | o, output Required. Backup ouput folder.
25 | p, password Secure the backup with a password.
26 | z, zip Use the zip format to store the backup.
27 | d, directcopy Do not compress the output, just copy the files recreating the folder structure.
28 | outputformat Backup archive name format. {0} is the VM's name, {1} the VM's GUID, {2} is the current date and time and {3} is the extension for the compression format (7z or zip).
29 | Default: "{0}_{2:yyyyMMddHHmmss}{3}"
30 | s, singlevss Perform one single snapshot for all the VMs.
31 | compressionlevel (Default: 3) Compression level, between 0 (no compression, very fast) and 9 (max. compression, very slow).
32 | cleanoutputbydays (Default: 0) Delete all files in the output folder older than x days. TOTALLY OPTIONAL. USE WITH CAUTION.
33 | cleanoutputbymb (Default: 0) Delete older files in the output folder if total size is bigger then x Megabytes. TOTALLY OPTIONAL. USE WITH CAUTION.
34 | onsuccess Execute this program if backup completes correctly. You must provide a full path to an executable file.
35 | onfailure Execute this program if backup fails. You must provide a full path to an executable file.
36 | mt (Default: off) Enable multi-threaded compression (only for 7zip format). In multicore processors use all the processing power available. The backups are faster at the cost of high processor usage.
37 | ```
38 |
39 | For example, if you want to backup the Mail Server virtual machine on \\\shared\backups folder you use:
40 |
41 | ```HyperVBackup -l "Mail Server" -o "\\shared\backups" --compressionlevel 0```
42 |
43 | Note: short switchs use one dash (-) / long switches use two dashes (--). Not all options have a short switch available.
44 |
45 | HyperVBackup only works on HyperV Server (Windows Server 2012, 2012 R2 and 2016 supported) and DOESN’T work on HyperV Client (Windows 8, 8.1 or 10). Client Windows doesn't include the necessary OS level support, so it's a Windows limitation and HyperVBackup cannot do anything about it.
46 |
47 | By default the output is stored in 7zip format (you must provide the 7z.dll file corresponding to the version you want to use, included is version 16.04).
48 | You can use the zip format for the output, in this case an internal compression engine is used. The backups take more time and the resulting files are slightly bigger if you use the zip format.
49 |
50 | Cluster Shared Volumes are supported.
51 |
52 | **How to configure logging:**
53 |
54 | The logging functions are based in NLog (http://nlog-project.org/), so you can configure the output using the nlog.config file. The official documentation (https://github.com/NLog/NLog/wiki/Configuration-file) shows you how to build one.
55 |
56 | The included nlog.config file writes the output to:
57 | * The console window
58 | * A file located in the logfiles subfolder (check that HyperVBackup has write permissions to this folder)
59 | * A log server, which allows you to monitor the backup in real time from another machine. For security, the default configuration uses a localhost address. You can use Sentinel (https://github.com/pablopioli/Sentinel) to watch the logs.
60 |
61 | **Requirements**
62 |
63 | * .Net Framework 4.6.1 (https://www.microsoft.com/en-us/download/details.aspx?id=49981)
64 | * Visual C++ 2017 Redistributable (https://social.msdn.microsoft.com/Forums/en-US/e653a57a-bc32-4134-87bf-df33058f0531/download-microsoft-visual-c-2017-redistributable)
65 | * Only 64 bit binaries are provided, if you need a 32 bit version you must download and compile the source code using Visual Studio 2017
66 |
67 | **Troubleshooting**
68 |
69 | * If you find the following error when you run the program: System.MissingMethodException: Method not found System.Array.Empty() you are probably running the Net Framework 4.5, you need to install version 4.6.1.
70 |
71 | * If you find the following error when you run the program: Could not load file or assembly AlphaVSS.60x64.dll you need to install the Microsoft Visual C++ 2017 Redistributable Package.
72 |
73 |
74 |
--------------------------------------------------------------------------------