Robocopy is a fantastic piece of software, there is only one major flaw. Which again also is the strength of it. It is a command line tool.
Command line tools seems to be hot again, and I really really hated them for a long period of time. But, I have come to love them again (?), even if it seems a super outdated technology in the age of the smartphone.
I must admit that Robocopy really does a more than a great job and I love it. And then it’s free – I love free software too.
Robocopy has always had an answer for a problem. Some guys at Microsoft made a graphical user interface for Robocopy, but it doesn’t give me the flexibility that I need. But if you feel like, you can have a look at them. The link is provided in the bottom of this article. In the end, they use the same command line tool.
Instead of spending a lot of time figuring out the syntax parameters you can use my commands.
Personally, I use Robocopy to take local backups. I use Robocopy in combination with online backup. I centralize a backup, from the various storage locations I have (NAS, data drives, system drive) and that backup I include in my Livedrive backup plan.
Anyway, one of the primary reasons for using Robocopy, rather than many other free backup products out there, is that it does a mirror backup. This means that it will make anything from the source directory to be reflected exactly the same way in the destination directory.
Just be sure that you do not get the source and destination the wrong way around. Robocopy can delete all your files extremely fast, if you mix up source and destination.
If you feel that your hand is shaking, start practicing with test directories. A mirror backup with the source and destination the wrong way around will erase your data faster, than you can spell ‘Oh Nooooo!’. This is not specific for Robocopy, it’s the nature (and point!) of a mirror copy tool. Do not switch source and destination!
The backup strategy
This is a basic backup strategy that you can modify for your exact needs. The plan is this:
- Copy all necessary data from desktop computer to an external hard drive
- Copy all user settings from Windows to an external hard drive
- Copy all necessary data from a NAS to an external hard drive.
Command for step 1:
robocopy C:\Data T:\DesktopPC\C-Drive /MIR /XA:H /W:0 /R:1 /REG > C:\externalbackup.log
And the parameters explained for the nerds:
|C:\Data||Is the source directory. I always store data that I backup in a folder called Data. It makes backup easy, just as well as it makes migration to a new computer very easy.|
|T:\DesktopPC\C-Drive||Is the destination directory|
|/MIR||This tells robocopy to make a mirror backup.
NB! Another important detail and word of warning, is that when you make a Mirrored backup, if you delete something in the Source, it will also be deleted in the Destination, when the script runs. This is also true if you delete something by accident.
|/XA:H||Leave out the hidden files. If they are hidden they are in my terminology not important.|
|/W:0||Wait time between retries, the default is 30 seconds. If a file is locked, because it is in use, the robocopy can wait and retry. I don’t want the backup to wait, it should continue straight away, otherwise it can take too long. I’ll get the file backed up the next time.|
|/R:1||The number of retries, if the file is locked. I set the to 1, the default is 1.000.000. If you combine that with with the /W paramater and a default of 30 seconds, that is potentially 30.000.000 seconds pr file permanently locked. The backup will never finish if you just have one single file that is permanently locked.|
|/REG||This one saves new default values on /W and /R to the registry. In theory this means that I only need to use this parameter once, but I keep it around for when I restore Windows or get a new computer.|
|/XD||Exclude Directories. This one is used to exclude directories like c:\temp. I only use it with fully qualified paths to be sure what it excludes.|
|/XF||Exclude files. I use this to exclude certain file extensions, like *.lrprev|
|> C:\externalbackup.log||This will start a new log file. I like to be able to see what the backup did.|
Command for step 2:
robocopy C:\Users\Jacob T:\DesktopPC\C-Drive\Users\Jacob /MIR /XA:SH /W:0 /R:1 /REG /XJ >> C:\externalbackup.log
Add a line for each user using the computer. And the parameters explained for the nerds:
|C:\Users\Jacob||Is the source directory and the directory in which my windows user profile is located. It contains your documents folder, favorites etc. A great folder to include in the backup.|
|T:\DesktopPC\C-Drive\Users\Jacob||Is the destination directory|
|/MIR||This tells robocopy to make a mirror backup.|
|/XA:SH||Leave out the hidden files and the system files. The hidden files I don’t want and they are often part of the system and the system files and I don’t really need either in the backup. The system will generate them again, if it needs them. The S is important when you backup the user profile, because there’s a lot of system files.|
|/XJ||Exclude junction points. This is something funky in Windows. If you don’t include it, when you backup a user profile, it will run forever, because it enters an infinite loop. Just trust me in this one.|
|>> C:\externalbackup.log||Notice the change from “>” to “>>”. This means that it will continue on the log from before. I used ‘>”, it would delete the log and start all over.|
Command for step 3. Copy from the computer to the NAS, this one requires a special parameter, because the NAS is a LINUX based computer. In the beginning my backup kept copying files already backed up.
robocopy C:\Data\CDs \\NAS\Music\CDs /MIR /XA:H /W:0 /R:1 /REG /FFT >> C:\externalbackup.log
And the parameters explained for the nerds:
|C:\Data\CDs||Is the source directory and the directory. I use Sonos for playing music in the house and I copy my ripped CDs to the NAS for both backup and for Sonos.|
|\\NAS\Music\CDs||Is the destination directory. My Sonos music system points to this location.|
|/MIR||This tells robocopy to make a mirror backup.|
|/XA:H||Leave out the hidden files.|
|/W:0||Wait time between retries, the same as above.|
|/R:1||The number of retries, if the file is locked. Again the same as above.|
|/REG||This one saves new default values on /W and /R to the registry. Same as above, once more.|
|/FFT||This one is important when backing up to a NAS based on LINUX. I have two different brands and have hands on experience on a third, and they are all based on LINUX. If you leave out this parameter it will keep copying the files to you NAS, even though they are already present. This has to do with some timing issues – just trust me on this one.|
Make a .bat file using Notepad.
My personal backup script copies some stuff criss cross among my various locations. I have an external backup (well actually two, because one I store at my office and then swap them once every two weeks), two NAS (old and new one – I don’t trust the old one too much) and then my Desktop computer. I make sure that I have at least two copies of everything. But they all use the same commands as shown above, just with various source and destinations.
Set up the scheduling of the backup
I set up my backup at 7 pm, because that is likely that my computer is turned on by then. I don’t want to switch on my computer to get a backup.
Step 1: Find the control panel.
Step 2: Start the Schedule Tasks
Step 3: Create a new basic task
Step 4: Name the new task
Step 5: Select when to run the task
Step 6: Select what time to run the task.
Step 7: Select what to run – you want to run a program. A batch file is a program too.
Step 8: Find your backup batch file
Step 9: A summary – that looks just right.
Step 10: Done. The new task is in my scheduler.
And that’s it. You now have a high performance backup that cost you absolutely nothing!
Other useful parameters for Robocopy
Robocopy can be used for many great file operating tasks, not only mirror backup. Here’s a list of some of the useful copy, move or mirror parameters available for Robocopy. Just be sure only to use ONE of them at the same time, and always do a test on test data, before doing it on real data. Robocopy can delete data faster than anything if you do something the wrong way.
|/MOV||This tells robocopy to move files from the source to the destination. Moving files include deleting the files from the source. Be sure you want to delete the files before using this parameter.|
|/MOVE||This tells robocopy to move files and folders from the source to the destination. Notice the difference between the switches /MOV and /MOVE. Moving files include deleting the files from the source. Be sure you want to delete the files before using this parameter. Do not combine with the switch /E, else it will not work as intended.|
|/E||This tells robocopy to make a copy of all files recursively. This way robocopy will not clean up in the destination. Changed files at the source will be overwritten with new ones, new files will be added, but files deleted at the source will stay at the destination. For some this might be the right solution, for others it won’t.|
|/MIR||This tells robocopy to make a mirror backup. Files deleted at the source will also be deleted at the destination.|
|/PURGE||Will delete empty folders at destination. If you use /E /PURGE is effectively the same as /MIR.|
If you didn’t read my article on how to make your own backup strategy, you might like to read it here.
If you like to have a look at Microsofts own Graphical User Interfaces for Robocopy, you can read about them here.