xcopy and retain permissions

Posted on 2014-07-16
Last Modified: 2014-07-30
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.
Question by:Jason Thomas
    LVL 82

    Accepted Solution

    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

    LVL 1

    Author Comment

    by:Jason Thomas
    Thank you very much. Would you happen to know where I can download a copy of robocopy please?
    LVL 82

    Expert Comment

    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:
    LVL 43

    Assisted Solution

    by:Steve Knight
    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.

    LVL 43

    Expert Comment

    by:Steve Knight
    Bit of delay between typing and pressing Submit there for me!
    LVL 1

    Author Comment

    by:Jason Thomas
    Thanks chaps, will give it a go now and report back.
    LVL 1

    Author Closing Comment

    by:Jason Thomas
    Sorry for the delay.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
    Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
    This tutorial will show how to inventory, catalog, and restore media from legacy versions of Backup Exec into both 2012 and 2014 versions of the software. Select Storage from the tabs along the ribbon bar as the top: Ensure the proper storage devi…
    This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now