Should you’re searching for a bit further peace of thoughts, double down in your knowledge backups. This straightforward Robocopy script leverages just a few helpful switches to make the duty handy and environment friendly.
Picture: Olivier Le Moal, Getty Pictures/iStockphoto
Home windows 10 provides a plethora of the way to again up and restore your knowledge—and even your complete system. For instance, there’s File Historical past, System Restore, Recent Begin, and System Picture Restoration simply to call just a few.
Should you’re conscientious in regards to the security of your knowledge, chances are high good that you’re already utilizing a number of of Home windows 10’s backup instruments. Nevertheless, you might wish to have an extra copy of your knowledge recordsdata simply to be on the protected aspect. Whilst you can simply accomplish that by copying your recordsdata and folders to an exterior arduous drive through drag and drop, that may be a tedious operation.
Luckily, Robocopy gives greater than 80 command-line parameters and switches (Desk A) that may let you create a strong knowledge backup operation.
That can assist you get a leg up, I delved into Robocopy’s command-line switches and developed a pleasant little script you should use to create a precise mirror duplicate of all the information recordsdata in your consumer profile folder (C:UsersYourName). Let’s take a better look.
SEE: 20 professional tricks to make Home windows 10 work the way in which you need (free PDF) (TechRepublic)
The way to assemble the command line in Robocopy
The essential command line syntax for Robocopy is just like the syntax used for the acquainted Xcopy command line utility widespread in DOS, so a few years in the past. The essential Robocopy command line will comply with this common sample:
robocopy [[ …]] 
Desk A: A pattern of Robocopy command line copy choices
Copies subdirectories. Notice that this feature excludes empty directories.
Copies subdirectories. Notice that this feature consists of empty directories.
Copies recordsdata in Backup mode.
Copies all encrypted recordsdata in EFS RAW mode.
Specifies the file properties to be copied. The next are the legitimate values for this feature:
· D Knowledge
· A Attributes
· T Time stamps
· S NTFS entry management checklist (ACL)
· Proprietor data
· U Auditing data
The default worth for CopyFlags is DAT (knowledge, attributes, and time stamps).
Deletes vacation spot recordsdata and directories that now not exist within the supply.
Strikes recordsdata and deletes them from the supply after they’re copied.
Supply: Microsoft Docs
For my instance, I’ll again up the information file contents of my consumer profile folder, C:UsersGreg Shultz, to a folder named TheBackup on an exterior arduous disk, which is assigned drive letter F. (You may in fact substitute the names and paths with your personal.) My fundamental command begins with:
Robocopy “C:UsersGreg Shultz” “F:TheBackup”
Now, I wish to again up each folder within the supply, even any empty folders, as they could be placeholders for future knowledge. I additionally do not wish to have recordsdata on the backup that I deleted from my arduous disk. Whereas I might use the /S and /PURGE switches to perform my purpose, the /MIR swap lets me accomplish each duties with one swap. My command is now:
Robocopy “C:UsersGreg Shultz” “F:TheBackup” /MIR
The C:UsersGreg Shultz folder accommodates a number of hidden system recordsdata and folders I do not need or must again up underneath my Robocopy operation—they’re picked up by the opposite backup instruments. For instance, I need not again up the NTUSER.DAT file, nor do I must again up the contents of the AppData folder. As well as, the C:UsersGreg Shultz folder accommodates a number of junction factors I need not again up. Home windows 10 makes use of junction factors to hyperlink numerous working system folders to the consumer profile folder. For instance, the Cookies folder and the SendTo folder are linked to the consumer profile folder through junction factors.
I am going to use the /XA:SH swap to exclude the hidden system recordsdata, and I can use /XD AppData to exclude the whole AppData folder. I am going to then use the /XJD swap to exclude all of the junction factors. My command is now:
Robocopy “C:UsersGreg Shultz” “F:TheBackup” /MIR /XA:SH /XD AppData /XJD
Certainly one of Robocopy’s most helpful options comes into play when it encounters a file that’s in use. When it does, Robocopy will cease and watch for that file to be closed in order that it will possibly proceed with the copy operation. It’s going to retry to repeat the file each 30 seconds. The default variety of retries is 1 million (no joke!). As it will more than likely forestall the backup operation from ever finishing, you need to reset it to an inexpensive quantity.
To alter the variety of retries, you may use the /R swap. To alter the wait time between retries, you may use the /W swap. I selected 5 retries with a 15-second wait time. That means, after an inexpensive variety of retries and wait interval, Robocopy will transfer on. My command is now:
Robocopy “C:UsersGreg Shultz” “F:TheBackup” /MIR /XA:SH /XD AppData /XJD /R:5 /W:15
At this level, I’m prepared so as to add the multi-threaded swap, which allows Robocopy to carry out a multi-threaded copy choice. Extra particularly, with multi-threaded capabilities, Robocopy can concurrently copy a number of recordsdata in parallel, which is able to lead to very quick backup operations.
The multi-threaded swap is: /MT[:n], the place n is a quantity from 1 to 128 and signifies the variety of threads for use. Remember the fact that n is non-compulsory and that by default, the /MT swap will use eight threads. I am utilizing 32 threads in my instance, as I discovered it to be a very good place to begin. My command is now:
Robocopy “C:UsersGreg Shultz” “F:TheBackup” /MIR /XA:SH /XD AppData /XJD /R:5 /W:15 /MT:32
Like all command-line instruments, Robocopy retains you apprised of the standing of operation proper within the Command Immediate window. Nevertheless, you may most likely wish to customise and report that suggestions in a log file. I prefer to have the entire image, so I am going to use the /V swap. Nevertheless, I actually need not know the proportion progress of every file copy, so I am going to additionally use the /NP swap. Then to create my log file, I am going to use the /LOG swap, which is able to overwrite the prevailing log file every time. Now, my command is:
Robocopy “C:UsersGreg Shultz” “F:TheBackup” /MIR /XA:SH /XD AppData /XJD /R:5 /W:15 /MT:32 /V /NP /LOG:Backup.log
SEE: Home windows 10 energy ideas: Secret shortcuts to your favourite settings (TechRepublic Premium)
The way to create and use your script
Now that you understand how the script works and which switches are crucial, you’ll be able to launch Notepad, kind the command, and save the file as RobocopyBackup.cmd. To ensure that the script and open log file do not intrude with the backup, I created a folder within the root listing known as BackupTool (C:BackupTool) and saved the script there.
You may discover the log file in the identical listing because the script after every backup operation. Remember the fact that whereas the log file is a straightforward textual content file, it may be bigger than Notepad can deal with. As such, you might wish to use Wordpad or one other phrase processor to open and look at the log file.
Now, everytime you wish to make an additional backup, you’ll be able to simply double-click on RobocopyBackup.cmd to launch it. When it’s performed, you’ll be able to study the Backup.log file. It’s also possible to use the Job Scheduler to mechanically run your RobocopyBackup.cmd regularly if you would like.
Microsoft Weekly Publication
Be your organization’s Microsoft insider with the assistance of those Home windows and Workplace tutorials and our specialists’ analyses of Microsoft’s enterprise merchandise.
Delivered Mondays and Wednesdays
Join in the present day
Join in the present day
What’s your take?
Have you ever used Robocopy in Home windows 10? In that case, what’s been your expertise? Would you add any extra switches to the script I introduced on this article? Share your ideas with fellow TechRepublic members.
Editor’s notice: This text written by Greg Shultz was first revealed on July 27, 2017. The newest replace written by Mark Kaelin was revealed on Aug. 14, 2019.