xcopy and retain permissions

Hi all,

got to copy shared user data from one server to another. I'm looking for a xcopy script that copies all folders and contained files and retains the permissions from the source and looks at the file being copied and only copies the file if it has newer changes applied.

Any help appreciated.
LVL 1
Jason ThomasAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
Use robocopy, not xcopy.
Robocopy will by default only copy files that don't exist in the same version in the target yet, so you can just run it several times and it will only copy the differences after the initial run.
Some hints to the arguments:
- /mir already includes /e or /s; this makes sure source and target are identical after the run (which includes deleting files in the target that don't exist in the source anymore!)
- /nfl and /ndl will suppress the file and folder listing of successfully copied files/folders; errors will still be logged. Having log entries for files that were successfully copied usually are of no interest and only clutter up the log
- /r and /w in a LAN are usually unnecessary; if a copy doesn't work, it's mostly "access denied", either because the file is in use or because someone thought he's so very smart that he doesn't need his files backed up, denying admin access. Retries won't change that and will only slow down the copy.
- /np disables the progress indicator. A progress bar is a very nice thing if you have the time to stare at the screen, willing the percentage to move, and if you copy files that are so large that a progress indicator actually makes sense. If writing to a log, it's totally counterproductive, because it fills the log with control characters.
- /z, /b, or /zb will slow down the copy because of the additional overhead, with not much benefit in a LAN. /z is useful if copying over WAN connections, and /b only if the account you're using doesn't have full control over the folder tree.
robocopy.exe \\OldServer\D$\Users D:\Users *.* /copyall /mir /r:0 /tee /nfl /ndl /np /log:"C:\Temp\UserCopy.log"

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jason ThomasAuthor Commented:
Thank you very much. Would you happen to know where I can download a copy of robocopy please?
0
oBdACommented:
robocopy is part of the OS since Vista/Server 2008 (which was part of your topics).
For XP/Server 2003, it's part of the Resource Kit Tools: http://www.microsoft.com/en-us/download/details.aspx?id=17657
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Steve KnightIT ConsultancyCommented:
The following options would be a start with xcopy:

xcopy /d /k /o /e  "c:\source\*.*" "D:\dest"

That will copy from source to dest if the file is newer or doesn't exist, but won't delete anything for dest.

but would suggest using robocopy instead:

robocopy "c:\source" "d:\dest" *.* /mir /copyall

That will DELETE any entries in dest that don't exist in source so be careful!  Nothing will be changed in source.

Steve
0
Steve KnightIT ConsultancyCommented:
Bit of delay between typing and pressing Submit there for me!
0
Jason ThomasAuthor Commented:
Thanks chaps, will give it a go now and report back.
0
Jason ThomasAuthor Commented:
Sorry for the delay.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Active Directory

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.