I have written previously on the use of xcopy for Windows file management including simple backups. Robocopy or “Robust Copy” can be used for many of the same things with some notable additions.
One of these additions is the ability to mirror a directory. The mirroring is only a one-way process but there are certainly use cases for such functionality.
It’s simple to use. The example below mirrors the source directory, e:\documents, to the target directory, f:\documents. The /mir switch tells the command to mirror the directory while the /z option allows the process to be restartable. With the /z option, the process will restart where it left off should an error occur. By default, it will restart the operation a million times with a wait time of 30 seconds between each restart (or retry). You can change that behaviour, as I have done below, with the /r (retries) and /w (wait time, in seconds) switches.
robocopy e:\documents f:\documents /mir /z /r:3 /w:10
As this is a mirror operation, files in the target directory that are not in the source directory will be removed.
If you are a little nervous about running your command, add a /l switch (just like xcopy). Your command will then produce a listing of what your command would do, without actually doing it. Handy, for sure.
You can also prevent robocopy from copying or mirroring hidden files through the use of an exclusion switch (/xa:H).
Check out the many references on robocopy to see where it might be useful in your environment. As always, Google is your friend.
From Microsoft:
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy
Leave a comment