- What is Robocopy?
It is basically a command line tool that is very efficient at copying and mirroring folders and directories. Robocopy offers a lot of useful and reliable features, like for example, the ability to copy file permissions and attributes over, resume where it left off after a disconnect, copy only new or changed files, and much more.
NOTE: For the purposes of this “How to” tutorial, I will stick with the basics needed to create a batch file that will run Win 10 Robocopy to perform a one-way sync of files between two devices on a scheduled basis.
- What will you need?
Robocopy C: \Desktop\robocopysource F: \robocopybackup
NOTE: Robocopy copies folders and files within those folders, not single files. Your files must be in a folder, your destination must be a folder also.
- What about syncing?
/mir Adding the /mir command copies all of the sources directory tree and everything in it, to the destination. This is essentially the /purge command used with /E.BE Careful: Because this is an exact mirror of the source copied to the destination,
any folders in the destination that are no longer in the source folder, will be
removed from the destination!
Robocopy C:\Desktop\robocopysource F:\robocopybackup /mir
/XX Excludes files and directories tagged as “extra”
- Here’s How it Works
- I am going to make a change in my source folder by adding another folder called “3rd folder“
Here you can see that it copied the one new folder named “3rd folder” and skipped
over the original 3, as no changes have been made to those, and a copy already
resides in the destination folder.
- Simple…open up Notepad by typing notepad into the search bar. This will open up notepad.
Type your code into the notepad, and save the file as a .bat file. This makes it an executable set of commands called a batch file.
Schedule the Robocopy
- You can schedule your Robocopy batch file to run using Windows Task Scheduler. Type task scheduler into the search bar. Hit enter.
- Click on Action on the top toolbar, and choose Simple Basic Task.
- Name your task in the box, then click next.
- Choose when you would like for your task to run, then click next.
- Now choose when you would like for your first task to start, and the time you would like it to run.
- Next you decide what it is you want the task to perform. Here we will choose start a program.
- Next is where you choose the program you would like the scheduler to start. This is going to be the batch file that you created. Browse to where you saved the batch file, select it, then hit next.
- Here you click Finish.
- Now lets make sure the program runs in elevated mode. Back at the main screen of the scheduler, browse through the Task scheduler library until you see the task you just created. Double click to open it. In this window, you want to check the box at the bottom that says, Run with highest privileges.
- Other Switch Commands:
Issue the robocopy /? command in the command line prompt to see a list of Robocopy commands.
There are many commands you can use depending on what it is you are trying to accomplish. I will name a few basic and most used commands here:
/mot:[# of minutes before running again] This monitors for changes and runs again when the elapsed time specified has been reached.
/E Copy ALL subdirectories (includes empty ones)
/S Copy subdirectories (excludes empty ones)
/Copy:DATS or /SEC Copies security information over
/PURGE Deletes all files and directories in destination that no longer exist in the source
/MIR Mirrors a whole directory tree in source…deletes files in destination that aren’t in source. Equal to /purge + /E
/W:[seconds] Specifies the amount of time between retries
(n.d.). Retrieved April 04, 2016, from http://burpee.smccme.edu/studenthowtos/robocopy.htm
Beginners Guides: Understanding and Creating Batch Files. (n.d.). Retrieved April 04, 2016, from http://www.pcstats.com/articleview.cfm?articleid=1767
Get to Know Robocopy for More Powerful File Management. (n.d.). Retrieved April 04, 2016, from https://technet.microsoft.com/en-us/magazine/ee851678.aspx
How To Write A Simple Batch (.bat) File. (n.d.). Retrieved April 04, 2016, from http://www.makeuseof.com/tag/write-simple-batch-bat-file/
How to schedule a Batch File to run automatically on Windows. (2011). Retrieved April 04, 2016, from http://www.thewindowsclub.com/how-to-schedule-batch-file-run-automatically-windows-7
Robocopy /MIR switch – mirroring file permissions. (n.d.). Retrieved April 04, 2016, from https://blogs.technet.microsoft.com/filecab/2008/07/31/robocopy-mir-switch-mirroring-file-permissions/
Robocopy.doc. (n.d.). Retrieved April 04, 2016, from http://theether.net/download/Microsoft/Utilities/robocopy.pdf
Robocopy: Can MIR or PURGE delete files from Source ? (n.d.). Retrieved April 04, 2016, from https://social.technet.microsoft.com/Forums/windows/ko-KR/93da73cf-5261-484f-9e81-f532747bf6b1/robocopy-can-mir-or-purge-delete-files-from-source-?forum=w7itproinstall
Schedule RoboCopy. (n.d.). Retrieved April 04, 2016, from https://social.technet.microsoft.com/Forums/windowsserver/en-US/a2647339-41e1-48ea-9bb2-71b9e51a5b29/schedule-robocopy?forum=winserverfiles
Two-way folder sync with robocopy. (n.d.). Retrieved April 04, 2016, from http://stackoverflow.com/questions/33022584/two-way-folder-sync-with-robocopy
Using robocopy with source and destination as variables. (n.d.). Retrieved April 04, 2016, from http://stackoverflow.com/questions/19956249/using-robocopy-with-source-and-destination-as-variables
Windows 7 help and support forum. (n.d.). Retrieved April 04, 2016, from http://www.sevenforums.com/tutorials/187346-robocopy-create-backup-script.html