How to use Robocopy to back up all your data in Windows 10: Commands and examples
Windows 10 offers a plethora of ways to back up and restore your data-and even your entire system. For example, there's File History, System Restore, Fresh Start, and System Image Recovery just to name a few.
If you're conscientious about the safety of your data, chances are good that you are already using one or more of Windows 10's backup tools. However, you may want to have an additional copy of your data files just to be on the safe side. While you can easily do so by copying your files and folders to an external hard drive via drag and drop, that can be a tedious operation.
Fortunately, Robocopy provides more than 80 command-line parameters and switches (Table A) that will allow you to create a powerful data backup operation.
To help you get a leg up, I delved into Robocopy's command-line switches and developed a nice little script you can use to create an exact mirror duplicate of all the data files in your user profile folder (C:\Users\YourName). Let's take a closer look.
SEE: 20 pro tips to make Windows 10 work the way you want (free PDF) (TechRepublic)
How to construct the command line in Robocopy
The basic command line syntax for Robocopy is similar to the syntax used for the familiar Xcopy command line application popular in DOS, so many years ago. The basic Robocopy command line will follow this general pattern:
Table A: A sample of Robocopy command line copy options
Source: Microsoft Docs
For my example, I'm going to back up the data file contents of my user profile folder, C:\Users\Greg Shultz, to a folder named TheBackup on an external hard disk, which is assigned drive letter F. (You'll of course substitute the names and paths with your own.) My basic command begins with:
Now, I want to back up every folder in the source, even any empty folders, as they may be placeholders for future data. I also don't want to have files on the backup that I deleted from my hard disk. While I could use the /S and /PURGE switches to accomplish my goal, the /MIR switch lets me accomplish both tasks with one switch. My command is now:
The C:\Users\Greg Shultz folder contains several hidden system files and folders I don't want or need to back up under my Robocopy operation-they are picked up by the other backup tools. For example, I don't need to back up the NTUSER.DAT file, nor do I need to back up the contents of the AppData folder. In addition, the C:\Users\Greg Shultz folder contains a host of junction points I don't need to back up. Windows 10 uses junction points to link various operating system folders to the user profile folder. For example, the Cookies folder and the SendTo folder are linked to the user profile folder via junction points.
I'll use the /XA:SH switch to exclude the hidden system files, and I can use /XD AppData to exclude the entire AppData folder. I'll then use the /XJD switch to exclude all the junction points. My command is now:
One of Robocopy's most handy features comes into play when it encounters a file that is in use. When it does, Robocopy will stop and wait for that file to be closed so that it can continue with the copy operation. It will retry to copy the file every 30 seconds. The default number of retries is 1 million (no joke!). As this will most likely prevent the backup operation from ever completing, you should reset it to a reasonable number.
To change the number of retries, you'll use the /R switch. To change the wait time between retries, you'll use the /W switch. I chose five retries with a 15-second wait time. That way, after a reasonable number of retries and wait period, Robocopy will move on. My command is now:
At this point, I am ready to add the multi-threaded switch, which enables Robocopy to perform a multi-threaded copy option. More specifically, with multi-threaded capabilities, Robocopy can simultaneously copy multiple files in parallel, which will result in very fast backup operations.
The multi-threaded switch is: /MT[:n], where n is a number from 1 to 128 and indicates the number of threads to be used. Keep in mind that n is optional and that by default, the /MT switch will use eight threads. I'm using 32 threads in my example, as I found it to be a good starting point. My command is now:
Like all command-line tools, Robocopy keeps you apprised of the status of operation right in the Command Prompt window. However, you'll probably want to customize and record that feedback in a log file. I like to have the whole picture, so I'll use the /V switch. However, I really don't need to know the percentage progress of each file copy, so I'll also use the /NP switch. Then to create my log file, I'll use the /LOG switch, which will overwrite the existing log file each time. Now, my command is:
SEE: Windows 10 power tips: Secret shortcuts to your favorite settings (TechRepublic Premium)
How to create and use your script
Now that you know how the script works and which switches are necessary, you can launch Notepad, type the command, and save the file as RobocopyBackup.cmd. To make sure that the script and open log file don't interfere with the backup, I created a folder in the root directory called BackupTool (C:\BackupTool) and saved the script there.
You'll find the log file in the same directory as the script after each backup operation. Keep in mind that while the log file is a simple text file, it can be larger than Notepad can handle. As such, you may want to use Wordpad or another word processor to open and view the log file.
Now, whenever you want to make an extra backup, you can just double-click on RobocopyBackup.cmd to launch it. When it is done, you can examine the Backup.log file. You can also use the Task Scheduler to automatically run your RobocopyBackup.cmd on a regular basis if you want.
What's your take?
Have you used Robocopy in Windows 10? If so, what's been your experience? Would you add any additional switches to the script I presented in this article? Share your thoughts with fellow TechRepublic members.
Editor's note: This article written by Greg Shultz was first published on July 27, 2017. The most recent update written by Mark Kaelin was published on Aug. 14, 2019.