Ahhh. The simplest of tools. Yet it works beautifully. A quick guide on using robocopy for large data migrations from NTFS where retaining the NTFS ACLs is important (oh and remember, you lose the shares using this method but heck they’re usually easy to re-create!).
First, audit your environment. More detail on that later, but at the very least dump out the shares list and top level ACLs.
Use this robocopy command to bulk copy the data upfront:
Robocopy %source% %target% /ZB /COPYALL /E /W:0 /R:0 /NP /LOG+:”C:\%logdir\%source%.txt
A few things to note, if the path for Source or Target has a space then you must enclose the path in “double quotes” but i advise always enclosing them in double quote unless they are really simple for example just root drive letters (e.g. robocopy E:\ X:\) where double quotes might cause problems.
Always generate a log file, you will always analyse it later for errors. I’ll show you how using a powershell script makes this easier in a blog post to follow.
Modify the switches accordingly, use robocopy /? to get a list within your powershell/cmd window. Use the same command to get a description of the above switches if you don’t already know what they are.
Use the SysInternals tool PsExec to execute the session in a system context so no user account needs to be actively logged into a server to execute a migration.
Robocopy Examples:
### Copy SECURITY without copying FILES ###
NOTE: Only refreshes security for EXISTING files, does not copy any file data
Robocopy %source% %dest% /secfix /xo /xn /xc
### Copy DIRECTORY Date Stamps ###
Robocopy %source% %dest% /DCOPY:T
### Skip SAME or NEWER in Destination ###
If you are copying files to the Target in stages over, then you don’t want to copy ALL
the files over again and only new files that were added since the first copy
you can use the “/XO” flag which excludes older files. This means if the
destination file exists and is the same date or newer than the source file
robocopy will skip that file.
robocopy %source% %dest% /E /W:0 /R:0 /XO
### Robocopy Log explanations ###
*Extra File or *Extra Dir – File does NOT exist on your Source, but DOES exist on your Target. If using /MIR, the “Extra file” will be deleted from the Target.
New File – means that it DOES exist on the Source, but DOES NOT exist on the Target. If using default or /MIR, the new file is copied to the Target
Newer – file is newer at Target, so the Source version is older and using default robocopy it will NOT copy an older Source file.
### What to do with “Access Denied” in Source ###
Use subinacl.exe, download it from the 2003 Resource Kit.
First you need to take Ownership of the folder causing the problem:
subinacl /file Z:\SourceFolder /setowner=administrators /grant=administrators=F
In the above example, replace ‘administrators’ with any user/group you wish to add.
How that you have ownership, you need to set the Full Control ACL for your user/group & apply to all sub-folders and files. Use this:
start cmd.exe /C subinacl /subdirectories Z:\SourceFolders\*.* /grant=administrators=F
Again, replace ‘administrators’ with any user/group you wish to add.
I often find I have to run this across multiple different root folders, so i add multiple entries to a batch file and use start cmd.exe /C to launch seperate command line sessions (manual multi-threading!)
If you’re really migrating, don’t miss the opportunity Robocopy gives you to optimized the directory structure. It’s a one time opportunity.
First, create the file structure with Robocopy’s /create parameter. Follow that with another Robocopy command, leaving out the /create parameter.
In this example, I leave out other options you may want for logging, attributes, retries, etc:
robocopy C:\ D:\ /E /create
robocopy C:\ D:\ /E
Your disk system will work faster if it doesn’t have to hop across files to update directory information.
Thanks Wynn, very useful info.
I’ll be diving deeper into the robocopy options in a blog post to come! Hope to cover most of the useful but misunderstood switches!
Thanks,
Hola, gracias por la informacion.
estoy buscando algo referente a una marca (-1) que escribe en el Log de registro, cuando le pongo el parametro /XC (excluir los archivos modificados)
Gracias