A few weeks ago I wrote about using XCopy to copy files and folder structures including their NTFS Permissions. Recently I came to the point where I wanted to see all errors and their related files, so I could fix messed up NTFS permissions. With XCopy however parsing the log is pretty much impossible. Also Microsoft suggests using RoboCopy as a sucessor to XCopy. And thats what I did.

Using RoboCopy like XCopy

In my other blog post I meantioned that I wanted to copy all folders and files including their NTFS permissions and ignore errors on the way. You can do the same thing with RoboCopy… and it is a lot faster.

To achieve the same result you can use the following command to keep directories in sync.

ROBOCOPY S:\Source_Dir D:\Destination_Dir /MIR /SECFIX /COPYALL /R:0 /W:0 /LOG:"C:\Logs\example_$(get-date -f "yyyy-MM-dd_hh-mm-ss").log" /TEE

Okay let’s go over the switches line by line.

/MIR – Mirrors the source to the destination dir copying all files and folders, including empty ones.
/SECFIX – Fixes security permissions on already copied files (you can leave this out if you want)
/COPYALL – Copies all files attributes including NTFS permissions.
/R:0 – Number of times to retry copying a failed file.
/W:0 – Wait time between retries. Defaults to 30 seconds.
/LOG:file – Logs output into the givenfile.
/TEE – Logs output to console and logfile.

You can always see a full list of switches with /?.system

Parsing RoboCopy error log

With RoboCopy we now get parseable log files and can use this nifty script from the Technet Gallery to extract all failed files from the logs.



chad · 6. March 2019 at 19:52

First, great post! Quick question though. With the logging string. I did a copy and paste, changed the path but left the syntax in place. However the logfile that is being created doesn’t have the variables included. It’s just creating a file that is exactly as the line shows. Example, the logfile output is example_$(get-date -f “yyyy-MM-dd_hh-mm-ss”).log. I am running it in powershell, which I was only at a DOS prompt before. Not sure what I am doing wrong

Michael · 16. March 2019 at 11:06

Do you have your path in quotes?
The $(…) syntax only works inside double quotes:

/LOG:”C:\Logs\example_$(get-date -f “yyyy-MM-dd_hh-mm-ss”).log” should work.

/LOG:’C:\Logs\example_$(get-date -f “yyyy-MM-dd_hh-mm-ss”).log’ doesn’t work.
/LOG:C:\Logs\example_$(get-date -f “yyyy-MM-dd_hh-mm-ss”).log doesn’t work.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: