From time to time, Windows professionals must copy large amounts of data from one volume to another. Many technicians take the easy route and simply drag and drop individual files and folders. Oh, and by the way, they also lose time and drive up costs for their company because they have to babysit the process. If you want to save yourself time and become a more valuable engineer, Robocopy is a tool you will want to add to your repertoire.
Robocopy may be run from a either a Command prompt or a PowerShell prompt. I recommend that you run Robocopy from PowerShell, as you will eventually want to create PowerShell scripts. The basic form of Robocopy is,
robocopy <source directory> <destination directory> <files> <options>
The source directory is the location of the files to be copied. The destination directory is the place where you want the files. The files argument specifies a DOS file matching parameter, for example, all executable files would match “*.exe”. The files argument may be omitted, in which case all files would be copied, i.e., the matching pattern of “*.*” is assumed.
So for example, if we wanted to copy the files located in Sally’s documents folder to an external drive mounted on the F: drive, the Robocopy command would be,
robocopy c:\Users\Sally\Documents f:\
The options argument allows you to modify the default manner in which Robocopy operates, and here we begin to see the real power of Robocopy. Some of the more commonly used options are,
/e – Copy all subdirectories, including empty directories
/z – Copy files in Restart mode. This is useful if you are copying large files over an unstable network. If disconnected, Robocopy picks up where it left off. In my experience, Robocopy performs slower when using this option. You don’t need to use it if you are on a stable network.
/b – Copy files in Backup mode. Allows an administrator to assert a “backup right” and copy files with denied readability to the administrator.
/copy:<copyflags> – Specify file properties to be copied. Values for this options include D (Data), A (Attributes), T (Time Stamps), S (NTFS ACL), O (owner information), and U (Auditing information). The default for <copyflags> is DAT.
/purge – (DANGER) Deletes destination files and directories that no longer exist in the source.
/mir – (DANGER) Mirrors a directory tree. Equivalent to /e /purge.
/move – (DANGER) Moves files and directories, and deletes from the source.
/xf <filename> – Excludes files that match a specified name (wildcards are allowed).
/xd <dirname> – Exclude directories that match a specified name (wildcards are allowed).
/r:<n> – Specify the number of retries on failed copies. The default is one million, you will want to set this to something less, like /r:1.
/w:<n> – Specify the wait time in seconds between retries. The default is 30 seconds. You will probably want to set this to something less, like /w:1.
/l – List the operations to be performed. No actions are taken. This is very useful if you’re not sure what Robocopy is going to do.
/log:<logfile>– Send output to a log file instead of standard output.
/tee – Send output to standard output as well as the log file.
Extending the previous example, let’s say that Sally’s Documents directory possessed a number of subdirectories. Also, we don’t want to copy any executable files, and we want to log the output. The Robocopy command would be,
robocopy c:\Users\Sally\Documents f:\ /e /r:1 /w:1 /xf *.exe /log:f:\logfile.txt
This is only a small fraction of the options available with Robocopy. See the TechNet website for a full description of the Robocopy command. If you find a new or interesting use for Robocopy, please add to the comments for all of us to admire!!!