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.