Robocopy permission denied

11

3

Robocopy is preinstalled with Windows 7. I've used it many times in the past. I tried to copy a folder to a remote share with

robocopy c:\source "\\server\share\path" /s /r:2 /w:2` 

As a result I get permission denied. Using explorer I can copy files to this share. I've opened a command prompt with administrator permissions with the same result. The share is read/write for public.

EDIT I've successfully mapped a driveletter to the share, but robocopy still fails

EDIT I've added the /B switch without success. The exact error is:

2009/09/26 20:43:14 ERROR 5 (0x00000005) 
    Accessing Destination Directory \\drobo\Drobo\fotos\__NEW\Ericsson\

Edosoft

Posted 2009-08-19T11:04:50.937

Reputation: 750

If you use the /V parameter, does Verbose mode give you any other information? The error 5 is usually an access denied message. From a command prompt can you use the COPY command? Does this work with other UNCs or is the Drobo the only one that fails? If so, the Drobo people may be the best place to turn for answers. – Jeffery Hicks – 2009-11-09T20:20:49.073

Type 'net use' and press enter. Edit question with result please – Canadian Luke – 2011-11-21T02:50:14.577

Have your tried taking ownership of the shared folder? Are you on a workgroup or an Active directory domain? – CGA – 2009-08-24T11:36:14.780

I'm using a Workgroup. I did take ownership. – Edosoft – 2009-09-23T15:53:32.743

Have you tried mapping the shared folder to a drive letter? – CGA – 2009-08-19T19:09:21.860

Yes I tried that first. Same result – Edosoft – 2009-08-24T10:45:46.160

@CGA: Robocopy handles UNC paths just fine. – surfasb – 2011-11-21T04:59:56.773

Answers

12

Quoted from here :

In my case, I started out with full control on both the source and destination shares. The problem was that Robocopy was resetting the ACL on the destination share to a null value (nobody has permission) before it began recursing subdirectories. After some quick tests, my conclusion is that Robocopy does not handle inherited permissions. Say you are copying C:\Share1 to D:\, and C:\Share1 is inheriting its permissions from the C:\ root directory, it actually has no explicit ACL. Therefore, when you copy its ACL, you are actually copying... nothing. By copying an empty ACL to your destination your permissions are removed in the first step of the copy, and all subsequent writes to the share fail with Error 5.

This is only a problem when you are copying from a source which you are accessing WITH inherited permissions and a destination which you are accessing WITHOUT inherited permissions. If you copy C:\ (which has you explicitly in its ACL), to D:\, there is no issue. If this is indeed your problem, you can resolve it by adding yourself explicitly to the source ACL with full control. When the copy runs, your ACL entry is duplicated to the destination, and the subsequent file copies can be written. You can undo your changes (on both source and destination) after the copy completes.

If you continue to have problems despite the above, you might want to consider trying the /B switch, which attempts to back up the file using your privileges as a Backup Operator. This will allow you to copy files that you otherwise couldn't, for example, if you are not on the ACL on your destination share. Robocopy defaults to attempting a restartable copy. By giving up restartable copies the worst case is that you lose the file currently being transferred in the event of a disruption. The next pass will restart that file from its beginning instead of partway through.

Hope that helps. Here's a quote from Microsoft's Robocopy doc regarding the /B switch:

Quote:

If you copy NTFS security information (ACLs) along with file data, it is possible to copy files to which you have read access, but not write access. After such a file is copied once, and the ACLs are applied, you may find that to get an “Access Denied” error when you try to copy the file again. In this situation you should use the /B or /ZB switch to copy the files in Backup Mode.

/B copies all files with backup semantics (Backup Mode). /ZB first attempts to copy files in restartable mode (for greater resiliency) but if that fails with an “Access Denied” error it automatically retries the copy using Backup Mode.

harrymc

Posted 2009-08-19T11:04:50.937

Reputation: 306 093

5

Try copying files using the Backup flag :

/B : Copy files in Backup mode.

Andreas Grech

Posted 2009-08-19T11:04:50.937

Reputation: 3 522

What's the different with the /ZB command ? – Senior Systems Engineer – 2014-07-06T02:55:08.307

Thx, I'll try that. – Edosoft – 2009-09-23T15:54:11.337

2

In addition to previous answers I can extend with the fix that worked for me. In my case I had local folders and files were the ownership was claimed by another user on the system. I simply claimed the ownership of all folders and sub folders and everything worked fine without the backup switch.

Claim ownership of a folder and its sub folders: http://technet.microsoft.com/en-us/magazine/ff404240.aspx

Marcus

Posted 2009-08-19T11:04:50.937

Reputation: 121

So in this case, the folder must be claimed the ownership by the batch script user account ? – Senior Systems Engineer – 2014-07-06T02:55:59.397

1

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 into if statement.
if (test-path errors.log) {

    #now capture the paths exactly.  Get-unique so it writes one error only once. 
    #Will assume you're 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 changes 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)

}

N.Naik

Posted 2009-08-19T11:04:50.937

Reputation: 11

It's worth noting that this script is for use with Windows Powershell. – Kevin Fegan – 2016-01-08T17:08:52.480