Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Here's the situation. We have a file server set up at \fileserver\ that has a folder for every user at \fileserver\users\first.last

I'm running an xcopy command to backup the My Documents folder from their computer to their personal folder. The command I'm running is:

xcopy "C:\Users\%username%\My Documents\*" "\\fileserver\users\%username%\My Documents" /D /E /O /Y /I

I've been silently running this script at login without the users knowing, just so I can get it to work before telling them what it does. After I discovered it wasn't working, I manually ran the batch script that executes the xcopy command on one of their computers and get an access denied error. I then logged into a test account on my own computer and got the same error.

I checked all the permissions for the share and security and they're set to how I want them. I can manually browse to that folder and create new files. I can drag and drop items into the \fileserver\users\first.last location and it works great.

So I try something else to try and find the source of the access denied problem. I ran an xcopy command to copy the My Documents folder to a different location on the same machine and I still got the access denied error!

So xcopy seems to be denied access when it tries to copy the My Documents folder.

Any suggestions on how I can get this working? Anyone know the reason behind the access denied error?

share|improve this question
    
what OS is involved –  Jim B Nov 29 '10 at 16:42
    
The OS is Windows 7 –  Safado Nov 29 '10 at 18:46
    
Update - I found another command called robocopy and it's error messages were a little more verbose. They said I didn't have the "Backup and Restore Files" permission, so I added my test user to the local Backup Operators and the robocopy command ended up working. I then tried the xcopy to see if it was a similar issue and I'm still getting the access denied error. With the xcopy command, I'm using /D to make it only back up delta files (ala rsync... I'm a Unix guy stuck in a Windows world :) ) but I couldn't seem to find such option with robocopy. Anyone know how to do that? –  Safado Nov 29 '10 at 20:30
1  
@Ryan M.: I believe robocopy ignores files on the destination whose last-modified timestamps are the same as or later than those of the source files, unless you specifically tell it not to. –  Steven Monday Nov 29 '10 at 22:15
    
@Steven - Thanks for the heads up. If that's the case, then Robocopy sounds like my best solution. Now to add everyone to the Backup and Restore Files group through GPO.... –  Safado Nov 30 '10 at 15:24
show 1 more comment

7 Answers 7

the Documents and Settings was folder was giving me trouble. The ntuser.dat file is unaccessable when in use. So I added .dat on a new line in my "exclude.txt" file and it works for me. So xcopy c:*.xls i:\xlsfiles /e /c /y /exclude:exclude.txt
(exclude.txt is a file with...5 lines with folder match srings or filename match srings with cr lf)

share|improve this answer
    
ntuser.dat isn't within the documents folder, which is what the OP is asking about. –  Bryan Jun 5 '13 at 7:11
add comment
up vote 0 down vote accepted

The answer is a combination of several answers that were given and here it is.

In the copy command it needs to be Documents and not My Documents.

Using the /O argument was killing it. I'm suspecting the issue is as Simon explained in that users don't have the rights to modify the ACLs on the target.

Changing those two items made the command work.

share|improve this answer
add comment

Let's break it down.

You want to copy the My Documents folder and all its contents to some location. Groovy.

Folder Redirection (/Offline Files) via Group Policy isn't how you're going about it, though. Fair enough; it's not for everyone.

But there are a ton of assumptions built into your script, and there's probably easier ways of doing it.

Instead, you could:

Xcopy /S /Y "%USERPROFILE%\Documents" "\\server\%username%\Documents"

On my really-very-vanilla install, trying that just worked for me.

There are other variables that might be useful too.

Next up: when's the script running? If it's logon, it should run as the user, but you might find sharing violations if anything's also being opened or used at the time.

Finally, you should be able to run that command without requiring SeBackupPrivilege; that sounds like you don't have the permissions you think you have for that account.

Oh, and when running in a logon script or at startup, you might find yourself "boxed", which reduces your effective permissions and speed.

share|improve this answer
    
So I tried the arguments that you used (/S /Y) and it worked. So I reviewed the arguments I was using and my problem was coming from the /O option, which says it will copy ownership and ACL information.. which in my case isn't needed because the files will inherit permissions from the %username% folder. The odd part is that I tried removing the O (see Simon Catlin's answer and my response) and it didn't work previously. But now it does. Now I have to decide whether to get rid of the robocopy script that's been running for over a year and use xcopy or not. –  Safado Jan 13 '12 at 14:59
add comment

Try running xcopy from an elevated command prompt. i.e. Right Click > Run as Administrator.

share|improve this answer
add comment

For one thing, maybe it's because of the superfluous '\*' in the first xcopy argument.

Again, using Documents might help, because 'My Documents' is just a junction point to 'Documents', only for backward compatibility with some limitations, e.g. you can't dir in it.

share|improve this answer
add comment

I suspect it's the /O - the users probably don't have the rights to modify the NTFS ACLs on the target.

share|improve this answer
    
Even without the /O I get the same Access Denied error –  Safado Nov 29 '10 at 20:26
add comment

Try Documents instead of My Documents in your path.

share|improve this answer
    
Thanks. I tried "Documents" instead and I got the same Access Denied error. –  Safado Nov 29 '10 at 18:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.