Mirror Files on Windows using Robocopy

Posted: 2013-08-28. Updated: 2013-08-28.


Robocopy is a command line robust copy utility that comes pre-installed with various Windows versions. It is well suited to mirror a large set of files between two external hard disks for example.

This is just a short cheat sheet to help remember its configuration options.

$ robocopy $source $target /MIR /MT /R:3 /W:5 /DCOPY:T /LOG+:$log_file /TEE

Attention: $source and $target must be capital drive letters!

We set the number of retries (/R) and the time to wait between them (/W) to some sensible numbers to speed up the copying process of unimportant and inaccessible files (the trash bin for example).
We also request multi-threaded operation by setting /MT.

Target Directory Empty Problem

It sometimes happens that if you copy a whole file system down from its root into another directory, that the $target directory looks empty when viewed in Windows explorer, even though robocopy states that all was copied correctly. I do not know if this is a bug, or feature, but robocopy sets the system and hidden bit on it. And normally systems files are not displayed in the explorer.

The solution is to simply remove the system (S) and hidden (H) flags from the $target directory.

You can list all files with:
$ dir /A
Or list only the files that have the system bit set:
$ dir /A:S
And finally remove both bits from the $target directory:
$ attrib -S -H $target

Back to writings.