Complete Guide to Robocopy

What is Robocopy?

Robocopy, short for “Robust File Copy,” is a powerful command-line utility in Windows designed for efficiently copying and synchronizing files and directories. It’s built into Windows! Robocopy offers advanced features like multi-threaded copying, the ability to resume interrupted transfers, and options to preserve file attributes and timestamps. It’s especially useful for backing up data, mirroring entire directories, and performing large-scale file migrations with precision and reliability. However, it can be a little daunting to use, especially with the amount of options available.

 

Therefore, I decided to create this guide. Credit for a lot of this goes to the following page as this is where I drew inspiration from. As well as the Microsoft documentation.

How to use Robocopy?

Syntax

robocopy [Source Folder] [Destination Folder] [Files] [Options] 

[Source Folder] – The source folder from which you are copying files/folders.
Can be either a direct path (such as C:\Users\admin\documents) or a network path (such as \\FILESRV01\Share)

[Destination Folder] – The destination folder to which you are copying files/folders.
Can be either a direct path (such as C:\Users\admin\documents) or a network path such as a mapped drive.
Must be a different directory than the [Source Folder]. If the destination does not exist, it will be created.

[Files] – A list of files or a wildcard. By default this is set to use *.*, which means copy all files of all extensions.
For example *.exe would only copy executable (exe) files.

Options

Copy Options

/COPY:flag[s] – What properties of files to copy (default flags used are DAT)
Flags: D=Data, A=Attributes, T=Timestamps,
S=Security=NTFS ACLs, O=Owner info, U=Auditing info

 

/DCOPY:flag[s] – What properties of directories to copy (default flags used are DA)
Flags: D=Data, A=Attributes, T=Timestamps,
E=EAs, X=Skip alt data streams.

 

/COPYALL – Copy ALL file info. Same as using all flags.

/NOCOPY – Copy no file info.

/NODCOPY – Copy no directory info.

/SEC – Copy files with security. Adds “S” flag to default.

/B – Copy files in Backup mode. Essentially bypass NTFS permissions to read contents to create a copy.

/EFSRAW – Copies all encrypted files in EFS RAW mode.

/L – List only – don’t copy, timestamp or delete any files. Can be used for a “dry” run.

/MOV – Move files only (deletes files from source after copying).

/MOVE – Move files and directories (deletes from source after copying).

/SJ – Copies junctions (soft-links) to the destination path instead of link targets.

/SL – Don’t follow symbolic links and instead create a copy of the symbolic link.

Logging Options

/LOG:[file path] – Output status to log file (overwrite if log file exists).

/UNILOG:[file path] – Output status to Unicode Log file (overwrite if log file exists)

/LOG+:[file path] – Output status to LOG file (append).

/UNILOG+:[file path] – Output status to Unicode Log file (append).

/unicode – Display the status output as Unicode text.

/TEE – Output to console window, as well as the log file.

/NP – Does not display % copied.

/TS – Include Source file Time Stamps in the output.

/FP – Include Full Pathname of files in the output.

/NS – Don’t log file sizes.

/NC – Don’t log file classes.

/NFL – Don’t log file names.

/NDL – Don’t log directory names.

/NJH – Don’t write Job Header to log.

/NJS – No Job Summary (Stats aboutt what files were copied, missed, skipped, etc)

/X – Report all extra files, not just those selected & copied.

/V – Produce Verbose output log, showing skipped files.

Source Options

/S – Copy Subfolders.

/E – Copy Subfolders, including Empty Subfolders.

/A – Copy only files with the Archive attribute set.

/M – like /A, but remove Archive attribute from source files.

/LEV:n – Only copy the top n Levels of the source tree.

/MAXAGE:n – Maximum file AGE – exclude files older than n days/date.

/MINAGE:n – Minimum file age – exclude files newer than n days/date.
(If n < 1900 then n = no of days, else n = YYYYMMDD date).

/FFT – Assume FAT File Times (2-second date/time granularity).
Use this when copying files to a Linux NAS or other non-windows file system.

/256 – Turn off very long path (> 256 characters) support.

Destination Options

/A+:[File Attributes] – Set file Attribute(s) on destination files + add.

/A-:[File Attributes] – UnSet file Attribute(s) on destination files – remove.

/FAT – Create destination files using 8.3 FAT file names only.

/CREATE – Create directory tree structure + zero-length files only.

/DST – Compensate for one-hour DST time differences.

/PURGE – Delete destination files/folders that no longer exist in source.

/MIR – Mirror a directory tree – equivalent to /PURGE plus all subfolders (/E)

/SECFIX – Update ACL file security on all files, even skipped files.

Performance Tweaks

/COMPRESS – Request SMB network compression during file transfer, if applicable.

/J – Copy using unbuffered I/O (recommended for large files).

/NOOFFLOAD – Copy files without using the Windows Copy Offload mechanism.

/IPG:[n] – Inter-Packet Gap (ms), to free bandwidth on slow lines. Essentially a bandwidth limiter (See notes).

/MT[:n] – Multithreaded copying, n = no. of threads to use (1-128). Default is 8.

/R:[n] – Number of Retries on failed copies – default is 1 million.

/W:[n] – Wait time between retries – default is 30 seconds.

/REG – Save /R:n and /W:n in the Registry as default settings.

/TBD – Specifies that the system waits for share names to be defined (retry error 67).

Job Options

/JOB:[jobname] – Read parameters from the named JOB file, e.g. multiple /XF files /XD directoriess to exclude.

/SAVE:[jobname] – Save parameters to the named job file, this must be the last option, the command will not be run. Saves as .rcj file.

/NOSD – Does not specify a source in a job file.

/NODD – Does not specify a destination in a job file.

The command-line and job file cannot contain conflicting Source/Destination paths.
In the .RCJ job file, Source/Destination paths can be given as /SD:path and /DD:path
/NOSD and /NODD can be used either on the command line or in the job file.

/QUIT – Quit after processing command line. Does not run the job.

/IF – Include the following Files.

Repeated Copy Options

/MON:n – Monitor source; run again when more than n changes seen.

/MOT:[m] – Monitor source; run again in m minutes Time, if changed.

/RH:[hhmm-hhmm] – Run Hours – e.g. /RH:1800-0200
If the robocopy command is launched outside the given hours it will pause until the next start time.

/PF – Check run hours on a Per File (not per pass) basis.

Advanced Options

/BYTES – Print sizes as bytes.

/DEBUG – Show debug volume information.

/ETA – Show Estimated Time of Arrival of copied files.

/LFSM – Operate in “low free space” mode, enabling copy, pause and resume.

/LFSM:n[KMG] – /LFSM, specifying the floor size in [K:Kilo,M:Mega,G:Giga] bytes. Allows job to pause if destination is down to n amount of space on a volume.

/TIMFIX – FIX file times on all files, even skipped files.

/Z – Copy files in restartable mode (pick up after network or connection drop).

/ZB – Use restartable mode; if access denied use Backup mode. 

Exclude and Include

/XO – Exclude Older – if destination file already exists and is the same date
or newer than the source, don’t overwrite destination.

/XC – Exclude Changed files – if destination file already exists and has been changed don’t overwrite destination.

/XN – Exclude Newer files – if destination file is older than source, don’t overwrite destination. 

/XL – Exclude “Lonely” files and directories (present in source, not destination)
This will prevent any new files being added to the destination.

/XX – Exclude “Extra” files and directories (present in destination, not source)
This will prevent any deletions from the destination. (this is the default setting).

 

/XF [file] [file]… – Exclude Files matching given names/paths/wildcards.

/XD [dirs] [dirs]… – Exclude Directories matching given names/paths.

XF and XD can be used in combination (for example
ROBOCOPY c:\source d:\dest /XF *.dmp “pagefile.sys” /XD “c:\System Volume Information” /S)

 

/IA:[File Attributes] – Include files with any of the given Attributes.

/XA:[File Attributes] – Exclude files with any of the given Attributes.

/IM – Include modified MFT files. The MFT (Master File Table) contains file attributes, filenames and
security permissions. If the MFT timestamp is different then the destination file will be
overwritten even if all the attributes are the same. Same as /copy:DATS. By default robocopy ignores the file attributes and looks only at the file size and modified time.

/IS – Include Same, overwrite files even if they are already the same.

/IT – Include Tweaked files. If any file attribute is different the destination file will is overwritten.

/XJ – Exclude Junction points from source (default setting).

/XJD – Exclude junction points from source directories.

/XJF – Exclude junction points from source files.

/MAX:[n] – Maximum file size – exclude files bigger than n bytes.

/MIN:[n] – Minimum file size – exclude files smaller than n bytes.

 

/MAXLAD:[n] – Maximum Last Access Date – exclude files unused since n.

/MINLAD:[n] – Minimum Last Access Date – exclude files used since n.

(If n < 1900 then n = n days, else n = YYYYMMDD date).

Notes

File Attributes

Any option flags that use FILE ATTRIBUTES will accept any of the following letters, more than one can be used:

R – Read only
A – Archive
S – System
H – Hidden
C- Compressed

N – Not content indexed
E – Encrypted
T – Temporary
O – Offline

Long File Names

When copying a large tree of multiple files and subfolders, it is likely some files will hit or even exceed the NTFS 256 character limit.

Robocopy will accept UNC (Universal Naming Convention) pathnames including long pathnames over 256 charecters long.

 

Bandwidth Limiting

Using the /IPG can help you limit the bandwidth your robocopy job by introducing a delay after a 64KB (512Kb) block of files has been sent. You can calculate the bandwidth limitation you need using the following formula:

D = 512/M

D = Delay in ms (nearest whole number)

M = Desired Bandwidth in Mbps

Or you can use the following chart as a quick guide to see what you should set your delay to for certain bandwidth in bps (Bits per second, not Bytes):

MS of Delay (n) Bandwidth Limitation
1 ms
512 Mbps
2 ms
256 Mbps
5 ms
102.4 Mbps
10 ms
51.2 Mbps
25 ms
20.48 Mbps
50 ms
10.24 Mbps
100 ms
5.12 Mbps
500 ms
≈ 1 Mbps

Please note that these limitation may not be exact as parameters such as MTU can affect the bandwidth as well.

Leave a Comment

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

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