{"action":"created","comment":{"url":"https://api.github.com/repos/duplicati/duplicati/pulls/comments/82339120","pull_request_review_id":3254079,"id":82339120,"diff_hunk":"@@ -108,59 +105,94 @@ public WindowsSnapshot(string[] sourcepaths, Dictionary<string, string> options)\n                 var requestedHyperVMs = new List<string>();\r\n                 if (options.ContainsKey(\"hyperv-backup-vm\"))\r\n                     requestedHyperVMs = options[\"hyperv-backup-vm\"].Split(';').Where(x => !string.IsNullOrWhiteSpace(x) && x.Trim().Length > 0).ToList();\r\n-                \r\n+\r\n                 //Check if we are backing up HyperV machines\r\n                 if (requestedHyperVMs.Count > 0)\r\n                 {\r\n-                    var hyperVUtility = new HyperVUtility(requestedHyperVMs);\r\n-                    m_hyperVMachines = hyperVUtility.GetHyperVMachines();\r\n+                    Logging.Log.WriteMessage(\"Starting to gather Hyper-V information.\", Logging.LogMessageType.Information);\r\n \r\n-                    #region Testing Features\r\n-                    if (!Utility.Utility.ParseBoolOption(options, \"hyperv-backup-no-merge\"))\r\n-                        hyperVUtility.MergeVhd(requestedHyperVMs);\r\n+                    var hyperVUtility = new HyperVUtility();\r\n+                    var hyperVGuests = hyperVUtility.GetHyperVGuests();\r\n \r\n-                    //Option: Create-new-vm-after-restore, \r\n-                    //hyperVUtility.CreateHyperVMachine(\"TestVM\", xmlpath);\r\n-                    #endregion Testing Features\r\n-                }\r\n+                    Logging.Log.WriteMessage(string.Format(\"Found {0} virtual machines on Hyper-V.\", hyperVGuests.Count), Logging.LogMessageType.Information);\r\n \r\n-                m_backup.StartSnapshotSet();\r\n+                    bool bNotFound = false;\r\n+                    List<string> notFoundVM = new List<string>();\r\n+                    foreach (var requestedHyperVM in requestedHyperVMs)\r\n+                    {\r\n+                        var foundVMs = hyperVGuests.FindAll(x => (x.ID.ToLower() == requestedHyperVM.ToLower()));\r\n \r\n-                try\r\n-                {\r\n-                    //Gather information on all Vss writers\r\n-                    m_backup.GatherWriterMetadata();\r\n+                        if (foundVMs.Count != 1)\r\n+                        {\r\n+                            bNotFound = true;\r\n+                            notFoundVM.Add(requestedHyperVM);\r\n+                            Logging.Log.WriteMessage(string.Format(\"Cannot find virtual machine with ID {0} on Hyper-V.\", requestedHyperVM), Logging.LogMessageType.Error);\r\n+                        }\r\n+                        else\r\n+                            Logging.Log.WriteMessage(string.Format(\"Found virtual machine {0} with ID {1} on Hyper-V.\", foundVMs[0].Name, requestedHyperVM), Logging.LogMessageType.Information);\r\n+                    }\r\n \r\n-                    //Update the sourcepaths if we're backing up Hyper-V Machines\r\n-                    if (requestedHyperVMs.Count > 0)\r\n+                    if (bNotFound)\r\n+                        throw new Exception(string.Format(\"Cannot find virtual machine with ID {0} on Hyper-V.\", string.Join(\", \", notFoundVM.ToArray())));\r\n+\r\n+                    var productType = new ManagementObjectSearcher(\"SELECT * FROM Win32_OperatingSystem\")\r\n+                        .Get().OfType<ManagementObject>()\r\n+                        .Select(o => (uint)o.GetPropertyValue(\"ProductType\")).First();\r\n+\r\n+                    if (productType != 1) // Hyper-V writer is present only on Server version of Windows\r\n                     {\r\n-                        //Find sourcepaths in Hyper-V WriterMetaData\r\n-                        var m_backup_wmd = m_backup.WriterMetadata.FirstOrDefault(o => o.WriterId.Equals(HyperVWriterGuid));\r\n-                        if (m_backup_wmd != null)\r\n-                            foreach (var component in m_backup_wmd.Components)\r\n+                        try\r\n+                        {\r\n+                            m_backup.GatherWriterMetadata();\r\n+                            var m_backup_wmd = m_backup.WriterMetadata.FirstOrDefault(o => o.WriterId.Equals(HyperVWriterGuid));\r\n+\r\n+                            if (m_backup_wmd != null)\r\n                             {\r\n-                                //Cross reference the requested Hyper-V Machines to backup and add the sources\r\n-                                if (!m_hyperVMachines.ContainsKey(component.ComponentName)) \r\n-                                    continue;\r\n-                            \r\n-                                foreach (var file in component.Files)\r\n+                                foreach (var component in m_backup_wmd.Components)\r\n+                                    if (requestedHyperVMs.Contains(component.ComponentName))\r\n+                                        foreach (var file in component.Files)\r\n+                                            if (file.FileSpecification.Contains(\"*\"))\r\n+                                            {\r\n+                                                if (Directory.Exists(file.Path + \"\\\\\"))\r\n+                                                {\r\n+                                                    m_sourcepaths.Add(file.Path + \"\\\\\");\r\n+                                                    Logging.Log.WriteMessage(string.Format(\"For VM {0} - adding {1}.\", component.ComponentName, file.Path + \"\\\\\"), Logging.LogMessageType.Profiling);\r\n+                                                }\r\n+                                            }\r\n+                                            else\r\n+                                            {\r\n+                                                if (File.Exists(Path.Combine(file.Path, file.FileSpecification)))\r\n+                                                {\r\n+                                                    m_sourcepaths.Add(Path.Combine(file.Path, file.FileSpecification));\r\n+                                                    Logging.Log.WriteMessage(string.Format(\"For VM {0} - adding {1}.\", component.ComponentName, Path.Combine(file.Path, file.FileSpecification)), Logging.LogMessageType.Profiling);\r\n+                                                }\r\n+                                            }\r\n+                            }\r\n+                            else\r\n+                                throw new Exception(\"Microsoft Hyper-V VSS Writer not found - cannot backup Hyper-V machines.\");\r\n+                        }\r\n+                        finally\r\n+                        {\r\n+                            m_backup.FreeWriterMetadata();\r\n+                        }\r\n+                    }\r\n+                    else\r\n+                    {\r\n+                        Logging.Log.WriteMessage(\"This is client version of Windows. Hyper-V VSS writer is present only on Server version. Backup will continue, but will be crash consistent only in opposite to application consistent in Server version.\", Logging.LogMessageType.Warning);\r\n+\r\n+                        foreach (var hyperVGuest in hyperVGuests)\r\n+                            if (requestedHyperVMs.Contains(hyperVGuest.ID))\r\n+                                foreach (var path in hyperVGuest.DataPaths)\r\n                                 {\r\n-                                    if (file.FileSpecification.Contains(\"*\")) \r\n-                                        continue;\r\n-                                    m_sourcepaths.Add(file.Path + file.FileSpecification);\r\n+                                    m_sourcepaths.Add(path);\r\n+                                    Logging.Log.WriteMessage(string.Format(\"For VM {0} - adding {1}.\", hyperVGuest.ID, path), Logging.LogMessageType.Profiling);\r\n                                 }\r\n-                            }\r\n                     }\r\n \r\n-                    m_backup.FreeWriterMetadata();\r\n+                    m_sourcepaths = m_sourcepaths.Distinct(StringComparer.CurrentCultureIgnoreCase).OrderBy(a => a).ToList();\r\n                 }\r","path":"Duplicati/Library/Snapshots/WindowsSnapshot.cs","position":139,"original_position":139,"commit_id":"b6eb6d444baa4abf8c29ab8dfa73e6f719c846eb","original_commit_id":"b6eb6d444baa4abf8c29ab8dfa73e6f719c846eb","user":{"login":"kenkendk","id":1510755,"avatar_url":"https://avatars.githubusercontent.com/u/1510755?v=3","gravatar_id":"","url":"https://api.github.com/users/kenkendk","html_url":"https://github.com/kenkendk","followers_url":"https://api.github.com/users/kenkendk/followers","following_url":"https://api.github.com/users/kenkendk/following{/other_user}","gists_url":"https://api.github.com/users/kenkendk/gists{/gist_id}","starred_url":"https://api.github.com/users/kenkendk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kenkendk/subscriptions","organizations_url":"https://api.github.com/users/kenkendk/orgs","repos_url":"https://api.github.com/users/kenkendk/repos","events_url":"https://api.github.com/users/kenkendk/events{/privacy}","received_events_url":"https://api.github.com/users/kenkendk/received_events","type":"User","site_admin":false},"body":"This should use `Library.Utility.Utility.ClientFilenameStringComparer` to be consistent, but since Hyper-V is Windows-only it is not terribly important","created_at":"2016-10-07T07:16:02Z","updated_at":"2016-10-07T07:16:02Z","html_url":"https://github.com/duplicati/duplicati/pull/1982#discussion_r82339120","pull_request_url":"https://api.github.com/repos/duplicati/duplicati/pulls/1982","_links":{"self":{"href":"https://api.github.com/repos/duplicati/duplicati/pulls/comments/82339120"},"html":{"href":"https://github.com/duplicati/duplicati/pull/1982#discussion_r82339120"},"pull_request":{"href":"https://api.github.com/repos/duplicati/duplicati/pulls/1982"}}},"pull_request":{"url":"https://api.github.com/repos/duplicati/duplicati/pulls/1982","id":88171011,"html_url":"https://github.com/duplicati/duplicati/pull/1982","diff_url":"https://github.com/duplicati/duplicati/pull/1982.diff","patch_url":"https://github.com/duplicati/duplicati/pull/1982.patch","issue_url":"https://api.github.com/repos/duplicati/duplicati/issues/1982","number":1982,"state":"open","locked":false,"title":"Hyper-v fixes","user":{"login":"mnaiman","id":2264442,"avatar_url":"https://avatars.githubusercontent.com/u/2264442?v=3","gravatar_id":"","url":"https://api.github.com/users/mnaiman","html_url":"https://github.com/mnaiman","followers_url":"https://api.github.com/users/mnaiman/followers","following_url":"https://api.github.com/users/mnaiman/following{/other_user}","gists_url":"https://api.github.com/users/mnaiman/gists{/gist_id}","starred_url":"https://api.github.com/users/mnaiman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mnaiman/subscriptions","organizations_url":"https://api.github.com/users/mnaiman/orgs","repos_url":"https://api.github.com/users/mnaiman/repos","events_url":"https://api.github.com/users/mnaiman/events{/privacy}","received_events_url":"https://api.github.com/users/mnaiman/received_events","type":"User","site_admin":false},"body":"fixes for hyper-v\r\nremove very dangerous parameter hyperv-backup-no-merge which was not btw default\r\nadded basic logging\r\nadded safe checks","created_at":"2016-10-05T22:45:00Z","updated_at":"2016-10-07T07:16:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8184c20e1d997f957a4dfc0b4a70452c20e9a61c","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/duplicati/duplicati/pulls/1982/commits","review_comments_url":"https://api.github.com/repos/duplicati/duplicati/pulls/1982/comments","review_comment_url":"https://api.github.com/repos/duplicati/duplicati/pulls/comments{/number}","comments_url":"https://api.github.com/repos/duplicati/duplicati/issues/1982/comments","statuses_url":"https://api.github.com/repos/duplicati/duplicati/statuses/b6eb6d444baa4abf8c29ab8dfa73e6f719c846eb","head":{"label":"mnaiman:hyper_v_fixes","ref":"hyper_v_fixes","sha":"b6eb6d444baa4abf8c29ab8dfa73e6f719c846eb","user":{"login":"mnaiman","id":2264442,"avatar_url":"https://avatars.githubusercontent.com/u/2264442?v=3","gravatar_id":"","url":"https://api.github.com/users/mnaiman","html_url":"https://github.com/mnaiman","followers_url":"https://api.github.com/users/mnaiman/followers","following_url":"https://api.github.com/users/mnaiman/following{/other_user}","gists_url":"https://api.github.com/users/mnaiman/gists{/gist_id}","starred_url":"https://api.github.com/users/mnaiman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mnaiman/subscriptions","organizations_url":"https://api.github.com/users/mnaiman/orgs","repos_url":"https://api.github.com/users/mnaiman/repos","events_url":"https://api.github.com/users/mnaiman/events{/privacy}","received_events_url":"https://api.github.com/users/mnaiman/received_events","type":"User","site_admin":false},"repo":{"id":59917473,"name":"duplicati","full_name":"mnaiman/duplicati","owner":{"login":"mnaiman","id":2264442,"avatar_url":"https://avatars.githubusercontent.com/u/2264442?v=3","gravatar_id":"","url":"https://api.github.com/users/mnaiman","html_url":"https://github.com/mnaiman","followers_url":"https://api.github.com/users/mnaiman/followers","following_url":"https://api.github.com/users/mnaiman/following{/other_user}","gists_url":"https://api.github.com/users/mnaiman/gists{/gist_id}","starred_url":"https://api.github.com/users/mnaiman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mnaiman/subscriptions","organizations_url":"https://api.github.com/users/mnaiman/orgs","repos_url":"https://api.github.com/users/mnaiman/repos","events_url":"https://api.github.com/users/mnaiman/events{/privacy}","received_events_url":"https://api.github.com/users/mnaiman/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mnaiman/duplicati","description":"Store securely encrypted backups on cloud storage services!","fork":true,"url":"https://api.github.com/repos/mnaiman/duplicati","forks_url":"https://api.github.com/repos/mnaiman/duplicati/forks","keys_url":"https://api.github.com/repos/mnaiman/duplicati/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mnaiman/duplicati/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mnaiman/duplicati/teams","hooks_url":"https://api.github.com/repos/mnaiman/duplicati/hooks","issue_events_url":"https://api.github.com/repos/mnaiman/duplicati/issues/events{/number}","events_url":"https://api.github.com/repos/mnaiman/duplicati/events","assignees_url":"https://api.github.com/repos/mnaiman/duplicati/assignees{/user}","branches_url":"https://api.github.com/repos/mnaiman/duplicati/branches{/branch}","tags_url":"https://api.github.com/repos/mnaiman/duplicati/tags","blobs_url":"https://api.github.com/repos/mnaiman/duplicati/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mnaiman/duplicati/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mnaiman/duplicati/git/refs{/sha}","trees_url":"https://api.github.com/repos/mnaiman/duplicati/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mnaiman/duplicati/statuses/{sha}","languages_url":"https://api.github.com/repos/mnaiman/duplicati/languages","stargazers_url":"https://api.github.com/repos/mnaiman/duplicati/stargazers","contributors_url":"https://api.github.com/repos/mnaiman/duplicati/contributors","subscribers_url":"https://api.github.com/repos/mnaiman/duplicati/subscribers","subscription_url":"https://api.github.com/repos/mnaiman/duplicati/subscription","commits_url":"https://api.github.com/repos/mnaiman/duplicati/commits{/sha}","git_commits_url":"https://api.github.com/repos/mnaiman/duplicati/git/commits{/sha}","comments_url":"https://api.github.com/repos/mnaiman/duplicati/comments{/number}","issue_comment_url":"https://api.github.com/repos/mnaiman/duplicati/issues/comments{/number}","contents_url":"https://api.github.com/repos/mnaiman/duplicati/contents/{+path}","compare_url":"https://api.github.com/repos/mnaiman/duplicati/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mnaiman/duplicati/merges","archive_url":"https://api.github.com/repos/mnaiman/duplicati/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mnaiman/duplicati/downloads","issues_url":"https://api.github.com/repos/mnaiman/duplicati/issues{/number}","pulls_url":"https://api.github.com/repos/mnaiman/duplicati/pulls{/number}","milestones_url":"https://api.github.com/repos/mnaiman/duplicati/milestones{/number}","notifications_url":"https://api.github.com/repos/mnaiman/duplicati/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mnaiman/duplicati/labels{/name}","releases_url":"https://api.github.com/repos/mnaiman/duplicati/releases{/id}","deployments_url":"https://api.github.com/repos/mnaiman/duplicati/deployments","created_at":"2016-05-28T22:47:15Z","updated_at":"2016-05-28T22:47:18Z","pushed_at":"2016-10-05T22:45:47Z","git_url":"git://github.com/mnaiman/duplicati.git","ssh_url":"git@github.com:mnaiman/duplicati.git","clone_url":"https://github.com/mnaiman/duplicati.git","svn_url":"https://github.com/mnaiman/duplicati","homepage":"","size":70826,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"duplicati:master","ref":"master","sha":"34072445e486c21cf8da4a117711adde49f7f441","user":{"login":"duplicati","id":8270231,"avatar_url":"https://avatars.githubusercontent.com/u/8270231?v=3","gravatar_id":"","url":"https://api.github.com/users/duplicati","html_url":"https://github.com/duplicati","followers_url":"https://api.github.com/users/duplicati/followers","following_url":"https://api.github.com/users/duplicati/following{/other_user}","gists_url":"https://api.github.com/users/duplicati/gists{/gist_id}","starred_url":"https://api.github.com/users/duplicati/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/duplicati/subscriptions","organizations_url":"https://api.github.com/users/duplicati/orgs","repos_url":"https://api.github.com/users/duplicati/repos","events_url":"https://api.github.com/users/duplicati/events{/privacy}","received_events_url":"https://api.github.com/users/duplicati/received_events","type":"Organization","site_admin":false},"repo":{"id":22636263,"name":"duplicati","full_name":"duplicati/duplicati","owner":{"login":"duplicati","id":8270231,"avatar_url":"https://avatars.githubusercontent.com/u/8270231?v=3","gravatar_id":"","url":"https://api.github.com/users/duplicati","html_url":"https://github.com/duplicati","followers_url":"https://api.github.com/users/duplicati/followers","following_url":"https://api.github.com/users/duplicati/following{/other_user}","gists_url":"https://api.github.com/users/duplicati/gists{/gist_id}","starred_url":"https://api.github.com/users/duplicati/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/duplicati/subscriptions","organizations_url":"https://api.github.com/users/duplicati/orgs","repos_url":"https://api.github.com/users/duplicati/repos","events_url":"https://api.github.com/users/duplicati/events{/privacy}","received_events_url":"https://api.github.com/users/duplicati/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/duplicati/duplicati","description":"Store securely encrypted backups on cloud storage services!","fork":false,"url":"https://api.github.com/repos/duplicati/duplicati","forks_url":"https://api.github.com/repos/duplicati/duplicati/forks","keys_url":"https://api.github.com/repos/duplicati/duplicati/keys{/key_id}","collaborators_url":"https://api.github.com/repos/duplicati/duplicati/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/duplicati/duplicati/teams","hooks_url":"https://api.github.com/repos/duplicati/duplicati/hooks","issue_events_url":"https://api.github.com/repos/duplicati/duplicati/issues/events{/number}","events_url":"https://api.github.com/repos/duplicati/duplicati/events","assignees_url":"https://api.github.com/repos/duplicati/duplicati/assignees{/user}","branches_url":"https://api.github.com/repos/duplicati/duplicati/branches{/branch}","tags_url":"https://api.github.com/repos/duplicati/duplicati/tags","blobs_url":"https://api.github.com/repos/duplicati/duplicati/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/duplicati/duplicati/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/duplicati/duplicati/git/refs{/sha}","trees_url":"https://api.github.com/repos/duplicati/duplicati/git/trees{/sha}","statuses_url":"https://api.github.com/repos/duplicati/duplicati/statuses/{sha}","languages_url":"https://api.github.com/repos/duplicati/duplicati/languages","stargazers_url":"https://api.github.com/repos/duplicati/duplicati/stargazers","contributors_url":"https://api.github.com/repos/duplicati/duplicati/contributors","subscribers_url":"https://api.github.com/repos/duplicati/duplicati/subscribers","subscription_url":"https://api.github.com/repos/duplicati/duplicati/subscription","commits_url":"https://api.github.com/repos/duplicati/duplicati/commits{/sha}","git_commits_url":"https://api.github.com/repos/duplicati/duplicati/git/commits{/sha}","comments_url":"https://api.github.com/repos/duplicati/duplicati/comments{/number}","issue_comment_url":"https://api.github.com/repos/duplicati/duplicati/issues/comments{/number}","contents_url":"https://api.github.com/repos/duplicati/duplicati/contents/{+path}","compare_url":"https://api.github.com/repos/duplicati/duplicati/compare/{base}...{head}","merges_url":"https://api.github.com/repos/duplicati/duplicati/merges","archive_url":"https://api.github.com/repos/duplicati/duplicati/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/duplicati/duplicati/downloads","issues_url":"https://api.github.com/repos/duplicati/duplicati/issues{/number}","pulls_url":"https://api.github.com/repos/duplicati/duplicati/pulls{/number}","milestones_url":"https://api.github.com/repos/duplicati/duplicati/milestones{/number}","notifications_url":"https://api.github.com/repos/duplicati/duplicati/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/duplicati/duplicati/labels{/name}","releases_url":"https://api.github.com/repos/duplicati/duplicati/releases{/id}","deployments_url":"https://api.github.com/repos/duplicati/duplicati/deployments","created_at":"2014-08-05T08:28:16Z","updated_at":"2016-10-07T06:45:55Z","pushed_at":"2016-10-07T07:02:27Z","git_url":"git://github.com/duplicati/duplicati.git","ssh_url":"git@github.com:duplicati/duplicati.git","clone_url":"https://github.com/duplicati/duplicati.git","svn_url":"https://github.com/duplicati/duplicati","homepage":"","size":76380,"stargazers_count":947,"watchers_count":947,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":159,"mirror_url":null,"open_issues_count":518,"forks":159,"open_issues":518,"watchers":947,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/duplicati/duplicati/pulls/1982"},"html":{"href":"https://github.com/duplicati/duplicati/pull/1982"},"issue":{"href":"https://api.github.com/repos/duplicati/duplicati/issues/1982"},"comments":{"href":"https://api.github.com/repos/duplicati/duplicati/issues/1982/comments"},"review_comments":{"href":"https://api.github.com/repos/duplicati/duplicati/pulls/1982/comments"},"review_comment":{"href":"https://api.github.com/repos/duplicati/duplicati/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/duplicati/duplicati/pulls/1982/commits"},"statuses":{"href":"https://api.github.com/repos/duplicati/duplicati/statuses/b6eb6d444baa4abf8c29ab8dfa73e6f719c846eb"}}}}
{"actor":{"display_login":"kenkendk"}}