Robocopy Error 5

Hello,

I do apologizes if I post this in the wrong section or if this question has already been answer.  I try searching but I can't fix anything that fixes my problem.

I am using robocopy to copy a network copy to a folder. 

robocopy J:\ \\ca-fileserver\Backup\ca-datsrv05\ /MIR /m /COPYALL /ZB /ETA /R:2 /W:2 /NP /FFT

When this started, robocopy gets me an error 5:  access denied.

The command runs as an administrator at both locations.   I can manuelly cut and paste the files and get no error messages.   It there something I am doing wrong?

 

July 11th, 2011 1:08am

When you say the command runs as an administrator at both locations, do you mean you are logged on with an account that has administrative rights AND you are running the robocopy command from an elevated command prompt (unless this is on XP or 2003 then elevation wouldn't apply)?

You are using /MIR which will delete files in the destination that do not exist on the source. If something has a handle open to one of those files that it is trying to delete in the destination folder, that would explain an access is denied. You could run the Sysinternals tool "Handle <fileName>" to find what has an open handle to the file.

And then ultimately you want to find the simplest command that reproduces the issue. So do you get access is denied when you run robocopy with that source and destination but no switches? If so, keep trying it as you add each switch back one by one until you find which switch allows you to reproduce the issue again.

Free Windows Admin Tool Kit Click here and download it now
July 11th, 2011 2:14am

Hello,

Thank you for the reply.   The command runs as an domain admin at both locations.   I am copying data from one Server 2003 to another Server 2003.  If I can copy and paste the files from one server to another, I get no error messages.  If I use robocopy, I get error5: access denied.  I would like to use /MIR as I want to mirror the data.  I try command without any switches or try different switches.  I still get the same error message. 

 

Thanks,

July 11th, 2011 12:33pm

Try this resolution. It might help you.

 

Thanks

Free Windows Admin Tool Kit Click here and download it now
July 11th, 2011 12:59pm

Thank you for your help,  I figured it out.

 

It was a file permission issue.  Stupid me did not think about Share permissions. I was looking the NTFS permissions.  

 

Everything is working great. 


July 11th, 2011 2:26pm

Thanks for your feedback.

Free Windows Admin Tool Kit Click here and download it now
July 11th, 2011 2:53pm

So what was the issue ?

and how did you fixed that ?

July 3rd, 2014 2:23pm

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)

}

Free Windows Admin Tool Kit Click here and download it now
September 22nd, 2014 4:28pm

Naik,

So in what format do I have to type the "YOUR ID" ?

September 25th, 2014 2:19am

The "YOURID" comment in my post is for the ID you want to assign the rights to.  So if you were running robocopy and got access denied errors, you'd want to assign rights to the user that you are doing robocopy as so he can copy and will not get access denied error.

If it is domain, you would do domain\user format.

Have fun!

Free Windows Admin Tool Kit Click here and download it now
November 3rd, 2014 7:50pm

This drive me crazy..

and after I see ntfs datastreams on the non backed up files

the solution is:

download streams.exe

https://technet.microsoft.com/en-us/sysinternals/bb897440.aspx

and run recursevely on your directory (the backup source)

streams.exe -s -d C:\directorytobackup


June 27th, 2015 4:19am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics