Monday, November 28, 2022
HomePowershellFinal Information with Examples — LazyAdmin

Final Information with Examples — LazyAdmin

Robocopy is a superb command-line utility that’s used to repeat, mirror, or transfer massive quantities of knowledge rapidly and effectively from one location to a different. The ability of Robocopy is that it comes with tons of choices/switches that you need to use to fine-tune and optimize the copy motion.

However all these attainable choices are additionally the frequent drawback with Robocopy. You most likely don’t use it day by day, so which switches (choices) do you could use? How did we copy additionally the NTFS permissions or skip the empty folders?

On this article, we’re going to try Robocopy with the assistance of generally used examples. What are the perfect practices? And the way do you pace up your copy motion?

The Fundamentals

Earlier than we deep dive into Robocopy and look into all of the choices, let’s first begin with the fundamentals. The primary and most vital to know is that you simply run Robocopy in a take a look at mode with /L. This may record the end result with out truly copying or eradicating any information or folders.

Robocopy "D:take a look at information" "F:lab" /L
test mode

For those who take a look at the outcomes, you will note which information or folders will probably be copied, eliminated, or skipped. If you find yourself new to Robocopy, utilizing the /L parameter first is admittedly a good suggestion to test if the outcomes are as anticipated.

Copying all Recordsdata

While you use Robocopy with none switches, it can copy solely the information from the given location to the vacation spot. It received’t copy any subfolders from the given listing, solely the information with out NTFS permissions or proprietor data. All you could do is specify the supply folder and vacation spot folder:

Robocopy "D:take a look at information" "F:lab"
Robocopy default choices

Copy all Recordsdata and Folders

To repeat all information and folders with Robocopy, we might want to specify the parameter /E. This may copy all information and folders from the given listing. For those who additionally wish to copy all attributes as properly, for instance, NTFS permissions or proprietor attributes, then additionally add the /COPYALL parameter as properly:

Robocopy "D:take a look at information" "F:lab" /E /COPYALL
robocopy copy all files and folders
robocopy copy all information and folders

Transfer Recordsdata

When you could transfer information from one location to a different, then you need to use the /mov parameter in Robocopy. This may copy all of the information, not the subfolders, to the vacation spot location and as soon as accomplished delete the information from the supply location.

Personally, I’m not an enormous fan of utilizing the /mov or /transfer parameters. As a result of if something goes fallacious with the copy motion, you additionally don’t have the supply information anymore. So be sure to take a look at the outcomes first with the /L parameter.

Robocopy "D:testfiles" "c:temptestfiles" /mov

When utilizing /mov alone, it received’t copy the file attributes, like NTFS permissions. So that you may wish to use the /COPYALL parameter as properly.

Transfer Recordsdata and Folders

To maneuver additionally the folders we are able to use the parameter /transfer, which must also transfer the subfolders from the listing. It is advisable to mix this with the /E parameter to undergo all of the subfolders, in any other case, solely the contents of the principle folder are moved.

Robocopy "D:testfiles" "c:temptestfiles" /transfer /e /copyall

The distinction with /mov /e is that this may go away the empty folders behind within the supply listing, the place /transfer /e additionally deletes the subfolders as soon as they’re copied.

Robocopy Mirror

While you wish to mirror an entire listing, then you need to use the Robocopy mirror parameter. Mirror will make it possible for the vacation spot folder is totally the identical because the supply.

Good to know is that if you happen to add or take away a file within the vacation spot folder, then this received’t be added to the supply. This mirror solely from the supply to the vacation spot


Don’t use Robocopy mirror as a backup resolution. If a file is deleted within the supply then it can routinely be delete on the vacation spot as properly. So this isn’t a backup resolution!

# Mirror information
Robocopy "D:testfiles" "c:temptestfiles" /mir
Robocopy mirror
Robocopy mirror

If we take a look at the outcomes you will note the road Choices. This reveals which Robocopy switches are used. As you’ll be able to see /E and /Purge are routinely added. Which means that /MIR can even mirror all subdirectories and purge (delete) any information within the vacation spot listing that don’t longer exist within the supply.

Robocopy Switches

As talked about at first, the Robocopy command comes with plenty of switches that you need to use. I’m not going to completely clarify every of them, however beneath you’ll find essentially the most generally used switches that you need to use for Robocopy. You may get all data by typing robocopy /?

Copy Choices

Possibility Description
/S copy Subdirectories, however not empty ones.
/E copy subdirectories, together with Empty ones.
/LEV:n solely copy the highest n LEVels of the supply listing tree.
/Z copy information in restartable mode.
/B copy information in Backup mode.
/ZB use restartable mode; if entry denied use Backup mode.
/J copy utilizing unbuffered I/O (advisable for big information).
/COPY:copyflag[s] what to COPY for information (default is /COPY:DAT).
(copyflags : D=Knowledge, A=Attributes, T=Timestamps, X=Skip alt information streams).
(S=Safety=NTFS ACLs, O=Proprietor information, U=aUditing information).
/SEC copy information with SECurity (equal to /COPY:DATS).
/COPYALL COPY ALL file information (equal to /COPY:DATSOU).
/NOCOPY COPY NO file information (helpful with /PURGE).
/SECFIX FIX file SECurity on all information, even skipped information.
/TIMFIX FIX file TIMes on all information, even skipped information.
/PURGE delete dest information/dirs that now not exist in supply.
/MIR MIRror a listing tree (equal to /E plus /PURGE).
/MOV MOVe information (delete from supply after copying).
/MOVE MOVE information AND dirs (delete from supply after copying).
/A+:[RASHCNET] add the given Attributes to copied information.
/A-:[RASHCNET] take away the given Attributes from copied information.
/CREATE CREATE listing tree and zero-length information solely.
/MON:n MONitor supply; run once more when greater than n modifications seen.
/MOT:m MOnitor supply; run once more in m minutes Time, if modified.
/RH:hhmm-hhmm Run Hours – instances when new copies could also be began.
/MT[:n] Do multi-threaded copies with n threads (default 8). n have to be at the least 1 and never higher than 128.
This feature is incompatible with the /IPG and /EFSRAW choices.
Redirect output utilizing /LOG possibility for higher efficiency.
/DCOPY:copyflag[s] what to COPY for directories (default is /DCOPY:DA).
(copyflags : D=Knowledge, A=Attributes, T=Timestamps, E=EAs, X=Skip alt information streams).
/NODCOPY COPY NO listing information (by default /DCOPY:DA is finished).
/NOOFFLOAD copy information with out utilizing the Home windows Copy Offload mechanism.
/COMPRESS Request community compression throughout file switch, if relevant.
Robocopy Switches

File Choice Choices

Possibility Description
/A copy solely information with the Archive attribute set.
/M copy solely information with the Archive attribute and reset it.
/IA:[RASHCNETO] Embody solely information with any of the given Attributes set.
R – Learn solely
A – Archive
S – System
H – Hidden
C – Compressed
N – Not content material listed
E – Encrypted
T – Short-term
/XA:[RASHCNETO] eXclude information with any of the given Attributes set.
/XF file [file]… eXclude Recordsdata matching given names/paths/wildcards.
/XD dirs [dirs]… eXclude Directories matching given names/paths.
/XC eXclude Modified information.
/XN eXclude Newer information.
/XO eXclude Older information.
/XX eXclude eXtra information and directories.
/XL eXclude Lonely information and directories.
/MAX:n MAXimum file dimension – exclude information larger than n bytes.
/MIN:n MINimum file dimension – exclude information smaller than n bytes.
/MAXAGE:n MAXimum file AGE – exclude information older than n days/date.
/MINAGE:n MINimum file AGE – exclude information newer than n days/date.
/MAXLAD:n MAXimum Final Entry Date – exclude information unused since n.
/MINLAD:n MINimum Final Entry Date – exclude information used since n.
(If n < 1900 then n = n days, else n = YYYYMMDD date).
/DST compensate for one-hour DST time variations.
/XJ eXclude symbolic hyperlinks (for each information and directories) and Junction factors.
/XJD eXclude symbolic hyperlinks for Directories and Junction factors.
/XJF eXclude symbolic hyperlinks for Recordsdata.
/IM Embody Modified information (differing change instances).
Robocopy File Choice Switches

Retry Choices

Possibility Description
/R:n variety of Retries on failed copies: default 1 million.
/W:n Wait time between retries: default is 30 seconds.
/REG Save /R:n and /W:n within the Registry as default settings.
/TBD Watch for share names To Be Outlined (retry error 67).
/LFSM Function in low free area mode, enabling copy pause and resume (see Remarks).
/LFSM:n[KMG] /LFSM, specifying the ground dimension in n [K:kilo,M:mega,G:giga] bytes.
Robocopy Retry Switches

Robocopy Examples

As you’ll be able to see there are plenty of switches that you need to use with Robocopy. One of the best ways to study and perceive the robocopy utility is by examples in my view. Under you’ll find among the mostly used robocopy instructions.

Robocopy Single File

Despite the fact that robocopy is primarily designed to repeat massive quantities of knowledge in a sturdy method, it’s attainable to repeat a single file with robocopy. To do that you will have to specify the file title as a filter:

robocopy d:testfiles c:tempdst "file-name-to-copy.txt"
robocopy single file
robocopy single file

Copy Recordsdata by Sort

In Robocopy, we are able to filter which information to repeat utilizing wildcards and filenames. This enables us to additionally filter the information on file kind. For instance, to repeat solely the log information from the given listing, we are able to filter on the extension .log utilizing the wildcard *:

robocopy d:testfiles c:tempdst *.log
copy by file type

As you’ll be able to see within the screenshot above, I’ve added the choice /s. This can even copy the .log information from the subdirectories. It received’t copy subdirectories that don’t have a .log file.

You may also specify a number of information sorts, merely go away an area between the information sorts:

robocopy d:testfiles c:tempdst *.log *.txt

Exclude File Sort

Excluding file sorts in Robocopy is finished with the /xf swap. We will use wildcards (* and ?) to specify the file sorts that we wish to exclude. Separate a number of file sorts with an area between them.

The instance beneath copies all information, besides log and txt information:

robocopy d:testfiles c:tempdst /xf *.log *.txt
robocopy Exclude File Type
Robocopy Exclude File Sort

We will see within the outcomes that 6 information had been skipped and 12 information copied.

Copy Recordsdata with a Filter

Apart from file sorts, we are able to additionally filter on file names or file attributes with Robocopy. The precept of filtering in filenames is much like filtering on file sorts. We will use wildcards (* and ?) to filter the a part of the filenames.

For instance, to filter all information the place the title begins with log:

robocopy d:testfiles c:tempdst log*
copy files with filter

It’s additionally attainable to filter the information that you simply wish to copy primarily based on an attribute. We will use /IA to repeat solely the information with a sure attribute or /XA to exclude information with a particular attribute.

For instance, to incorporate or exclude information which might be marked Learn-Solely:

# Exclude all information which might be read-only
robocopy d:testfiles c:tempdst /XA:R

# Copy solely the read-only information
robocopy d:testfiles c:tempdst /IA:R

You possibly can mix all of the filter choices if you need. The instance beneath copies all information that include the title sep, because the extension .log and isn’t marked read-only.

robocopy d:testfiles c:tempdst *sep* *.log /XA:R

Copy Contents with out Empty Directories

Copying empty folders will not be at all times wished. To exclude the empty folders we are able to use the swap /s. This fashion empty folders received’t be copied:

robocopy d:testfiles c:tempdst /s

Robocopy Exclude Folder

Identical to information, we are able to additionally exclude folders with Robocopy. For this, we will probably be utilizing the swap /XD adopted by the folder or folders that we wish to exclude. We can even be utilizing the /E swap to repeat all different subfolders from the listing:

robocopy d:testfiles c:tempdst /e /xd "folder a" "folder c"
robocopy exclude folders
robocopy exclude folders

Copy primarily based on File Age

Filtering out information primarily based on age can also be a typical technique used with Robocopy. We will use the switches /MINAGE and /MAXAGE for filtering. /MAXAGE is for instance helpful while you wish to copy solely the information which might be a few days previous. The age can solely be laid out in days.

# Copy information which might be created final week
robocopy d:testfiles c:tempdst /MAXAGE 7

Or while you wish to transfer all information which might be older than a 12 months you are able to do:

# Transfer all information which might be extra then a 12 months previous
# NOTE - This may DELETE the information from the supply!
robocopy d:testfiles c:tempdst /MINAGE 365 /MOVE /E

Apart from file age, you may as well filter the information primarily based on the final entry date the file is accessed. For this use the switches /MINLAD and /MAXLAD.

Copy primarily based on File Dimension

While you wish to copy all information massive than 10Mb or information solely information {that a} much less 1Mb, then you need to use the Robocopy swap /max and /min. The file dimension is laid out in bytes.

# Copy solely information which might be bigger then 10Mb
robocopy d:testfiles c:tempdst /MIN:10000000
robocopy filter file size

Embody Safety (permissions)

When copying information to a different NTFS formatted drive, we are able to additionally copy the file permissions with /sec. For those who use /copyall, then safety can even be copied, /sec is identical as /copy:dats (Data, Attributes, Time stamps, NTFS Entry management record)

# Copy file together with the NTFS permissions
robocopy d:testfiles c:tempdst /SEC

If the vacation spot isn’t an NTFS formatted drive, then the permissions will probably be misplaced.

Copy All Recordsdata and Folder Data

The /copyall swap in Robocopy solely specifies which attributes to repeat from the information (all the pieces). By default, solely the Knowledge and Attributes of folders are copied. You may also copy the timestamps of the folders, for this you will have to specify /dcopy:dat.

If we mix the 2, then we are able to copy all information and folder data:

# Copy all file and folder data
robocopy d:testfiles c:tempdst /copyall /dcopy:dat

Copy to Community Path

When you could copy information and folders to a different server (community path) then there are a number of suggestions with regards to utilizing Robocopy. The issue with copying information over the community is that even a brief community interruption could cause regular copy actions to start out over.


It’s suggest to make use of full UNC paths when copying information over the community as an alternative of utilizing mapped drives.

Apart from interruption, we additionally want to remember bandwidth limitations. For those who run Robocopy with a multi-threading throughout enterprise hours on the file server, then there’s a likelihood that your customers begin complaining. To restrict bandwidth utilization we are able to use /ipg:n. An alternative choice is to specify the hours between which Robocopy can run with /RH

So to optimize community switch with Robocopy we are able to use the next switches:

Possibility Description
/RH:hhmm-hhmm Specify the time between the job can run
/ZB Copy information in restartable mode, if entry is denied, restart the copy motion in backup mode. This may override information and folder permissions that may block entry.
/MT:n Multi-Threaded will pace up the file switch, n = default 8
/IPG:n Restrict bandwidth utilization by telling Robocopy to attend n milliseconds
/R:n Specify the variety of retries
/W:n Specifies how lengthy to attend between the retry
Robocopy Community Switch

If you wish to run the Robocopy job throughout enterprise hours, then you definately may wish to restrict bandwidth utilization with /ipg. Robocopy copies the info in blocks of 64KB, the ipg swap provides a brief pause in milliseconds between every block, making room for different information. I received’t go absolutely in-depth about the way it works however /ipg:25 limits the required bandwidth by 50%. And /ipg:9 about 25%.

# Copy all file and folders to community share and restrict throughput by 50%
robocopy d:testfiles la-srv-lab02temp$dst /copyall /e /ipg:25 /zb /r:3 /w:1

One other good technique when transferring information over the community is to schedule it after enterprise hours. With Robocopy we are able to specify the time between the job can run. For this, we’re going to use the /RH swap.

robocopy d:testfiles la-srv-lab02temp$dst /copyall /e /rh:1900-0600 /zb /r:3 /w:1
robocopy network path
Schedule Robocopy job

You possibly can see within the screenshot above that the job is paused till 19:00.

Enhance Copy Velocity with Multi-Threading

Multi-Threading lets you copy extra information concurrently. By default, it’s set to eight, however you’ll be able to improve it to 128. So let’s set it as excessive as attainable, proper? Properly, there’s extra to it. How excessive you’ll be able to set Multi-Threading in Robocopy will depend on the supply and vacation spot sources. The extra disks (and IOPS) you will have, the extra information the server can concurrently deal with. But additionally CPU, reminiscence, and bandwidth all have to be taken into consideration.

Generally, we are able to say, when you’ve got plenty of small information, then it’s value rising the multi-threadings. When you will have main massive information, then it is perhaps higher to decrease the variety of threads.

I did a fast take a look at with 2500 information, copying them from one SSD disk to a different on the identical gadget:

  • 8 Threads > 0.72 seconds
  • 16 Threads > 0.31 seconds
  • 128 Threads > 0.48 seconds

The numbers above are to offer you an thought. When you could copy a considerable amount of information then it’s a good suggestion to do some exams on what the optimum quantity is in your atmosphere.

Robocopy Log

By default, Robocopy outputs the log instantly into the console. Nice for small copy jobs, however when transferring a lot of information, you may wish to save the outcomes to a log. One other good thing about utilizing the log file is that Robocopy will probably be sooner.

Possibility Description
/LOG:<path> Specify the log file to avoid wasting the data to
/LOG+: Append the end result to an present log file
/ts Embody the supply file time stamp within the log output
/tee Output to log and console
/fp Embody the complete path of the information within the log
/v Verbose, output additionally skipped information
Robocopy log choices

It’s even attainable to find out what to log or not, like don’t log the directories for instance. You will discover all of the choices right here within the documentation.

Utilizing log information is admittedly advisable if you find yourself operating Robocopy unattended. It offers you the power to test for any errors afterward, even in case the console is closed. It’s additionally a good suggestion the use the log information when transferring plenty of information. This fashion you’ll be able to simply test for any copy points which have occurred.

Just be sure you additionally specify the file title, not solely the log file location.

robocopy d:testfiles la-srv-lab02temp$dst /copyall /e /log:c:tempdst.log /zb /r:3 /w:1


You would not have the Handle Auditing person proper error

When utilizing the parameter /COPYALL or /COPY:U you could run the command immediate (or Home windows Terminal) as administrator.

Speedup Robocopy

To hurry as much as copy course of it’s greatest to redirect the output to the log information. Outputting it to the console will decelerate the copy course of. Additionally when you’ve got a steady and dependable community connection, then you’ll be able to pass over the /z (restartable mode) swap. Enhance the threads to 16 with /mt:16, setting it too excessive may trigger latency to happen.

Wrapping Up

When you could copy massive quantities of knowledge, then Robocopy is among the greatest instruments to make use of. It comes with plenty of choices, as you will have seen, that can assist you with copying information in essentially the most environment friendly method. When working with massive information units, just remember to take a look at your instructions with the /L swap earlier than operating them on manufacturing information.

I hope you discovered this text helpful, when you’ve got any questions, simply drop a remark beneath.



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments