Knowing how to masterfully use robocopy to transfer files might become a life saver and help you keep your job. Well the previous statement might be a tad bit over dramatic but who knows, it might be true too. The world’s a weird place.

There comes a time in a life of an IT engineer where you need to migrate file servers to new hardware or make a backup copy of your data to cover your buns to an external hard drive because management does not want to invest to replace old backup hardware that’s on the verge of failing.

Transferring files using robocopy is a more powerful method than the traditional copy and paste method. It’s much faster and can be multi-threaded to copy tons of small files. It is a lot more reliable as you can set it to restart copy or skip files in your robocopy script. Plus you get to output logs as well.

Since robocopy is a script, you can set it in the Windows Task Scheduler to run at appropriate times to back up what’s needed to an external location.

Masterfully use robocopy to transfer files

The syntax for robocopy is as below:

robocopy <source> <destination> <filename> </options>

source: Location of the files that you want to copy from.

destination: Location that you want to copy to.

filename: Name of the file that you want to copy. If left blank robocopy will copy all the files in the directory.

options: specify available options to use with the robocopy command.

You can use robocopy either on Command Prompt or PowerShell. I’ll be using PowerShell in this guide. Ensure that you run either program in Administrator mode.

An example to copy files from one server to another:

robocopy \\oldfileserver01\business \\newfileserver01\business /MIR /SEC /ZB /MT:2 /R:1 /W:1 /LOG /TEE
powershell-robocopy
Entering robocopy command in Windows PowerShell

An example to copy files from a server to an external drive attached to your computer:

robocopy \\oldfileserver01\business F:\business /MIR
 /ZB /MT:2 /R:1 /W:1 /

An example to copy a file from a local disk to an external drive attached to your computer:

robocopy D:\business F:\business business-report-March-2021.xlsx /MT:2 /Z

As you can see from the above examples, robocopy can be used to transfer files either within the same computer or to an external location over the network. If your organization allows you to attach external drives to your servers, the transfer will be much quicker. Mine doesn’t.

To masterfully use robocopy to transfer files you would need to get to know the parameters a lot better. They are the ones who make robocopy such a powerful tool to have in your arsenal.

The ones used in my examples are usually what I utilize when doing file transfers with robocopy and are explained below.

/MIR : Mirrors the entire directory of the source to the destination.

/SEC : Copy files with security permissions intact.

/Z   : Allows to copy files in restartable mode. Usually combined with /B.

/B   : Allow to copy file in back up mode. Usually combined with /Z

/MT  : Multi threading option. Able to specify number of threads you want by declaring the number i.e /MT:2, MT:4 and so on.

/LOG : Writes output status on the log file.

/TEE : Writes output status both on the log file and console window.

/R   : Specifies the number of retries that robocopy will do on failed copies. The default value is 1 million, so you might want to adjust it a little bit.

/W   : Specifies the wait time between retries. The default value is 30 seconds per interval. You might want to adjust this as well. Imagine a million retries at 30 second intervals, huh!

Another pro tip is to be careful when using the /MIR parameter as it will remove any files or folders in the destination that are no longer available in the source. If you just need to transfer new files from the source then you can erase the /MIR parameter from your command.

If you are doing robocopy over the network, please mind using the /MT parameter as it might affect your network bandwidth. Try are see what works best for your environment.

There are a lot more robocopy options available to choose from for copying, file selections, logging and job depending on your needs that you can refer below so that you can masterfully use robocopy to transfer files.

The list below are courtesy from Microsoft robocopy page.

Copy options

OptionDescription
/sCopies subdirectories. This option automatically excludes empty directories.
/eCopies subdirectories. This option automatically includes empty directories.
/lev:<n>Copies only the top n levels of the source directory tree.
/zCopies files in restartable mode.
/bCopies files in Backup mode.
/zbUses restartable mode. If access is denied, this option uses Backup mode.
/jCopies using unbuffered I/O (recommended for large files).
/efsrawCopies all encrypted files in EFS RAW mode.
/copy:<copyflags>Specifies which file properties to copy. The valid values for this option are:

D – Data
A – Attributes
T – Time stamps
S – NTFS access control list (ACL)
O – Owner information
U – Auditing information.

The default value for this option is DAT (data, attributes, and time stamps).
/dcopy:<copyflags>Specifies what to copy in directories. The valid values for this option are:

D – Data
A – Attributes
T – Time stamps.

The default value for this option is DA (data and attributes).
/secCopies files with security (equivalent to /copy:DATS).
/copyallCopies all file information (equivalent to /copy:DATSOU).
/nocopyCopies no file information (useful with /purge).
/secfixFixes file security on all files, even skipped ones.
/timfixFixes file times on all files, even skipped ones.
/purgeDeletes destination files and directories that no longer exist in the source. Using this option with the /e option and a destination directory, allows the destination directory security settings to not be overwritten.
/mirMirrors a directory tree (equivalent to /e plus /purge). Using this option with the /e option and a destination directory, overwrites the destination directory security settings.
/movMoves files, and deletes them from the source after they are copied.
/moveMoves files and directories, and deletes them from the source after they are copied.
/a+:[RASHCNET]Adds the specified attributes to copied files. The valid values for this option are:

R – Read only
A – Archive
S – System
H – Hidden
C – Compressed
N – Not content indexed
E – Encrypted
T – Temporary
/a-:[RASHCNET]Removes the specified attributes from copied files. The valid values for this option are:

R – Read only
A – Archive
S – System
H – Hidden
C – Compressed
N – Not content indexed
E – Encrypted
T – Temporary
/createCreates a directory tree and zero-length files only.
/fatCreates destination files by using 8.3 character-length FAT file names only.
/256Turns off support for paths longer than 256 characters.
/mon:<n>Monitors the source, and runs again when more than n changes are detected.
/mot:<m>Monitors the source, and runs again in m minutes, if changes are detected.
/MT[:n]Creates multi-threaded copies with n threads. n must be an integer between 1 and 128. The default value for n is 8. For better performance, redirect your output using /log option.The /mt parameter can’t be used with the /ipg and /efsraw parameters.
/rh:hhmm-hhmmSpecifies run times when new copies may be started.
/pfChecks run times on a per-file (not per-pass) basis.
/ipg:nSpecifies the inter-packet gap to free bandwidth on slow lines.
/slDon’t follow symbolic links and instead create a copy of the link.
/nodcopyCopies no directory info (the default /dcopy:DA is done).
/nooffloadCopies files without using the Windows Copy Offload mechanism.
/compressRequests network compression during file transfer, if applicable.
Copy options to masterfully use robocopy to transfer files.

File selection options

OptionDescription
/aCopies only files for which the Archive attribute is set.
/mCopies only files for which the Archive attribute is set, and resets the Archive attribute.
/ia:[RASHCNETO]Includes only files for which any of the specified attributes are set. The valid values for this option are:

R – Read only
A – Archive
S – System
H – Hidden
C – Compressed
N – Not content indexed
E – Encrypted
T – Temporary
O – Offline
/xa:[RASHCNETO]Excludes files for which any of the specified attributes are set. The valid values for this option are:

R – Read only
A – Archive
S – System
H – Hidden
C – Compressed
N – Not content indexed
E – Encrypted
T – Temporary
O – Offline
/xf <filename>[ ...]Excludes files that match the specified names or paths. Wildcard characters (* and ?) are supported.
/xd <directory>[ ...]Excludes directories that match the specified names and paths.
/xcExcludes changed files.
/xnExcludes newer files.
/xoExcludes older files.
/xxExcludes extra files and directories.
/xlExcludes “lonely” files and directories.
/isIncludes the same files.
/itIncludes modified files.
/max:<n>Specifies the maximum file size (to exclude files bigger than n bytes).
/min:<n>Specifies the minimum file size (to exclude files smaller than n bytes).
/maxage:<n>Specifies the maximum file age (to exclude files older than n days or date).
/minage:<n>Specifies the minimum file age (exclude files newer than n days or date).
/maxlad:<n>Specifies the maximum last access date (excludes files unused since n).
/minlad:<n>Specifies the minimum last access date (excludes files used since n) If n is less than 1900, n specifies the number of days. Otherwise, n specifies a date in the format YYYYMMDD.
/xjExcludes junction points, which are normally included by default.
/fftAssumes FAT file times (two-second precision).
/dstCompensates for one-hour DST time differences.
/xjdExcludes junction points for directories.
/xjfExcludes junction points for files.
File selection options to masterfully use robocopy to transfer files.

Retry options

OptionDescription
/r:<n>Specifies the number of retries on failed copies. The default value of n is 1,000,000 (one million retries).
/w:<n>Specifies the wait time between retries, in seconds. The default value of n is 30 (wait time 30 seconds).
/regSaves the values specified in the /r and /w options as default settings in the registry.
/tbdSpecifies that the system will wait for share names to be defined (retry error 67).
Retry options to masterfully use robocopy to transfer files

Logging options

OptionDescription
/lSpecifies that files are to be listed only (and not copied, deleted, or time stamped).
/xReports all extra files, not just those that are selected.
/vProduces verbose output, and shows all skipped files.
/tsIncludes source file time stamps in the output.
/fpIncludes the full path names of the files in the output.
/bytesPrints sizes, as bytes.
/nsSpecifies that file sizes are not to be logged.
/ncSpecifies that file classes are not to be logged.
/nflSpecifies that file names are not to be logged.
/ndlSpecifies that directory names are not to be logged.
/npSpecifies that the progress of the copying operation (the number of files or directories copied so far) will not be displayed.
/etaShows the estimated time of arrival (ETA) of the copied files.
/log:<logfile>Writes the status output to the log file (overwrites the existing log file).
/log+:<logfile>Writes the status output to the log file (appends the output to the existing log file).
/unicodeDisplays the status output as Unicode text.
/unilog:<logfile>Writes the status output to the log file as Unicode text (overwrites the existing log file).
/unilog+:<logfile>Writes the status output to the log file as Unicode text (appends the output to the existing log file).
/teeWrites the status output to the console window, as well as to the log file.
/njhSpecifies that there is no job header.
/njsSpecifies that there is no job summary.
Logging options to masterfully use robocopy to transfer files.

Masterfully use robocopy to transfer files: Return value codes

Return codes describes what happened during the file transfer process for your knowledge and action if there were any failures.

ValueDescription
0No files were copied. No failure was encountered. No files were mismatched. The files already exist in the destination directory; therefore, the copy operation was skipped.
1All files were copied successfully.
2There are some additional files in the destination directory that are not present in the source directory. No files were copied.
3Some files were copied. Additional files were present. No failure was encountered.
5Some files were copied. Some files were mismatched. No failure was encountered.
6Additional files and mismatched files exist. No files were copied and no failures were encountered. This means that the files already exist in the destination directory.
7Files were copied, a file mismatch was present, and additional files were present.
8Several files did not copy.
Return codes to understand and masterfully use robocopy to transfer files.

Read more: Learn how to restore files from Shadow Copy which the path exceeds Windows allowed character limits.

Conclusion about how to masterfully use robocopy to transfer files

As you can see robocopy is a very extensive and powerful program to have in your toolbox. Most of the time for your file transfer activities, you might won’t even use one third of the listed options.

To masterfully use robocopy to transfer files you do not need to remember all of the options, it is adequate to remember a few and use the list above for reference when you have a specific need for them.

Leave a Comment

Your email address will not be published. Required fields are marked *

This div height required for enabling the sticky sidebar