The Ultimate Guide to Robocopy

choubertsprojects

The Best WordPress plugins!

1. WP Reset

2. WP 301 Redirects

3. WP Force SSL

Robocopy is a command-line utility used to copy files and directories between locations. It can be used for backups, mirroring or synchronization of data in Microsoft Windows operating systems. The software was built by the company Sysinternals in 1995 and has been updated ever since then on an almost constant basis with new features each time.

The “robocopy command to copy folders and subfolders” is a command-line tool that allows users to copy files and folders. The Ultimate Guide to Robocopy has many commands that you can use with the tool.

The Ultimate Guide to Robocopy

Robocopy is a popular command-line utility for copying huge amounts of data under Windows. Because of how strong it is, it is such a popular tool. However, with all that power comes a great deal of complication. We’ll break down all of that jargon and give you a step-by-step Explanation on how to utilize this helpful tool in this article.

Are you not a reader? Take a look at this related video.

Robocopy is a command-line program for Windows that has been around since Windows NT. It’s a substitute for the xcopy utility, which is less flexible. It enables you to copy/Files should be moved from a command prompt by specifying a disk path or server location.

As of this writing, the latest version of Robocopy is 10.0.18. This is the version on which I did my tests.

Robocopy comes with a number of tools that may help you execute efficient and quick file copies and transfers. It may be able to:

  • Files may be copied across a network and resumed.
  • Infinite loops may cause failure by skipping NTFS junction points.
  • Copying file and directory characteristics while keeping timestamps is possible.
  • NTFS permissions, owners, and auditing information may all be copied.
  • It’s possible to Copy the timestamps in the directory.
  • Can copy files in ‘backup’ mode to guarantee that files are copied even if the administrator’s permissions have been denied.
  • Retries are performed automatically.
  • Two folders may be synced
  • Is intelligent enough to skip files that have previously been copied
  • Paths with more than 256 characters may be copied.
  • Using its multithreading capabilities, do asynchronous copies.
  • Returns a set of standardized Codes of Exit that may be used in scripts.

There’s a lot to copy, as you can see. I wanted to make sure you knew all there is to know about this useful tool.

Syntax for Robocopy in Common

Why is it necessary to write such a lengthy blog article on a single utility? Just have a look at the tables below. With robocopy, you have a lot of choices for copying and moving files! In the separate sections, you’ll find additional possibilities.

The help syntax supplied by robocopy /? was used to create these tables. They’ve been divided into more helpful parts, expanded over time, and cleaned up to give more relevant information.

Optional Sources

Switch Explanation Default Actions Switches That Are Equivalent Notes
/S Subfolders are copied.      
/E Subfolders are copied. including empty subfolders      
/COPY:[DATSOU] Options for copying /COPY:DAT   D stands for data, A for attributes, and T for timestamps. O=Owner information, U=aUditing information, S=Security=NTFS ACLs File Timestamps are always included in File Data (D) (T)
/SEC SECURITY is used to copy files.   /COPY:DATS  
/DCOPY:T Copy the timestamps in the directory      
/COPYALL COPY THE ENTIRE FILE INFORMATION   /COPY:DATSOU This prevents offline files from being dehydrated and instead copies the file’s tag (at least on emc VNX/Unity systems). This isn’t anything that’s been formally recorded! You can’t transfer the ACLs along with your files if you require dehydration (which is why I discovered this problem). Monsieurx is should be credited with this image (Reddit)
/NOCOPY NO information about the file is copied.     /PURGE is a handy command.
/A Only files having the Archive attribute set should be copied.      
/M similar to /A, but without the Archive property in the source files      
/LEV:n Only the top n LEVels of the source tree should be copied.      
/MAXAGE:n MAXIMUM FILE AGE – files older than n days/date will be excluded.      
/MINAGE:n MINIMUM FILE AGE – files older than n days/date will be excluded.     If n < 1900 then n = no of days, else n = YYYYMMDD date
/FFT Assume you’re working with FAT files.     Date/time granularity of 2 seconds. This takes the place of the NTFS timestamps. When exchanging data through a network, it seems to be more dependable.
/256 Turn off very long path (> 256 characters) support      

Optional Destinations

Switch Explanation Default Actions Switches That Are Equivalent Notes
/A+:[RASHCNET] Add file attribute(s) on destination files + set file attribute(s) on source files      
/A-:[RASHCNET] On destination files, remove the file attribute(s).      
/FAT Only use 8.3 FAT file names when creating destination files.      
/CREATE Make a directory tree structure with only zero-length files.      
/DST Make up for the one-hour discrepancy in DST time.      

Options for copying

Switch Explanation Default Actions Switches That Are Equivalent Notes
/L Only file names are listed.     No files should be copied, timestamped, or deleted.
/MOV Files should be moved     After you’ve copied anything, remove it from the source.
/MOVE Files should be moved and directories     After you’ve copied anything, remove it from the source.
/sl Instead of the destination, copy file symbolic links.      
/Z Copy files in a manner that may be restarted.     Thrive in the face of a network outage
/B In backup mode, copy files.      
/J Using unbuffered I/O to copy     Large files should be avoided.
/NOOFFLOAD Copy files without utilizing the copy offload method in Windows.     https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-R2-and-2012/hh831628(v=ws.11)
/EFSRAW EFS RAW mode may be used to copy any encrypted data.      
/TIMFIX Fix all file timings, including those that were skipped.      
/XO Older people are not allowed to participate.     If the destination file already exists and is the same or newer in date than the source, don’t overwrite it.
/XC Files that have changed should be excluded.      
/XN Newer files should be excluded.      
/XX Files that are present in the destination but not the source are excluded. /XX    
[file] /XF /XF /XF /XF /XF / Exclude files that have the same names/paths/wildcards as the specified names/paths/wildcards.      
[dirs] /XD /XD /XD /XD /XD /XD Exclude directories with names or paths that match the provided ones.     ROBOCOPY c:source d:dest /XF *.doc *.xls /XD c:unwanted /S ROBOCOPY c:source d:dest /XF *.doc *.xls /XD c:unwanted /S
/IA:[RASHCNETO] Include files that have any of the qualities listed.      
/XA:[RASHCNETO] Exclude files that have any of the qualities listed.      
/IM Overwrite files that have been edited. This comprises files that were created at various periods.      
/IS Even if the files are identical, overwrite them.      
/IT Include files that have been modified.      
/XJ Junction points should be excluded from the source. /XJ    
/XJD Junction points should be excluded from the source. directories      
/XJF Junction points should be excluded from the source. files      
/MAX:n Exclude files with a size greater than n bytes.      
/MIN:n Exclude files with a size of less than n bytes.      
/MAXLAD:n Exclude files that haven’t been used in n years.      
/MINLAD:n Exclude files that have been used since n.     If n < 1900 then n = n days, else n = YYYYMMDD date
/MIR A directory tree is mirrored.   /PURGE /E  
/PURGE Delete any dest files or directories that don’t exist in the source.      
/XL Files that are present in the source but not in the destination are excluded.      
/SECFIX Robocopy /secfix secures all files, even those that have been skipped.     Choose one of the following choices to specify the kind of security information you wish to copy: /COPYALL /COPY:O /COPY:S /COPY:U /SEC /COPYALL /COPYALL /COPYALL /COPYALL /COPYALL /COPYALL /COPY
/ZB If access is denied, use Backup mode; otherwise, use Restartable mode.      

Options for Monitoring

Switch Explanation Default Actions Switches That Are Equivalent Notes
/R:n The number of times a copy has been retried after it has failed. /R:1000000   Always make an effort to set this option. To avoid wasting time retrying, I propose setting this to 10-20.
/W:n The amount of time between retries is called the wait time. /W:30   To retry more rapidly, attempt to set this option to a lower value. I recommend a range of 5 to 10.
/REG Save /R:n and /W:n as default values in the Windows registry.      
/RH:hhmm-hhmm When may fresh copies be started?      
/TBD Wait for sharenames to be specified before proceeding.     Error 67: Retry
/PF Check the number of hours it takes to execute a file (not a pass).      
/MON:n When there are more than n modifications, run it again.      
/MOT:m If anything has changed, run it again in m minutes.      

Understanding the Behavior of Robocopies

With all of the different syntactic possibilities open to you, I’ve thoroughly blown your mind. Let’s look at all of the numerous ways we can utilize this syntax now.

I could give you a huge list of robocopy commands with an ever-increasing amount of options. However, I believe it is preferable to teach you how to fish. Let’s look at how to make sense of all of these choices.

Only whole directories are copied by Robocopy.

There will be a source and destination directory for each robocopy operation. Robocopy copies and transfers files from one directory to another. With robocopy, it is not feasible to copy a single file directly. For this, use copy or PowerShell’s Copy-Item.

However, with the correct filtering, you may robocopy a single file, which you’ll read about below. To robocopy a single file, give the source and destination folders first, then the file name in the source directory.

> robocopy c:src d:dst copythisfile.txt

The Environment Influences Syntax

Also, the robocopy parameters you offer will be dependent on the environment. When deciding which alternatives to employ, you’ll need to answer a few questions.

  • Will you be copying to an empty directory all of the time?
  • Is it conceivable that files in the target directory already exist?
  • Will you be copying terabytes or a few gigabytes of data?
  • Will you be copying files locally or across a network?
  • …and a lot more.

You shouldn’t worry about options that overwrite files if there are no files in the target file directory. Don’t worry about those settings if you won’t be transferring data across the network. Clearly outline the present and prospective future conditions in which your environment will be.

Recognize the Default Choices

Robocopy comes with a number of settings pre-installed. By glancing at the tables above, you’ll be able to identify them. Every time you execute the utility, it also produces a useful result.

You can see below that when I ran robocopy with its most basic options (the source and destination folder), it automatically used some options. Understanding the Default Actions is important.

You’ll understand precisely what robocopy is doing behind the covers if you compare the choices you see in the output with the option descriptions above.

Default roboOptions for copyingDefault roboOptions for copying

Understanding the Functions of Robocopy Commands

If you’ve used copy or PowerShell’s Copy-Item cmdlets, you’ve probably specified a source and destination and went on about your day. There’s not a whole lot of options you can configure there. These robocopy commands have a Default Actions.

However, robocopy knows a lot more and provides you the freedom to change the behavior as much as you wish.

It’s crucial to understand that robocopy doesn’t merely understand the idea of a file or directory. There’s a lot more to a filesystem than that, and robocopy can handle it all.

A file on a filesystem isn’t merely a pointless object with a single function. There are several properties and features associated with the idea of a file. A file, for example, may include properties such as:

  • a date and time stamp (written, modified and accessed)
  • NTFS ACL
  • an owner
  • Information about NTFS auditing
  • unnoticed flag
  • flag that has been archived

If you copy or move a file, you have the option to copy or transfer all of its contents as well.

When you run robocopy, keep in mind that you’re not simply copying a file; you’re possibly copying all of the other data as well. It’s critical to recognize this and account for it in the robocopy choices you supply.

WhatIf Scenarios: The Fundamentals

If you have a large file server someplace that you’d want to move but don’t want to do anything just yet, you may utilize robocopy to reverse the process.

You may instruct robocopy to enumerate all of the files and/or directories you provide and return a list of files it copied/moved by using the /L option.

The /L option may be combined with any other option. This is a fantastic approach to get all of the settings that robocopy would have used back (default or not). It’ll give you a general idea of what robocopy will perform with the parameters you’ve given it.

Using /LUsing /L

The Fundamentals: Copying Files

Using a source and destination directory with no arguments is the most basic application of robocopy.

This option copies all files from C:src to C:dst, except subfolders.

Everything, including subfolders (empty or not) and NTFS rights, may be copied. This seems to be the procedure for copying everything about a directory of files to another directory, as far as I can determine.

All NTFS ACLs, file owners, subfolders (even empty ones), and file characteristics are copied here. All of this is feasible because to the /E option, which includes all empty subfolders, and the /COPYALL option, which catches the remainder.

> robocopy C:src C:dst /E /COPYALL

Moving Files: The Fundamentals

Moving files is similar to copying in that it moves files from one directory to another. The only difference between a copy and a move is that following the copy, the source files are deleted.

Use the /MOV option to remove files/directories from the source after copying. This will delete all files in the directory you provide (no subfolders).

> robocopy C:src C:dst /MOV

To transfer all files and subfolders, use the /MOVE command.

> robocopy C:src C:dst /MOVE

Syncing Files: The Fundamentals

You may use Robocopy to sync two folders. This implies making sure that all of the files in the destination directory are in the source directory, and nothing else. /MIR copies all files in the source that aren’t in the destination and deletes files in the destination that aren’t in the source. Beware!

> robocopy C:src C:dst /MIR

Using a Network to Copy Files

If you’re Using a Network to Copy Files, there are a few options that you should consider.

The /Z option in Robocopy enables you to copy files in’restartable mode.’ This implies that if a file starts copying and stops in the middle, the copy may resume rather than failing entirely. When the stream is cut across a network, the /Z option comes in handy.

Warning: Using /Z has been said to reduce performance by a quarter. Please let me know what you discover.

The /FFT option is also available. When uploading files over a network, this switch has been reported to retain file timestamps more correctly. Instead of NTFS, this option utilizes FAT file system timestamps.

SRV1share /Z /FFT robocopy C:src

Controlling the Inter-Packet Gap with /IPG

When Using a Network to Copy Files, you can use the /IPG switch. This is also known as the inter-packet gap option. This option defines (in milliseconds) the frequency in which robocopy will wait between sending new packets.

Use UNC Paths instead of Drive Letters wherever possible.

A Reddit user found the hard way that mapped disks should not be used as a destination directory. Instead, utilize a UNC path wherever possible. If you do, you can run into problems with the 256-character restriction. For further details, see this Microsoft document.

Robocopy /Z (Robocopy /Z) (Robocopy /Z) (Robocopy /Z) (Robo

Robocopy provides a backup to restartable mode (/ZB) option (/B) that copies files in backup mode. What exactly is “backup mode”?

When you copy a file on Windows and come across one that needs administrator rights, you’ll get an error message stating that you don’t have permission. Windows won’t allow you access it even if you’re operating as the local administrator.

WARNING: When transferring data to a Windows Server 2016 server with de-duplication enabled, there have been complaints of damaged server volumes. When you use the /ZB option, the System Volume Information will be discarded, resulting in a dedup chunk storage. When you attempt to alter the copied files, they will not be readable and will create errors. More information may be found at the Serverfault link.

Backup mode allows you to access files without having to be concerned about permissions.

Robocopy utilizes backup mode to read files with the SeBackupPrivilege user right and restore files with the SeRestorePrivilege user right. Any ACEs that would ordinarily restrict you from accessing such files are ignored.

The user rights SeBackupPrivilege and SeRestorePrivilege are usually issued to users in the Backup Operators and Administrators groups, although they may be deleted at any time. The backup module addresses this danger by temporarily granting those permissions to the person who is running robocopy.

Whether you want to know if your user account has that permission, type whoami /priv, and both rights should be shown.

Filtering and Sorting Files and Folders

The vast bulk of your choices revolve on excluding files and folders in various ways. I’ve outlined all of the methods you may use different criteria to filter or exclude files and folders.

Using the file name or the file extension

Wildcards are used to filter which files are copied/moved during a robocopy request. A wildcard may be used to find files that match a given file name string or extension.

You may specify *.txt to just copy TXT files, for example.

> robocopy C:src C:dst *.txt

You might use a* to restrict your search to to files that begin with the letter a.

> robocopy C:src C:dst a*

You may also use a space to separate several sets of file name matches, as illustrated below.

> robocopy C:src C:dst a* b*

Robocopy will display you the filter in the output if you filter by file name.

Filtering the output of filesFiltering the output of files

Using the Directory Name

Robocopy allows you to filter items not just by file but Using the Directory Name too. Using robocopy /xd, you can exclude certain directories matching a specific name.

Use the /XD option to exclude directories from the run when copying multiple folders.

> robocopy C:src C:dst /XD “c:srcexclude”

By the timestamp of a file or directory

Below you will find all of the roboOptions for copying that will exclude files and folders based on various timestamp attributes.

Switch Explanation
/DCOPY:T Copy the timestamps in the directory
/MAXAGE:n Exclude files that are more than n days/dates old.
/MINAGE:n Exclude files that are more than n days/dates old.
/XO Don’t overwrite if the destination file already exists and is the same date or newer than the source.
/XN Don’t overwrite if the destination file already exists and is the same date or older than the source.

When it comes to timestamp filtering, there are two prominent options: /XO and /MAXAGE.

Only files that are newer than the source may be excluded from copying using /XO. You may robocopy just new files by access date using the /XO option.

> robocopy C:src C:dsc /XO

You may also use the /MAXAGE option if you know how old your files will be. This enables you to set the oldest date a file may have before it’s duplicated in YYYMMDD format.

> robocopy c:src c:dst /S /MAXAGE:20191001

Jobs for Robocopiers

You’ve seen that there are a plethora of possibilities open to you. It’s simple for these alternatives to become cumbersome very quickly. Thankfully, you have a better alternative than remembering all of these selections and ensuring that they are correct every time.

Job files for Robocopy are text files with one parameter per line. To produce these job files, you’ll most likely utilize robocopy. After that, you can either use robocopy or a basic text editor to alter them.

You have a number of robocopy commands that may be used with tasks.

Switch Explanation Default Actions Switches That Are Equivalent Notes
/JOB:jobname Parameters should be taken from the designated job file.      
/SAVE:jobname Save the job parameters to a specified file.      
/QUIT After processing the command line, exit.     This is useful for looking at parameters.
/NOSD There is no source directory given.      
/NODD There is no defined destination directory.      
/IF Include the following files in your project:      

A common robocopy job file has the RCJ suffix and looks like the example below. robocopy C:src D:dst /save:myjob was used to produce this job file. You can see that you may add comments to the task file using::, which is what this file is mostly made up of.

The file would only have one choice per line if there were no comments.

:: :: Robocopy Job C:MYJOB.RCJ :: :: Created by Administrator on Sunday, August 18, XXXX at 8:53:24 AM :: :: :: Source Directory : :: /SD:C:SRC :: Source Directory. :: :: Destination Directory : :: /DD:C:SRC :: Destination Directory. :: :: Include These Files : :: /IF :: Include Files matching these names :: *.* :: Include all names (currently – Command Line may override) :: :: Exclude These Directories : :: /XD :: eXclude Directories matching these names :: :: eXclude no names (currently – Command Line may override) :: :: Exclude These Files : :: /XF :: eXclude Files matching these names :: :: eXclude no names (currently – Command Line may override) :: :: Options for copying : :: /DCOPY:DA :: what to COPY for directories (default is /DCOPY:DA). /COPY:DAT :: what to COPY for files (default is /COPY:DAT). :: :: Retry Options : :: /R:1000000 :: The number of times a copy has been retried after it has failed.: default 1 million. /W:30 :: The amount of time between retries is called the wait time.: default is 30 seconds. :: :: Logging Options : ::

Keeping Job Files Safe

Saving a job file is as simply as appending the /SAVE:<jobname> option to the end of your syntax. Replace <jobname> with the name of the job. The /SAVE option will create a file called <jobname>.rcj in the directory where you ran robocopy.

> robocopy C:src C:dst /SAVE:myjob

As the final option, you must provide /SAVE. After /SAVE, any settings supplied will not be saved in the job file. Also, keep in mind that even if a job file already exists, robocopy will always replace it. Your task files should be backed up or version controlled!

Note: Attempting to save a job file with the /MT option will result in the job file not being saved. Please let me know if you were successful in getting this added.

Making Use of Job Files

Once a job is saved into a job file, you can then use the /JOB:<jobname> option to specify the job file to read from. Robocopy reads all of the parameters inside of the job file. It then executes just as if you provided the options directly on the command-line.

Using /QUIT to create a job file without running a job

The /QUIT option’s function isn’t evident. On the surface, /QUIT seems to compel a running exit. /QUIT is more of a stopgap measure than a way to stop a task from running in the first place.

The /QUIT option “forces robocopy to cease processing the command line,” according to the documentation. It’s best described as producing a job file without actually performing a task.

It will also execute the task automatically if you use the /SAVE option. It’s impossible to generate a job file without first executing it. You may use a text editor to construct the RCJ job file, or you can use robocopy to do it by putting /QUIT to the end.

> robocopy C:src C:dst /SAVE:myjob /QUIT

Making Changes to a Job File

You can modify job files using your preferred text editor or have robocopy do it for you since they are simply text files.

Using the commands /JOB, /SAVE, and /QUIT, you may modify job files.

For example, suppose you want to exclude all EXE files from your robocopy operation, which is recorded in the backupfiles.rcj job file. You don’t want to replace the whole job file that you’ve previously generated. You may add the new option in the following way:

> robocopy /JOB:backupfiles /XF *.EXE /SAVE:backupfiles /QUIT

Making Use of Multiple Job Files

You may even utilize job files in conjunction with each other. When several job files are specified in the same run, all of the parameters used in that run are pooled.

If you have a long list of files to exclude from your backupfiles copy task, for example. To create an exclude.rcj file, open a text editor and type the following.

Then, as follows, you may exclude these files from the backupfiles job:

> robocopy /JOB:backupfiles /JOB:exclude

The above run’s syntax would be /XF *.exe a.exe b.txt c.cer since the original backupfiles job file already excluded all EXE files. Robocopy is a program that integrates all of your selections into one.

Using the /NOSD and /NODD Options with Robocopy Templates

You can create task files that take parameters if you’re dealing with a lot of them. When you execute tasks using Robocopy, you may send values from the command line to them. Although a parameter is not a robocopy phrase, it works nicely in this situation.

You can build Jobs for Robocopiers to accept parameters by not specifying a source or destination directory either explicitly using the /NOSD and /NODD options or just not including a source and destination directory at all.

Create a task file with no source or destination using the syntax below as an example. The goal of this operation is to transfer all TXT and EXE files from one directory to another.

> robocopy *.txt *.exe /SAVE:backupfiles /QUIT

Because there is no source or destination directory given, this task will never operate on its own.

The job file is automatically produced when you create a job with no source or destination directories by using the /NOSD and /NODD parameters.

/NOSD /NODD /IF *.txt *.exe /DCOPY:DA /COPY:DAT /R:1000000 /W:30 /NOSD /NODD /IF *.txt *.exe

You didn’t provide a source directory with the /NOSD option, and you didn’t include a destination directory with the /NODD option. This job file may be used as a “template” for future tasks.

However, you may supply the source and destination folders by passing “parameters” to this job file.

You may utilize the newly generated job file to transfer files from C:src to C:dst by passing these directories directly on the command line, which will be supplied to the task.

> robocopy /JOB:backupfiles C:src C:dst

Asynchronous Copying (Robocopy /MT) is a kind of asynchronous copying.

Robocopy only handles one file at a time by default. Using the /MT option, you may force robocopy to copy many files at once.

You may set the number of threads robocopy will utilize to copy files using the /MT parameter. The maximum number of characters is 128.

You may use /MT in the following way:

> robocopy C:src C:dst /MT:32

In this situation, I’ve used 32 as a starting point. I recommend beginning at 32 and adjusting the threads based on how your machine and network handle things.

It’s worth noting that if you use /MT, you’ll be unable to utilize /IPG or /EFSRAW. Don’t send the log to the console for improved performance. Use /LOG instead.

Robocopy Scheduling

You may schedule when Robocopy runs in a few different ways.

Using /RH

You may instruct robocopy to only execute at a specified hour using the /RH option. If you have a maintenance window or a period when everyone has left for the day, this is ideal.

In the format HHMM-HHMM, you may provide a start and finish time. For example, to execute robocopy but only between the hours of 5 p.m. and 9 a.m. as indicated by the system clock, type:

> robocopy C:src C:dst /RH:1700-0900

If you run robocopy outside of specified hours, it will display the current time and then wait for the start time to run.

If you schedule a copy, Robocopy will inform you when it will begin.If you schedule a copy, Robocopy will inform you when it will begin.

You must make sure that both times are in 24-hour format and have the same number of digits. The time limit must be more than two minutes.

/RH checks for the start time before the full run by default. If you have a large number of files and think the procedure will take longer than that, you may use the /PF option. /PF causes robocopy to verify the window before copying each file.

How to Use the Task Scheduler

The Log of Output

Robocopy will always provide a log of the output. It’s up to you whether that log is shown on the console via stdout and/or forwarded to a log file.

When it comes to presenting robocopy output, you have a number of possibilities.

Switch Explanation Default Actions Switches That Are Equivalent Notes
/NP There has been no advancement. The display of progress information is disabled. When output is routed to a file, this might be handy.      
/unicode The status output should be shown as unicode text.      
/LOG:file Write the current state to a log file and overwrite it.      
/UNILOG:file Overwrite the status in the unicode log file.      
/LOG+:file Write the current status to a log file and add it to the existing log file.      
/UNILOG+:file Write the current status to a unicode log file and add it to the existing log file.      
/TS The file timestamps for each file handled are shown.      
/FP In the output, basic file names are replaced with complete file pathnames.      
/NS File sizes are not shown.      
/NC Hides the file class “Text Tags” from output (see https://www.uvm.edu/gcd/2015/04/robocopy-file-classes/ for additional details).      
/NFL The names of the files are hidden. However, failures are still recorded. Any files that have been deleted or would be destroyed if the /L option is not used are always recorded.      
/NDL The output of the directory listing is hidden. To make it easier to hunt down problematic files, full file pathnames are output.      
/TEE Output to the console window and a log file      
/NJH There is no job title.      
/NJS There is no job description available.      
/BYTES Sizes in bytes for printing      
/X Report all files, not just those selected & copied      
/V Produce a detailed output log that includes any files that were skipped.      
/ETA Show estimated time of arrival of copied files. See the start time of each file copy and the estimated time of completion based on the observed throughput of previous copies. Times are displayed after the file name in the format HH:MM – > HH:MM (start – > finish).      
/DEBUG Display information about the debug volume      

Using /NJS and /NJH to Limit Log Elements

Robocopy’s output includes two components by default: a job header and a job summary.

At the top, the task header is a standard ROBOCOPY heading.

Header for a robocopy operationHeader for a robocopy operation

The job summary displays the current state of all files and folders, as well as the amount of data transferred and the time the project was completed.

Job description for a robocopierJob description for a robocopier

You may use the /NJH option to hide the job header and the /NJS option to conceal the job summary to hide each of these items. You may use one of these choices or both of them at the same time.

Hide the job title and descriptionHide the job title and description

Changing the Output Log’s Destination to a File

If you need to save The Log of Output, you can redirect it to a text file and/or display it on the console. You can do so using traditional output redirectors like >, >>, PowerShell or the /LOG option.

To redirect The Log of Output to a file using the /LOG option overwriting any existing log file use the syntax /LOG:<filepath> like below. The only output you will receive on the console is the path to the log file.

> robocopy C:src C:dst /LOG:c:file.log Log File : c:file.log

You may use the + operator to maintain the contents of any existing log file and add the results to a file, as illustrated below.

> robocopy C:src C:dst /LOG+:c:file.log Log File : c:file.log

Changing the Output Log’s Destination to a File and Displaying on the Console

If you’d like to save The Log of Output to a file yet also see it on the console, you can use the /TEE option. This option causes robocopy to write the output to the log file while still maintaining the Default Actions of returning output to the console.

robocopy C:src /TEE C:dst /LOG+:c:file.log

Codes of Exit

Like all other command-line utilities, robocopy returns Codes of Exit depending on the results of the execution. We all wish for robocopy to always exit successfully with a 0 but that doesn’t always happen.

All of the exit codes returned by robocopy, as well as their Explanations, are listed here. If the exit code is larger than seven, it means there was at least one failure throughout the execution.

Exit Code Explanation
0 There was no action taken. The source and destination are in sync.
1 At least one file was successfully transferred.
2 There were found to be additional files or folders. Examine the logbook.
3 Codes of Exit 2 and 1 combined.
4 There were some files or folders that were mismatched. Examine the logbook.
5 Codes of Exit 4 and 1 combined.
6 Codes of Exit 4 and 2 combined.
7 Codes of Exit 4, 1 and 2 combined.
8 It was not possible to copy at least one file or directory. The maximum number of retries has been reached. Examine the logbook.
16 The copy failed miserably.

If you run robocopy using a third-party tool, any non-zero exit code may be interpreted as a failure. If it returns 1, adjust the exit code to 0 to avoid this.

The Robocopy “extra” file exit code is a typical return code that indicates the presence of a “extra” file in the destination folder but not in the source folder. This code removes any extras that might prevent the destination from being deleted.

Changing a Batch File’s Exit Code

You can determine the value of the percent ERRORLEVEL percent variable if you’re using a batch file to run robocopy. If it returns 1, use the exit keyword to terminate the script with a value of 0.

> (robocopy <options>) ^& IF %ERRORLEVEL% LEQ 1 exit 0

In a PowerShell script, changing the exit code

If you’re using Start-Process in a PowerShell script, you may use PassThru to return the process that was launched and Wait to wait for robocopy to complete. You may then look for a value of 1 in the ExitCode field. If the exit code is 1, use $host to quit the PowerShell script with a 0. SetShouldExit().

$exitCode = (Start-Process -FilePath ‘robocopy’ -ArgumentList ‘<option>’ -PassThru -Wait).ExitCode if ($exitCode -eq 1) { $host.SetShouldExit(0) }

Typical Errors

If you’re dealing with thousands of files, you’re bound to run across some problems. Here’s a breakdown of Typical Errors I’ve come across

Invalid Parameter Error

When you see an error stating Invalid Parameter Error, this normally means that you’ve tried to pass options to robocopy out of sequence somehow. The robocopy invalid parameter 3 error is the most common, it seems.

When you provide a source or destination directory with spaces and neglect to enclose it with quotes, you’re likely to encounter this error.

Examples of Robocopy

You may either create your own robocopy strings or utilize what others have already learnt! In this part, I’ll go through several examples of how to utilize robocopy for different tasks.

Determine the size of a network folder’s directory.

northendtrooper is a contributor (Reddit)

> robocopy “\MACHINEfileshare” c:dummy /l /xj /e /nfl /ndl /njh /r:0 /mt:64

Delete the contents of the folder quickly (ignoring permissions on subfolders)

pizzasteveo is a contributor (Reddit)

> robocopy c:dummy c:foldertodelete /MIR

Migrating large files is a time-consuming process.

@MySnozzberries is a contributor (Twitter)

This snippet’s objective is to reassign ownership of all files to Administrators. Even though we’re also establishing inheritance, we add an explicit ACE for the Administrators group to give them complete power over all objects recursively.

Finally, we do a complete robocopy copy to the destination with log using DACLs. After that, the log may be examined for any more permission problems or file locks, and a delta sync can be conducted afterwards.

> takeown /F .test /R /A /D Y > icacls .test /grant “Administrators”:(OI)(CI)F /T > robocopy .test .test2 /E /SEC /FP /V /LOG:.temp.log

Force the Administrators group to be the owner of all files and folders recursively. There are methods around this, but this is the most forceful and typically the quickest one.

> takeown /F .test /R /A /D Y

We may now force a new ACE into the DACL for every item once we are the owner. With inheritance enabled and recursively across the route, this gives Administrators complete control.

When a share has CREATOR OWNER with Full Control (which regrettably is even Microsoft’s recommended for things like file user profile storage), the user may deactivate inheritance or delete ACEs at their whim. As a result, the quickest treatment is generally a heavy hand.

> icacls .test /grant “Administrators”:(OI)(CI)F /T

We attempt moving the files to a new place after changing the DACLs on the bulk of files, which is usual for file share migrations. We’re doing this by recursively replicating the items and utilizing the /SEC switch to copy the Data/Attributes/Timestamps/DACLs as well.

Then we log the operation with full paths and for all objects (/V verbose switch) to a log, so we can remediate the <5% of errors that are commonly path length or file lock related and get more granular.

> robocopy .test .test2 /E /SEC /FP /V /LOG:.temp.log

This is a straightforward framework for handling a file sharing migration with little user effect. It also increases IT’s data management capabilities. This becomes a more complicated discussion if a customer has a strong data governance practice where ownership is properly managed at the child folder level, but most customers we find are lucky enough to be using inheritance and group-based ACEs only, so this is the most common situation and fix we start with.

Alternatives to Robocopy

Although Robocopy is an excellent tool, there are many more that are comparable and may be of interest.

Summary

Robocopy is a fantastic tool for copying big groups of files. Whether you’re migrating data, keeping folders in sync, or just need a fast method to precisely copy files, robocopy is an excellent option.

The “robocopy /mir” is a command-line tool that allows users to copy files and directories. The “Ultimate Guide to Robocopy” will provide you with detailed information on the tool and how it can be used.

Frequently Asked Questions

What is better than Robocopy?

A: For a list of other options, please see Robocopy vs. SyncToy

Should I use XCopy or Robocopy?

A: XCopy is the better option.

Is Robocopy faster than XCopy?

A: Robocopy is faster than XCopy.

Related Tags

  • robocopy gui
  • robocopy examples
  • robocopy script
  • robocopy switches
  • robocopy multiple files

Table of Content