{"id":94975,"date":"2016-12-20T07:00:00","date_gmt":"2016-12-20T22:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/?p=94975"},"modified":"2019-03-13T10:35:00","modified_gmt":"2019-03-13T17:35:00","slug":"20161220-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20161220-00\/?p=94975","title":{"rendered":"If you ask robocopy to destroy the destination, then it will destroy the destination"},"content":{"rendered":"<p>A customer reported that Explorer was not showing a folder on their hard drive that they were sure was there. <\/p>\n<p>I asked them to check whether the folder really was there, by going to a command prompt and using the <code>dir \/a<\/code> command. <\/p>\n<p>Turns out the folder really was gone. <\/p>\n<p>The customer went back and retraced their steps and reconstructed what happened. <\/p>\n<p>First, the customer created a folder on their <code>D:<\/code> called <code>D:\\backups\\fdrive\\spreadsheets<\/code>. <\/p>\n<p>Next the customer copied two files from their <code>F:<\/code> drive to the <code>D:\\backups\\fdrive\\spreadsheets<\/code> folder. <\/p>\n<p>So far so good. <\/p>\n<p>Next, the customer wanted to copy their entire <code>F:<\/code> drive to the  <code>D:\\backups\\fdrive<\/code> folder, so they performed the following command: <\/p>\n<pre>\nrobocopy \/MIR F: D:\\backups\\fdrive\n<\/pre>\n<p>The customer let this command run for a while, but then the operation started encountering <\/i>Access denied<\/i> errors, so they hit <kbd>Ctrl<\/kbd>+<kbd>C<\/kbd> to stop the robocopy command. <\/p>\n<p>At this point, the customer noticed that the <code>spreadsheets<\/code> folder was gone. <\/p>\n<p>The customer theorized, &#8220;I suspect that what happened is that robocopy was matching the directory structure of the <code>F:<\/code> drive against the directory structure of <code>D:\\backups\\fdrive<\/code>, and since my important spreadsheet files weren&#8217;t present in the <code>F:\\spreadsheets<\/code> folder on the source, it deleted them from the destination. If I had let the copy run to completion, it presumably would have eventually copied the files from their location on the <code>F:<\/code> drive to the corresponding subdirectory of <code>D:\\backups\\fdrive<\/code>.&#8221; <\/p>\n<p>The customer continued, &#8220;From a user perspective, it seems that I <i>should<\/i> have really been alerted by robocopy that the target folder (in this case, <code>D:\\backups\\fdrive<\/code>) wasn&#8217;t empty, and it should have asked for confirmation that I didn&#8217;t really want to lose those files (which I didn&#8217;t).&#8221; <\/p>\n<p>Well, um, yeah, because that&#8217;s what the <code>\/MIR<\/code> option means. <\/p>\n<pre>\n       \/E :: copy subdirectories, including Empty ones.\n   \/PURGE :: delete dest files\/dirs that no longer exist in source.\n     \/MIR :: MIRror a directory tree (equivalent to \/E plus \/PURGE).\n<\/pre>\n<p>The <code>\/MIR<\/code> option means that the destination folder should be an exact copy of the source folder. The documentation points out that this is the same as <code>\/E<\/code> (copy recursively) combined with <code>\/PURGE<\/code> (remove anything from the destination that is not present in the source). <\/p>\n<p>The <code>\/PURGE<\/code> behavior is by definition destructive. <\/p>\n<p>If that&#8217;s not what you want, then don&#8217;t pass the <code>\/MIR<\/code> flag. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Be careful what you ask for. You might get it.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[104],"class_list":["post-94975","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-tipssupport"],"acf":[],"blog_post_summary":"<p>Be careful what you ask for. You might get it.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/94975","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=94975"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/94975\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=94975"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=94975"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=94975"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}