The robocopy command line tool offers much more flexibility than using Windows Explorer or the copy command to copy your files from one destination to another. A popular parameter used with the robocopy command is /mir. But, you may find that it deletes some of your files from the destination folder. In the sections below, we’ll take a look at why this happens and how you can recover files deleted by the robocopy /mir command.
What is Robocopy and How it Wipes Data
Robocopy is short for “Robust File Copy,” which, at its core, is a command-line tool used to copy folders from one destination to another. However, it has numerous parameters and switches that provide unparalleled flexibility – the reason it’s so popular among IT professionals. For a complete list of Robocopy switches and parameters, look at Microsoft’s Robocopy page. Alternatively, you can use the robocopy /?
command in CMD to see a complete list of the various modifiers and what they do.
So, how does a tool that’s used to copy files from one location to another manage to delete your files?
Well, it usually happens because of the /mir parameter—which commands Windows to mirror the source folder and the destination folder. Any files that aren’t there in the source folder, but are there in the destination folder, will be deleted. In essence, the folders need to be an exact copy of each other, without any extra files or folders.
Note: Robocopy copies entire folders from one destination to another. You cannot use the tool to copy a singular file.
How to Recover Deleted Files After Using Robocopy /Mir
Files that were deleted because of the robocopy /mir command can usually be recovered. We say, “usually,” because deleted files are technically still there on your drive until new files overwrite the data blocks which previous files occupied.
If you’ve copied numerous new files to your drive, data recovery is still possible, but not all your files will be recovered. Of course, if you have a backup or other copies of the files, you can recover all of them. But, that’s unlikely if you’re on this page.
Third-party data recovery tools are your best bet when looking to recover files deleted by the robocopy /mir command. There are plenty of such tools available on the web, but we recommend you choose one that has a good track record, is easy-to-use, and can recover deleted files from network drives (since robocopy is often used to copy files to and from network locations).
Our data recovery tool of choice is Disk Drill. It’s exceptionally easy-to-use, while being equipped with an excellent data recovery algorithm. The software is versatile—with support for all major file systems and storage device types, making it useful in a wide variety of data loss scenarios. Windows users can take advantage of Disk Drill’s free trial which lets them recover up to 500 MB of data for free.
Here’s how to use Disk Drill to restore deleted files:
- Download Disk Drill and install it. Do this on a different storage device, not the one which contains the deleted files.
- Open Disk Drill, select the drive or partition which contains the deleted files, and click Search for lost data to begin the data recovery scan.
- Click on Review found items to view the files Disk Drill discovered. If you wish to filter out the results, you can directly click on the relevant file type tiles instead (Pictures, Video, Audio, Documents, Archives, and Other).
- Expand the Deleted or lost and Reconstructed sections to view deleted files that are recoverable.
- Use the checkboxes to select the files you wish to recover. To help you out Disk Drill displays a preview of the currently selected file, and you can manually preview any file by clicking the eye icon next to its filename. Once you’re done with the selection, click on Recover.
- Pick a recovery destination for the files and click Next.
- Disk Drill will recover the selected files.
How to Avoid Losing Data Using Robocopy
Avoiding data loss when due to robocopy is all about using the correct parameters for your specific requirements. If you want to use robocopy /mir without deleting any files, ensure that the destination folder doesn’t contain any files that you need. It’s best to leave the directory empty.
The syntax for a robocopy command is as follows:
robocopy <source> <destination> [<file>[ ...]] [<parameters>]
Here are some robocopy parameters to use if you wish to copy files from one destination to another without losing any data:
Parameter | Description |
/xo | Exclude older files, i.e., if the destination file already exists, don’t overwrite it if it’s newer or the same date as the source. |
/xx | Exclude extra files and directories. This prevents deletion from the destination directory. |
/xc | Exclude changed files. |
/xn | Exclude newer files. |
/e | Copy all subfolders, including the ones that are empty. This won’t affect the existing files in the destination directory. |
An example would be robocopy C:\folder to move D:\Sample /MT:32 /XO which will move a folder called “folder to move” from the C: drive to a folder called “Sample” in the D: drive. It will use 32-thread multithreading (/MT:32) for faster speed and will exclude older files (/XO).
Conclusion
The flexibility and sheer customizability of the robocopy utility can be a double-edged sword because the various parameters can often be confusing to understand. If you’re not careful and don’t understand the /mir parameter, using it can result in files being deleted from the destination folder. Luckily, you can get them back using a good data recovery tool. To avoid data loss due to robocopy in the future, remember to use more appropriate parameters.