From 06cccea7a74d8f76bae42fdd2be983f413bb2d8a Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 16 Oct 2016 01:40:12 +0200 Subject: [PATCH] moved hyper-v code to hyper-v classes --- .../Library/Interface/IGenericSourceModule.cs | 3 ++- Duplicati/Library/Main/Controller.cs | 2 +- .../Library/Main/Operation/BackupHandler.cs | 10 -------- .../Library/Modules/Builtin/HyperVOptions.cs | 23 ++++++++++++++++--- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/Duplicati/Library/Interface/IGenericSourceModule.cs b/Duplicati/Library/Interface/IGenericSourceModule.cs index 8628983b0..1f1d8c0b4 100644 --- a/Duplicati/Library/Interface/IGenericSourceModule.cs +++ b/Duplicati/Library/Interface/IGenericSourceModule.cs @@ -40,8 +40,9 @@ namespace Duplicati.Library.Interface /// /// Backup source paths /// Filters that are applied to backup paths (include, exclude) + /// A set of commandline options passed to Duplicati /// A list of changed or added options values - Dictionary ParseSource(ref string[] paths, ref string filter); + Dictionary ParseSource(ref string[] paths, ref string filter, Dictionary commandlineOptions); /// /// This method is the interception where the module can interact with the execution environment and modify the settings. diff --git a/Duplicati/Library/Main/Controller.cs b/Duplicati/Library/Main/Controller.cs index 13305137c..3d53b0f33 100644 --- a/Duplicati/Library/Main/Controller.cs +++ b/Duplicati/Library/Main/Controller.cs @@ -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; diff --git a/Duplicati/Library/Main/Operation/BackupHandler.cs b/Duplicati/Library/Main/Operation/BackupHandler.cs index 372d7ed5b..99688d73e 100644 --- a/Duplicati/Library/Main/Operation/BackupHandler.cs +++ b/Duplicati/Library/Main/Operation/BackupHandler.cs @@ -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 ? diff --git a/Duplicati/Library/Modules/Builtin/HyperVOptions.cs b/Duplicati/Library/Modules/Builtin/HyperVOptions.cs index 6e5ac5c61..72351e742 100644 --- a/Duplicati/Library/Modules/Builtin/HyperVOptions.cs +++ b/Duplicati/Library/Modules/Builtin/HyperVOptions.cs @@ -72,7 +72,7 @@ namespace Duplicati.Library.Modules.Builtin #endregion #region Implementation of IGenericSourceModule - public Dictionary ParseSource(ref string[] paths, ref string filter) + public Dictionary ParseSource(ref string[] paths, ref string filter, Dictionary 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(); 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; }