RoboCopy - Ultimate Guide With Examples - LazyAdmin
RoboCopy - Ultimate Guide With Examples - LazyAdmin
RoboCopy - Ultimate Guide With Examples - LazyAdmin
Robocopy is a great command-line utility that is used to copy, mirror, or move large
amounts of data quickly and efficiently from one location to another. The power of
Robocopy is that it comes with tons of options/switches that you can use to fine-tune and
optimize the copy action.
But all those possible options are also the common problem with Robocopy. You probably
don’t use it daily, so which switches (options) do you need to use? How did we copy also
the NTFS permissions or skip the empty folders?
In this article
The Basics
Copying all Files
Copy all Files and Folders
Move Files
Move Files and Folders
Robocopy Mirror
Robocopy Switches
Copy Options
File Selection Options
Retry Options
Robocopy Examples
Robocopy Single File
Copy Files by Type
Exclude File Type
Copy Files with a Filter
Copy Contents without Empty Directories
Robocopy Exclude Folder
Copy based on File Age
Copy based on File Size
Include Security (permissions)
Copy All Files and Folder Information
Copy to Network Path
Increase Copy Speed with Multi-Threading
Robocopy Log
FAQ
Wrapping Up
In this article, we are going to take a look at Robocopy with the help of commonly used
examples. What are the best practices? And how do you speed up your copy action?
The Basics
Before we deep dive into Robocopy and look into all the options, let’s first start with the
basics. The first and most important to know is that you run Robocopy in a test mode with
/L . This will list the result without actually copying or removing any files or folders.
When you use Robocopy without any switches, it will copy only the files from the given
location to the destination. It won’t copy any subfolders from the given directory, only the
files without NTFS permissions or owner information. All you need to do is specify the
source folder and destination folder:
To copy all files and folders with Robocopy, we will need to specify the parameter /E . This
will copy all files and folders from the given directory. If you also want to copy all
attributes as well, for example, NTFS permissions or owner attributes, then also add the
/COPYALL parameter as well:
1. Robocopy "D:\test files" "F:\lab" /E /COPYALL Copy
Move Files
When you need to move files from one location to another, then you can use the /mov
parameter in Robocopy. This will copy all the files, not the subfolders, to the destination
location and once completed delete the files from the source location.
Personally, I am not a big fan of using the /mov or /move parameters. Because if anything
goes wrong with the copy action, you also don’t have the source files anymore. So make
sure you test the results first with the /L parameter.
To move also the folders we can use the parameter /move , which should also move the
subfolders from the directory. You need to combine this with the /E parameter to go
through all the subfolders, otherwise, only the contents of the main folder are moved.
The difference with /mov /e is that this will leave the empty folders behind in the source
directory, where /move /e also deletes the subfolders once they are copied.
Robocopy Mirror
When you want to mirror a complete directory, then you can use the Robocopy mirror
parameter. Mirror will make sure that the destination folder is completely the same as the
source.
Good to know is that if you add or remove a file in the destination folder, then this won’t
be added to the source. This mirror only from the source to the destination
Note
Don’t use Robocopy mirror as a backup solution. If a file is deleted in the source then it will
automatically be delete on the destination as well. So this isn’t a backup solution!
If we look at the results you will see the line Options. This shows which Robocopy switches
are used. As you can see /E and /Purge are automatically added. This means that /MIR
will also mirror all subdirectories and purge (delete) any files in the destination directory
that don’t longer exist in the source.
Robocopy Switches
As mentioned in the beginning, the Robocopy command comes with a lot of switches that
you can use. I am not going to fully explain each of them, but below you will find the most
commonly used switches that you can use for Robocopy. You can get all information by
typing robocopy /?
Copy Options
Option Description
/LEV:n only copy the top n LEVels of the source directory tree.
Option Description
/MOVE MOVE files AND dirs (delete from source after copying).
/MON:n MONitor source; run again when more than n changes seen.
/MT[:n] Do multi-threaded copies with n threads (default 8). n must be at least 1 and
not greater than 128.
Option Description
/NOOFFLOAD copy files without using the Windows Copy Offload mechanism.
Robocopy Switches
Option Description
/M copy only files with the Archive attribute and reset it.
/XJ eXclude symbolic links (for both files and directories) and Junction points.
Retry Options
Option Description
/LFSM Operate in low free space mode, enabling copy pause and resume (see Remarks).
Robocopy Examples
As you can see there are a lot of switches that you can use with Robocopy. The best way to
learn and understand the robocopy utility is by examples in my opinion. Below you will
find some of the most commonly used robocopy commands.
Even though robocopy is primarily designed to copy large amounts of data in a robust
way, it’s possible to copy a single file with robocopy. To do this you will need to specify the
file name as a filter:
In Robocopy, we can filter which files to copy using wildcards and filenames. This allows us
to also filter the files on file type. For example, to copy only the log files from the given
directory, we can filter on the extension .log using the wildcard * :
You can also specify multiple files types, simply leave a space between the files types:
Excluding file types in Robocopy is done with the /xf switch. We can use wildcards (* and
?) to specify the file types that we want to exclude. Separate multiple file types with a
space between them.
The example below copies all files, except log and txt files:
1. robocopy d:\testfiles c:\temp\dst /xf *.log *.txt Copy
We can see in the results that 6 files were skipped and 12 files copied.
Besides file types, we can also filter on file names or file attributes with Robocopy. The
principle of filtering in filenames is similar to filtering on file types. We can use wildcards (*
and ?) to filter the part of the filenames.
For example, to filter all files where the name starts with log:
You can combine all the filter options if you want. The example below copies all files that
contain the name sep, as the extension .log and isn’t marked read-only.
Just like files, we can also exclude folders with Robocopy. For this, we will be using the
switch /XD followed by the folder or folders that we want to exclude. We will also be using
the /E switch to copy all other subfolders from the directory:
Filtering out files based on age is also a common method used with Robocopy. We can
use the switches /MINAGE and /MAXAGE for filtering. /MAXAGE is for example useful when
you want to copy only the files that are a couple of days old. The age can only be specified
in days.
Or when you want to move all files that are older than a year you can do:
1. # Move all files that are more then a year old Copy
2. #
3. # NOTE - This will DELETE the files from the source!
4. #
5. robocopy d:\testfiles c:\temp\dst /MINAGE 365 /MOVE /E
Besides file age, you can also filter the files based on the last access date the file is
accessed. For this use the switches /MINLAD and /MAXLAD .
When you want to copy all files large than 10Mb or files only files that a less 1Mb, then
you can use the Robocopy switch /max and /min . The file size is specified in bytes.
When copying files to another NTFS formatted drive, we can also copy the file permissions
with /sec . If you use /copyall , then security will also be copied, /sec is the same as
/copy:dats (Data, Attributes, Time stamps, NTFS Access control list)
If the destination isn’t an NTFS formatted drive, then the permissions will be lost.
The /copyall switch in Robocopy only specifies which attributes to copy from the files
(everything). By default, only the Data and Attributes of folders are copied. You can also
copy the timestamps of the folders, for this you will need to specify /dcopy:dat .
If we combine the two, then we can copy all files and folder information:
When you need to copy files and folders to another server (network path) then there are a
few tips when it comes to using Robocopy. The problem with copying files over the
network is that even a short network interruption can cause normal copy actions to start
over.
Tip
It’s recommend to use full UNC paths when copying files over the network instead of using
mapped drives.
Besides interruption, we also need to keep in mind bandwidth limitations. If you run
Robocopy with a multi-threading during business hours on the file server, then there is a
chance that your users start complaining. To limit bandwidth usage we can use /ipg:n .
Another option is to specify the hours between which Robocopy can run with /RH
So to optimize network transfer with Robocopy we can use the following switches:
Option Description
/RH:hhmm-
Specify the time between the job can run
hhmm
Copy files in restartable mode, if access is denied, restart the copy action
/ZB in backup mode. This will override files and folder permissions that might
block access.
Option Description
If you want to run the Robocopy job during business hours, then you might want to limit
bandwidth usage with /ipg . Robocopy copies the data in blocks of 64KB, the ipg switch
adds a short pause in milliseconds between each block, making room for other data. I
won’t go fully in-depth about how it works but /ipg:25 limits the required bandwidth by
50%. And /ipg:9 about 25%.
1. # Copy all file and folders to network share and limit throughput by 50% Copy
2. robocopy d:\testfiles \\la-srv-lab02\temp$\dst /copyall /e /ipg:25 /zb /r:3 /w:1
Another good method when transferring data over the network is to schedule it after
business hours. With Robocopy we can specify the time between the job can run. For this,
we are going to use the /RH switch.
1. Copy
robocopy d:\testfiles \\la-srv-lab02\temp$\dst /copyall /e /rh:1900-0600 /zb /r:3
/w:1
Schedule Robocopy job
You can see in the screenshot above that the job is paused until 19:00.
Multi-Threading allows you to copy more files simultaneously. By default, it’s set to 8, but
you can increase it to 128. So let’s set it as high as possible, right? Well, there is more to it.
How high you can set Multi-Threading in Robocopy depends on the source and
destination resources. The more disks (and IOPS) you have, the more files the server can
simultaneously handle. But also CPU, memory, and bandwidth all need to be taken into
account.
In general, we can say, if you have a lot of small files, then it’s worth increasing the multi-
threadings. When you have primary large files, then it might be better to lower the
number of threads.
I did a quick test with 2500 files, copying them from one SSD disk to another on the same
device:
The numbers above are to give you an idea. When you need to copy a large amount of
data then it’s a good idea to do some tests on what the optimal number is for your
environment.
Robocopy Log
By default, Robocopy outputs the log directly into the console. Great for small copy jobs,
but when transferring a large number of files, you might want to save the results to a log.
Another benefit of using the log file is that Robocopy will be faster.
Option Description
/ts Include the source file time stamp in the log output
It’s even possible to determine what to log or not, like don’t log the directories for
example. You can find all the options here in the documentation.
Using log files is really recommended when you are running Robocopy unattended. It
gives you the ability to check for any errors afterward, even in case the console is closed.
It’s also a good idea the use the log files when transferring a lot of data. This way you can
easily check for any copy issues that have occurred.
Make sure that you also specify the file name, not only the log file location.
1. robocopy d:\testfiles \\la-srv-lab02\temp$\dst /copyall /e /log:c:\temp\dst.logCopy
/zb
/r:3 /w:1
FAQ
Speedup Robocopy
To speed up to copy process it’s best to redirect the output to the log files. Outputting it
to the console will slow down the copy process. Also if you have a stable and reliable
network connection, then you can leave out the /z (restartable mode) switch. Increase the
threads to 16 with /mt:16 , setting it too high might cause latency to occur.
Wrapping Up
When you need to copy large amounts of data, then Robocopy is one of the best tools to
use. It comes with a lot of options, as you have seen, to help you with copying data in the
most efficient way. When working with large data sets, make sure that you test your
commands with the /L switch before running them on production data.
I hope you found this article useful, if you have any questions, just drop a comment below.
Subscribe
I hate spam to, so you can unsubscribe at any time.
basics IT
Nov 3, 2023
All required Domain Controller Ports
17 thoughts on “RoboCopy – Ultimate Guide with Examples”
Amol
September 15, 2023 at 07:37 | Reply
Good day,
I need a small help. I am creating one script .bat. my backup and old date deleted
file is run smoothly and also each file generate the time but how to set date and
time can you help me please
set CUR_YYYY=%date:~10,4%
set CUR_MM=%date:~4,2%
set CUR_DD=%date:~7,2%
set CUR_HH=%time:~0,2%
if %CUR_HH% lss 10 (set CUR_HH=0%time:~1,1%)
set CUR_NN=%time:~3,2%
set CUR_SS=%time:~6,2%
set CUR_MS=%time:~9,2%
set SUBFILENAME=%CUR_DD%-%CUR_MM%-
%CUR_YYYY%_%CUR_HH%.%CUR_NN%.%CUR_SS%
AB15-09-2023–_11.01.41.log
Del15-09-2023–_11.01.41.txt
Thanks In Advanced
Amol
Tim
September 2, 2023 at 04:45 | Reply
Hello, this is a great article! It had just what I needed, examples of multiple
parameters on a single command line.
Thank you!
Silverberg
August 29, 2023 at 05:51 | Reply
Hello Rudy! thanks for the comprehensive guide. Last weekend I have copied
across millions of files to another file server using robocopy which took 28 hours.
After another week, I am required to copy across the changes (delta) from the
source and I am planning to use parameters below:
given above command, my question would be – will /MIR overwrite ALL the files or
just copy across the updated/new files?
Reason is there is a time constraint for me to do the copy, and I was hoping that
/MIR will just transfer the new/updated files and folder.
MIR will only copy the changed and new files to the destination. Keep in mind
though that files and folders deleted from the source, wil also be deleted from
the destination.
dan
August 18, 2023 at 18:59 | Reply
RoboCop should update their ABOUT screen from Windows 8 to Windows 10/11.
Also, have the errors (see
https://sourceforge.net/projects/robocoprobocopy/reviews) been corrected?
Roy
July 31, 2023 at 18:35 | Reply
We need to migrate 2 TB of data from one data drive to another (both the drives
are mounted on the same VM) and my question is how can we get an ETA for the
copy operation to complete? We would want to know how long will it take so that
we can schedule a downtime accordingly. I know that there is a /ETA switch that
can be used but that only shows the status of the copy operation for individual
files/directories and not for the copy operation as a whole (it wouldn’t show the
total amount of data out of the 2 TB that has been transferred over and/or is yet to
be transferred). Please suggest.
/ETA will only work when copying files. What I personally would do is a test run.
Run the command for 10 min orso and see how much data is processed. You can
then calculate how long the 2TB will take. This will give you a good estimate
jean_louis
June 5, 2023 at 18:24 | Reply
Seems that /XO doesn’t work when i robocopy files from my desktop to the cloud
(ionos) :
it doesn’t exclude files even if they have the same date/hour ?
if i send twice the same robocopy command … it uploads same files twice
Sorry, I am unfamiliar with Ionos. Might have something to do with the file
system they are using or a timezone issue. Best option would be to contact Ionos
about it.
Calvin
March 30, 2023 at 03:29 | Reply
I am trying to use robocopy where the Source and Destination are in 2 different
AD domain (there is vpn tunnel, but no trust). I do not see a way to specify
credentials in robocopy!
dan
March 14, 2023 at 00:14 | Reply
After DAYLIGHT SAVINGS TIME occurred, my next run of Robocopy seemed to
check on and report on every file, unlike its usual checking process. It took over an
hour whereas it usually takes a minute or so. How come?
Thanks,
Dan
You can use the switch /DST to compensate for the daylight saving time.
dan LazyAdmin
April 1, 2023 at 04:50 | Reply
Hi Rudy,
Thanks for your reply.
I’m wondering why “/DST” isn’t the default for ROBOCOPY. After all, what is the
benefit of ROBOCOPY rechecking every file just because DST occurred? Or more
basic, how did DST cause ROBOCOPY to do all the rechecking in the first place?
Thanks again,
Dan
Freeman
February 14, 2023 at 17:43 | Reply
HI,
How to exclude copying of files without extensions. ?
I Take
/XF *.
do not work
An idea
Thanks
$source = c:\files\
notmatch '\.'})
Love the guide but I find that Robocop Robocopy makes Robocopy almost
foolproof.
Leave a Comment
Name *
Email *
Leave Empty
Notify me of followup comments via e-mail. You can also subscribe without
commenting.
Post Comment
Hey! I'm Ruud. I work as an IT Consultant in the Netherlands and love to write about IT, Microsoft 365, PowerShell
and Smart Home stuff.
Last Articles
1. PowerShell ForEach-Object and ForEach
2. How to Setup UniFi Network
Recommended article
LazyAdmin.nl is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a
means for sites to earn advertising fees by advertising and linking to Amazon.com and other sites. LazyAdmin.nl is compensated for
referring traffic or business to these companies at no expense to you. Your support helps running this website and I genuinely
appreciate it. I always try to make my reviews, articles and how-to's, unbiased, complete and based on my own expierence.