moved hyper-v code to hyper-v classes

This commit is contained in:
Max
2016-10-16 01:40:12 +02:00
parent 17178b56d9
commit 06cccea7a7
4 changed files with 23 additions and 15 deletions
@@ -40,8 +40,9 @@ namespace Duplicati.Library.Interface
/// </summary>
/// <param name="paths">Backup source paths</param>
/// <param name="filter">Filters that are applied to backup paths (include, exclude)</param>
/// <param name="commandlineOptions">A set of commandline options passed to Duplicati</param>
/// <returns>A list of changed or added options values</returns>
Dictionary<string, string> ParseSource(ref string[] paths, ref string filter);
Dictionary<string, string> ParseSource(ref string[] paths, ref string filter, Dictionary<string, string> commandlineOptions);
/// <summary>
/// This method is the interception where the module can interact with the execution environment and modify the settings.
+1 -1
View File
@@ -613,7 +613,7 @@ namespace Duplicati.Library.Main
if (mx.Value is Library.Interface.IGenericSourceModule)
{
var sourceoptions = ((Library.Interface.IGenericSourceModule)mx.Value).ParseSource(ref paths, ref pristinefilter);
var sourceoptions = ((Library.Interface.IGenericSourceModule)mx.Value).ParseSource(ref paths, ref pristinefilter, m_options.RawOptions);
foreach (var sourceoption in sourceoptions)
m_options.RawOptions[sourceoption.Key] = sourceoption.Value;
@@ -248,12 +248,6 @@ namespace Duplicati.Library.Main.Operation
public static Snapshots.ISnapshotService GetSnapshot(string[] sources, Options options, ILogWriter log)
{
if (!Library.Utility.Utility.IsClientWindows && options.RawOptions.ContainsKey("hyperv-backup-vm"))
log.AddWarning("hyperv-backup-vm is efective only on Windows OS.", null);
if (Library.Utility.Utility.IsClientWindows && options.RawOptions.ContainsKey("hyperv-backup-vm") && options.SnapShotStrategy == Options.OptimizationStrategy.Off)
throw new Exception("Snapshot strategy cannot be Off when backuping Hyper-V using hyperv-backup-vm"); //VSS is required for Hyper-V backups
try
{
if (options.SnapShotStrategy != Options.OptimizationStrategy.Off)
@@ -263,12 +257,8 @@ namespace Duplicati.Library.Main.Operation
{
if (options.SnapShotStrategy == Options.OptimizationStrategy.Required)
throw;
else if (options.SnapShotStrategy == Options.OptimizationStrategy.On && options.RawOptions.ContainsKey("hyperv-backup-vm"))
throw; //VSS is required for Hyper-V backups
else if (options.SnapShotStrategy == Options.OptimizationStrategy.On)
{
log.AddWarning(Strings.Common.SnapshotFailedError(ex.ToString()), ex);
}
}
return Library.Utility.Utility.IsClientLinux ?
@@ -72,7 +72,7 @@ namespace Duplicati.Library.Modules.Builtin
#endregion
#region Implementation of IGenericSourceModule
public Dictionary<string, string> ParseSource(ref string[] paths, ref string filter)
public Dictionary<string, string> ParseSource(ref string[] paths, ref string filter, Dictionary<string, string> commandlineOptions)
{
var hypervpathguidexp = @"%HYPERV:(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}%";
var hypervguidexp = @"(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}";
@@ -81,7 +81,10 @@ namespace Duplicati.Library.Modules.Builtin
var ret = new Dictionary<string, string>();
if (paths.Contains(hypervpathallexp, StringComparer.OrdinalIgnoreCase))
pathshyperv = new HyperVUtility().GetHyperVGuests().Select(x => string.Format("%HYPERV:{0}%", x.ID)).ToList();
{
if (Utility.Utility.IsClientWindows)
pathshyperv = new HyperVUtility().GetHyperVGuests().Select(x => string.Format("%HYPERV:{0}%", x.ID)).ToList();
}
else
pathshyperv = paths.Where(x => Regex.IsMatch(x, hypervpathguidexp, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)).ToList();
@@ -101,7 +104,21 @@ namespace Duplicati.Library.Modules.Builtin
}
pathshyperv = pathshyperv.Select(x => Regex.Match(x, hypervguidexp).Value).ToList();
ret[OPTION_SOURCE] = string.Join(System.IO.Path.PathSeparator.ToString(), pathshyperv);
if (pathshyperv.Count != 0 && Utility.Utility.IsClientWindows && (!commandlineOptions.Keys.Contains("snapshot-policy") || commandlineOptions["snapshot-policy"] != "required"))
{
Logging.Log.WriteMessage("Snapshot strategy have to be set to \"required\" when backuping Hyper-V virtual machines. Changing to \"required\" to continue.", Logging.LogMessageType.Information);
ret["snapshot-policy"] = "required";
}
if (pathshyperv.Count != 0)
{
if (Utility.Utility.IsClientWindows)
ret[OPTION_SOURCE] = string.Join(System.IO.Path.PathSeparator.ToString(), pathshyperv);
else
Logging.Log.WriteMessage("Hyper-V backup works only on Windows OS.", Logging.LogMessageType.Warning);
}
return ret;
}