close

Home

Windows 10

Windows 11

Windows Client OS

A Complete Guide to Robocopy

Author avatar - Michael Reinders

Michael Reinders

|
Windows

Robocopy is a powerful command-line tool for Windows that allows users to synchronize files and folders from one location to another. Learn more about everything you can do with Robocopy here.

What is Robocopy?

Robocopy stands for “Robust File Copy.” It is a powerful (and potentially scary) command-line utility to copy or move files from one place to another. It is a favorite amongst many IT Pros, mostly due to its overwhelming number of useful features and switches.

advertisment

It was built to be more robust (hence the name) than Xcopy or the original copy command. Robocopy was first released with the Windows NT 4.0 Resource Kit (!). It has been a standard ‘feature’ in Windows since Windows Vista and Windows Server 2008.

What’s the difference with XCopy?

The biggest difference between Robocopy and Xcopy is the bewildering number of features, switches, flags, etc. There have also been several performance enhancements to Robocopy, making it a more pseudo-like backup utility compared to Xcopy.

Why use Robocopy instead of PowerShell?

Although you inherently get a lot of power in using PowerShell to handle the same basic copy/move file tasks mentioned here, again, the number of options available to you with Robocopy makes it the perfect choice if you want to handle file copy tasks efficiently and safely. Robocopy is a wonderful option for new file server creation and migration projects as well.

How Robocopy works

As I’ve already stated several times, Robocopy contains a robust set of options, switches, and flags to be as meticulous as you need for all your file transfer tasks that land on your plate. Let’s go through all these lovely options together!

advertisment

Note: These tables are directly from Microsoft’s docs.microsoft.com article as part of the tool’s main documentation site.

Copy options

Why don’t we just let you utilize this lovely table to get a handle on the complete, but always growing, number of options around the basics of copying? Enjoy. (POP quiz in about 10 minutes!) 🙂

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. In restartable mode, should a file copy be interrupted, Robocopy can pick up where it left off rather than re-copying the entire file.
/bCopies files in backup mode. Backup mode allows Robocopy to override file and folder permission settings (ACLs). This allows you to copy files you might otherwise not have access to, assuming it’s being run under an account with sufficient privileges.
/zbCopies files in restartable mode. If file access is denied, switches to 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 – DataA – AttributesT – Time stampsS – NTFS access control list (ACL)O – Owner informationU – Auditing informationThe 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 – DataA – AttributesT – Time stampsThe 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 onlyA – ArchiveS – SystemH – HiddenC – CompressedN – Not content indexedE – EncryptedT – Temporary
/a-:[RASHCNET]Removes the specified attributes from copied files. The valid values for this option are:R – Read onlyA – ArchiveS – SystemH – HiddenC – CompressedN – Not content indexedE – EncryptedT – 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 /logoption.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.

File Selection options

Alright, now we’ll present another nice table of all the ‘File Selection’ options in Robocopy.

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 onlyA – ArchiveS – SystemH – HiddenC – CompressedN – Not content indexedE – EncryptedT – TemporaryO – Offline
/xa:[RASHCNETO]Excludes files for which any of the specified attributes are set. The valid values for this option are:R – Read onlyA – ArchiveS – SystemH – HiddenC – CompressedN – Not content indexedE – EncryptedT – TemporaryO – 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.
/imInclude modified files (differing change times).
/isIncludes the same files.
/itIncludes tweaked files.
/xcExcludes existing files with the same timestamp, but different file sizes.
/xnExcludes existing files newer than the copy in the source directory.
/xoExcludes existing files older than the copy in the source directory.
/xxExcludes extra files and directories present in the destination but not the source. Excluding extra files will not delete files from the destination.
/xlExcludes “lonely” files and directories present in the source but not the destination. Excluding lonely files prevents any new files from being added to the destination.
/isIncludes the same files. Same files are identical in name, size, times, and all attributes.
/itIncludes “tweaked” files. Tweaked files have the same name, size, and times, but different attributes.
/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.

Retry options

Here is a good set of options to help keep your Robocopy command more robust and reliable.

advertisment

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).

Logging options

For the next set, let’s go over the list of Logging options available in Robocopy.

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.

Copying files and folders with Robocopy

Alright, it looks like I bombarded you with all these options, switches, and flags, Oh my! Let’s get to some examples of copying files with Robocopy.

I am using a Windows 11 client machine in my Windows Server 2022 Active Directory domain lab environment.

The following command will (not really) back up the files in the first location to the file server (G: drive). I used the /quit switch to verify that what Robocopy intends to do is correct.

Robocopy c:\Backup_Files g:\folder01 /quit
Our first Robocopy command
Our first Robocopy command – playing it safe…

This command shows the Source and Destination ‘root’ locations, what files to backup, and then the options it will use. Everything looks good, now let’s run it!

Robocopy c:\Backup_Files g:\folder01
We copied a whole file with this Robocopy command!
We copied a whole file with this command!

Notice that only one file was copied, the single TXT file in the root of c:\Backup_Files. This is because subdirectories are not backed up by default. So, the next step is to include subdirectories.

How to include subfolders

We can include subfolders with the /e switch to include all subdirectories, even empty ones.

robocopy c:\Backup_Files g:\folder01 /e
We copied 17 files with the /e switch to include all subdirectories
That’s more like it! We copied 17 files with the /e switch

Looking at the summary below, 18 total files were discovered in the source, and 17 were copied because we already copied that single file in the root of the source. As a result, one file was skipped.

Moving files and folders

Instead of copying the files, we can move them using the /move switch.

robocopy c:\Backup_Files g:\folder01 /move /e
Here we choose to /MOVE files to the destination
Here we choose to /move files to the destination

I checked my C: drive and the files are indeed gone. They are now on the G: drive.

How to filter files and folders

I doubt you won’t always want to copy ALL the files from one place to another. You will want to filter what files get copied.

Next, I’ll go through the most prevalent switches to select files by name, type, size, etc., all by using wildcard characters.

Selecting files by name or file type

We can use wildcards to choose specific filenames. As you can see, the command below with the asterisk only copied the files starting with the letter ‘m’.

robocopy c:\Backup_Files g:\folder01 m* /e
We used a wildcard character to only include files that start with the letter 'm'
We are specifying to only include files that start with the letter ‘m’

We can also choose to copy only PDF files with the command below.

robocopy c:\Backup_Files g:\folder01 *.pdf /e

Selecting files by file size

To address the need to choose files by size, let’s use this command with the /max switch to only copy files under 1MB.

robocopy c:\Backup_Files g:\folder01 /e /max:1000000
Using the /MAX switch to only copy files under 1 MB
Using the /max switch to only copy files under 1 MB

Here, 26 files under 1MB were copied and 10 were skipped because they were larger.

Selecting files by modification date

If we only wish to copy files that are less than a year and a half old, we can use the /maxage switch.

robocopy c:\Backup_Files g:\folder_01 /e /maxage:547

There were 4 files skipped here because they were older than 1.5 years old (or 547 days).

Synchronizing files and folders

We can use the powerful and potentially impactful /mir (MIRror) command to keep two locations in sync. Each time you run this command, anything not exactly the same in both the source and destination will be rectified.

In practice, if you delete a file from the source, it will also be deleted in the destination (gone from both!). Moreover, if someone deletes a file in the destination, it will be also deleted in the source (gone from both!). Yes, powerful and scary, so use this command with care.

robocopy c:\Backup_Files g:\folder_01 /e /mir
Using the /MIR switch to sync two locations
Using the /mir switch to sync two locations

I ran the command, and it did nothing as both locations were the same. I deleted one file from the source and ran it again.

As you can see above, there was an ‘EXTRA File’ found. So, naturally, Robocopy deleted it also in the destination. Interesting choice of words, wouldn’t you say?

How to monitor backups

If you have a dire need for a ‘should be good enough for our needs right now’ backup service in a pinch, Robocopy has a few tricks up its sleeve. You can use the /mon and /mot switches to monitor for changes. After a specified number of file changes and amount of time, Robocopy will make another pass and get your files backed up again.

robocopy c:\Backup_Files g:\folder_01 /e /mon:3 /mot:5
Using the /MON and /MOT switches to watch for file changes
Using the /mon and /mot switches to watch for file changes

As you can see at the bottom of this capture, the ‘Monitor’ is running, waiting for both 5 minutes and 3 file changes to take place. Using my DeLorean, I made at least three changes and went five minutes in the future…

Robocopy automatically ran again after 5 minutes because at least 3 file changes were detected
Robocopy automatically ran again after 5 minutes because at least 3 file changes were detected

You’ll notice Robocopy ran again and copied a file, skipped most, and also found an extra file in the destination. Pretty slick!

How to transfer files across a network

There are a few specific switches and options to help IT Pros when doing larger file copies over a Local Arean Network (LAN) or a Wide Area Network (WAN). Here are the core options:

ParameterDescription
/zbThis switch will copy files in restartable mode, letting it pick up from an interrupted copy session if a network path is slow, or unreliable. The ‘B’ option helps you overcome locked down ‘read’ permissions on the source by letting you at least copy ALL files.
/copyallTo ensure your files are able to be opened and changed in your new fileserver, for example, use this so all file permissions are copied along with the files. You’ll want your users to be able to seamlessly access all their files after your new fileserver is in place!
/rhThis will restrict Robocopy from running during certain hours. If you have a huge fileserver migration project and you don’t want your network connection (especially a WAN) to be saturated during business hours, use this little wonder.
/mtUse this to help boost the number of threads Robocopy will instruct the CPU to use, to help the performance of your copies.

How to use Robocopy Jobs

Here’s another Robocopy feature I was unaware of – Jobs. You can save a rather complex Robocopy command for later use using the /save switch at the end. Here is an example.

robocopy c:\Backup_Files g:\folder_01 m* /e /max:1000000 /maxage:400 /save:"c:\Temp\BackupJob1"
This is the output text file from the /SAVE command
This is the output text file from the /save command

The image above is the output of the text file Robocopy creates. Now, to run this specific Job/string in the future, you utilize the /job switch as so.

robocopy /job:"c:\temp\BackupJob1.rcj"
we 'retrieve' the saved Robocopy job using the /JOB command
And here we ‘retrieve’ the saved job using the /job command

Voila!

Conclusion

Robocopy is a wonderful file copy utility every IT Pro should keep in their arsenal. It is continually being enhanced with new features, even on Windows 11, and we hope this guide gives you some ideas about how to integrate Robocopy into your workflow.

Article saved!

Access saved content from your profile page. View Saved