Robocopy – Windows Rsync

Well the title is not 100% true but its almost. In a previous post I wrote a script using rsync to synchronise your home folder to an external hard drive. This command I am going to go through today does something similar.

The command I am going to be talking about is robocopy. Robocopy is a very close cousin of rsync but only runs on Windows.

Since I switch between my Win10 and Linux Mint (My video editing software seems to be more stable on Win10 than Linux Mint, more on that in a future post) I wanted something that when I need to back up I just double click and off it goes.

I was looking for some software to do this but after a while I couldn’t find any that didn’t cost over £10 so I though why not see if a Batch file can do the job.

A Batch file is basically a set of Command Prompt (think MS DOS) commands that you can run together in one file.

So my criteria was a sync file function with a log of if anything went wrong and a summary in a text file that I can check every so often, and also for it to overwrite that log file when I start a new job. I didn’t want any prompts popping up, for when I click the batch file to finish I do not want to do anything.


The first command I was looking at was xcopy. xcopy is a bit like the copy command but also copies sub directories as well as the main directory. Unfortunately this command copies all the data all the time and if you delete a file from the source directory it doesn’t sync that deletion from the backup directory. So my next point of call is robocopy.


Robocopy, or Robust File Copy for Windows, is a command that lies in the c:\windows\system32 directory. This is a powerful command that can cause havoc if not used right.

First thing I did was look at the help file for the options. You can see this by at a command prompt type:-

c:\windows\system32\robocopy /?

So looking through the options these are the ones I wanted to use :-

  1. MIR – Mirror or sync the files
  2. E – copy sub directores, even empty ones
  3. log – write results to a log or text file
  4. log+ – append the above log or text file
  5. NFL – No File List – don’t log file names.
  6. NDL – No Directory List – don’t log directory names.
  7. TEE – Output to console window, as well as the log file.

The reason why the options “log” and “log+” are there is I am backing up my NAS, but I don’t need to back it all up, just some of it. So I will be running multiple copies of the command pointing to different directories, the first command will use the “log” command and the rest will use the “log+” command.

So the full command is as follows (this is for the first one in the series)

C:\windows\system32\robocopy "source" "Destination" /E /MIR log:"destination drive letter:\backuplog.txt" /NFL /NDL /TEE

The Final Script

Below is the final script.

REM Backup Script By John Herdman
REM Free to copy and use
REM ***** Music *****
C:\windows\system32\robocopy w:\ E:\Music\ /E /MIR /log:"e:\backuplog.txt" /NFL /NDL /TEE
REM ***** Software *****
C:\windows\system32\robocopy u:\ E:\Software\ /E /MIR /log+:"e:\backuplog.txt" /NFL /NDL /TEE
REM ***** House TV Series *****
C:\windows\system32\robocopy t:\tv\house\ E:\House /E /MIR /log+:"e:\backuplog.txt" /NFL /NDL /TEE
REM ***** Office Stuff *****
C:\windows\system32\robocopy y:\Office\ e:\office /E /MIR /log+:"e:\backuplog.txt" /NFL /NDL /TEE
REM ***** Photos *****
C:\windows\system32\robocopy x:\ E:\Photos /E /MIR /log+:"e:\backuplog.txt" /NFL /NDL /TEE
REM ***** Personal Videos *****
C:\windows\system32\robocopy v:\Personal\ e:\YouTube /E /MIR /log+:"e:\backuplog.txt" /NFL /NDL /TEE
notepad e:\backuplog.txt

The first command clears the screen. Then the last 2 commands opens the log file into notepad then exits the batch file when you close notepad so you don’t have to close 2 things at the end.

This is what a selection of the log looks like, this was a test run to see if it copied all the data again or not. It didn’t as you can see.

ROBOCOPY :: Robust File Copy for Windows

Started : 19 November 2017 01:00:57
Source : w:\
Dest : E:\Music\

Files : *.*

Options : *.* /NDL /NFL /TEE /S /E /DCOPY:DA /COPY:DAT /PURGE /MIR /R:1000000 /W:30



Total Copied Skipped Mismatch FAILED Extras
Dirs : 408 0 408 0 0 0
Files : 4517 0 4517 0 0 0
Bytes : 30.272 g 0 30.272 g 0 0 0
Times : 0:00:02 0:00:00 0:00:00 0:00:02
Ended : 19 November 2017 01:00:59

As you can see, the log is very simple to understand and every time I run the batch file, it overwrites the old log with the new one.

So I have done it, saved myself £30 on something like Acronis True Image 2018 though of course that program can do a lot more than just sync a folder, that is all I wanted, for about 1/2 hours research and testing.

The initial backup took quite a wile (as its backing all the data up for the first time) but now when I click on the batch file it takes less than 30 seconds to complete, depending on if I have changed any data in the directories robocopy is looking at of course.

Hope you find this useful.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s