/// <summary> /// For all MS SQL databases it enumerate all associated paths using VSS data /// </summary> /// <returns>A collection of DBs and paths</returns> public void QueryDBsInfo() { if (!IsMSSQLInstalled) { return; } m_DBs.Clear(); using (var vssBackupComponents = new VssBackupComponents()) { var writerGUIDS = new [] { MSSQLWriterGuid }; try { vssBackupComponents.SetupWriters(writerGUIDS, null); } catch (Exception) { throw new Interface.UserInformationException("Microsoft SQL Server VSS Writer not found - cannot backup SQL databases.", "NoMsSqlVssWriter"); } foreach (var o in vssBackupComponents.ParseWriterMetaData(writerGUIDS)) { m_DBs.Add(new MSSQLDB(o.Name, o.LogicalPath + "\\" + o.Name, o.Paths.ConvertAll(m => m[0].ToString().ToUpperInvariant() + m.Substring(1)) .Distinct(Utility.Utility.ClientFilenameStringComparer) .OrderBy(a => a).ToList())); } } }
/// <summary> /// Constructs a new backup snapshot, using all the required disks /// </summary> /// <param name="sources">Sources to determine which volumes to include in snapshot</param> /// <param name="options">A set of commandline options</param> public WindowsSnapshot(IEnumerable <string> sources, IDictionary <string, string> options) { // For Windows, ensure we don't store paths with UNC prefix sources = sources.Select(SystemIOWindows.StripUNCPrefix); try { _vssBackupComponents = new VssBackupComponents(); // Default to exclude the System State writer var excludedWriters = new Guid[] { new Guid("{e8132975-6f93-4464-a53e-1050253ae220}") }; if (options.ContainsKey("vss-exclude-writers")) { excludedWriters = options["vss-exclude-writers"] .Split(';') .Where(x => !string.IsNullOrWhiteSpace(x) && x.Trim().Length > 0) .Select(x => new Guid(x)) .ToArray(); } _vssBackupComponents.SetupWriters(null, excludedWriters); _vssBackupComponents.InitShadowVolumes(sources); _vssBackupComponents.MapVolumesToSnapShots(); //If we should map the drives, we do that now and update the volumeMap if (Utility.Utility.ParseBoolOption(options, "vss-use-mapping")) { _vssBackupComponents.MapDrives(); } } catch (Exception ex1) { Logging.Log.WriteVerboseMessage(LOGTAG, "WindowsSnapshotCreation", ex1, "Failed to initialize windows snapshot instance"); //In case we fail in the constructor, we do not want a snapshot to be active try { Dispose(); } catch (Exception ex2) { Logging.Log.WriteVerboseMessage(LOGTAG, "VSSCleanupOnError", ex2, "Failed during VSS error cleanup"); } throw; } }
/// <summary> /// For all Hyper-V guests it enumerate all associated paths using VSS data /// </summary> /// <returns>A collection of VMs and paths</returns> private static IEnumerable <WriterMetaData> GetAllVMsPathsVSS() { using (var vssBackupComponents = new VssBackupComponents()) { var writerGUIDS = new [] { HyperVWriterGuid }; try { vssBackupComponents.SetupWriters(writerGUIDS, null); } catch (Exception) { throw new Interface.UserInformationException("Microsoft Hyper-V VSS Writer not found - cannot backup Hyper-V machines.", "NoHyperVVssWriter"); } foreach (var o in vssBackupComponents.ParseWriterMetaData(writerGUIDS)) { yield return(o); } } }