locked
Robocopy Error 5 RRS feed

  • Question

  • 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?

     

    Monday, July 11, 2011 1:08 AM

Answers

  • 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. 


    Monday, July 11, 2011 2:26 PM

All replies

  • 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.

    Monday, July 11, 2011 2:14 AM
  • 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,

    Monday, July 11, 2011 12:33 PM
  • Try this resolution. It might help you.

     

    Thanks

    Monday, July 11, 2011 12:59 PM
  • 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. 


    Monday, July 11, 2011 2:26 PM
  • Thanks for your feedback.

    Monday, July 11, 2011 2:53 PM
  • So what was the issue ?

    and how did you fixed that ?


    /* Server Support Specialist */

    Thursday, July 3, 2014 2:23 PM
  • 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)

    }

    Monday, September 22, 2014 4:28 PM
  • Naik,

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


    /* Server Support Specialist */

    Thursday, September 25, 2014 2:19 AM
  • 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!

    Monday, November 3, 2014 7:50 PM
  • 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


    Saturday, June 27, 2015 8:12 AM
  • What did you figure out?  I know this strand is old but could you share an example?

    Tuesday, April 5, 2016 5:52 PM
  • In my case the access denied error was caused by the "Share" permissions on the destination directory. Once I gave Everyone full control it zipped right along.
    Wednesday, April 27, 2016 10:04 PM
  • Try to run cmd not 'as admin'. 
    Friday, March 3, 2017 5:45 PM
  • Two things, check NAS permissions and REBOOT the machine, pal.

    I met with a similar problem with my NAS last week. I was able to copy-paste all files and folders to-and-fro without any problem using the GUI, but powershell, CMD as well as Robocopy, they all failed for no reason. All of them were working an hour ago without any issue. I rebooted NAS device twice, also disconnected, reconnected and remapped network drive without help. I had a large number of files open on my computer so didn't want to restart it, but eventually had to do it. All problems solved after a Reboot of my machine. 


    Sandeep Verma

    Sunday, December 24, 2017 1:11 PM
  • typical tech nerd response.

    Not everyone has your "level/knowledge" of "scripts" so it might help if you provided a sample script

    in one piece instead of the techno-babble you typed here.

    Try and keep it simple please.

    As for Robocopy....everyone talking about rights, permissions etc.  I'm not buying that.

    I have the same issue trying to copy files using Robocopy from a removable hard drive to a Netgear NAS drive

    and robocopy throws a fit everytime spouting error 5.  permission denied.

    If that was actually the case then explain to me why I can preform the same copy, on the same PC, using just windows 7 file manager/explorer with out any issues.

    Anyone??????

    Regards

    Jerry

    Saturday, March 17, 2018 8:49 AM
  • Literally all you have to do is read the comments. It tells you exactly what the script is doing.

    # 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)
    }
    Tuesday, March 12, 2019 8:50 AM