if it is not simple issue like you mentioned, you can also write a script to fix this automatically
# To run robocopy with logging which logs errors
robocopy source dest /MIR /NP /TEE /R:0 /W:1 /FFT /LOG+:log.txt
# get errors from log and use set-content so it only writes if there are errors.
get-content log.txt | select-string "0x00000005" | set-content errors.log
#if statements to check if it even had errors. only if errors go in to if statement.
if (test-path errors.log) {
#now capture the paths exactly. Get-unique so it writes one error only once. Will assume you using UNCs to #copy vs. drive letters, please modify as necessary
select-string -path errors.log -pattern "\\.*$" | %{ $_.Matches[0].captures[0].value} | get-unique > paths.log
#just do foreach loop for each path.
foreach ($path in $paths) {
#use subinacl to take ownership and assign permissions, it is better and faster than icacls and ps ways but #you can use whatever works. Report the chnges you made. if '$path' is a folder then you will need to #modify subinacl command to inherit etc. look
it up.
.\subinacl /file "$path" /setowner="YOUR ID" >> change-perms.log
.\subinacl "$path" /grant="your ID"=F >> change-perms.log
}
#run your robocopy command again to copy missed file in previous step.
robocopy source dest /MIR /NP /TEE /R:0 /W:1 /FFT /LOG+:log.txt
#Delete the error log file so it does not go in to if loop next time you run.
remove-item error.log (use force, erroraction etc as necessary)
}
-
Proposed as answer by
Senior System Engineer
Thursday, September 25, 2014 2:18 AM