RoboCopy (Robust File Copy) is a command-line file copying tool in Windows. It is designed for reliable copying or mirroring of directories anywhere the computer has access, including local drives, removable drives, Local Area Network, remote servers, and in the process ensures that all file properties and permissions stay intact
Mirror Sample Copy:
Robocopy “\fs1\c$\Docuware Web Baskets” “E:\DWStorage2\WebTrays” /MIR /FFT /Z /XA:H /W:5
Robocopy Syntax and Examples
robocopy source destination [file [file] ... ] [parameters]
- source: specifies source folder. You can use drive:\path or \\server\share\path here.
- destination: specifies destination folder. You can use drive:\path or \\server\share\path here.
- file: Files to process. Wildcard characters are supported (* match any sequence of characters, ? : match a single character)
- parameters: Command-line switches you wish to use. You can find the entire list at the end of this post.
Example 1: A simple Robocopy command looks like this:
robocopy C:\Folder1 C:\Backup or robocopy \\sourceserver\path \\destinationserver\path
This command will copy all files in C:\Folder1 to C:\Backup. Sub-folders are excluded. To recursively copy all files and sub-folders, use this command:
robocopy C:\Folder1 C:\Backup /E
Example 2: Copy a single file:
robocopy C:\Folder1 C:\Backup myfile.xlsx
Example 3: Copy only a specific file type from source to destination:
robocopy C:\Folder1 C:\Backup *.docx /E
Example 4: Mirror source folder to destination folder:
robocopy C:\Folder1 C:\Backup /MIR
This command will mirror C:\Folder1 to C:\Backup. While doing so, it will delete any file(s)/folder(s) in the destination folder that’s not present in source.
Example 5: Mirror folders, while preserving all pre-existing files and folders in destination.
robocopy C:\Folder1 C:\Backup /MIR /XX
For preserving specific file or folder use /XF (file) or /XD (folder) parameter.
robocopy C:\Folder1 C:\Backup /MIR /XD "C:\Backup\Old"
Example 6: Copy only those files and folders that exists in destination, ignore others:
robocopy C:\Folder1 C:\Backup /S /XL
Example 7: Copy files from source to destination, skipping files already existing in the destination.
robocopy C:\Folder1 C:\Backup /S
This can be useful to save time as well as to prevent loss of existing file data/properties.
Example 8: List files of specific size:
robocopy C:\Folder1 C:\Backup /MAX:33554432 /L
This will list files larger than 32MB. Use
/MIN for smaller than 32MB files.
Example 9: Copy only those files that are older/newer than specified days:
robocopy C:\Folder1 C:\Backup /E /MINAGE:7
This command copies only those files that are older than 7 days. To select only newer files use
Example 10: Mirror folders by enabling resume function, ignore hidden files, and reduce wait time between failures:
robocopy robocopy C:\Folder1 \\DestinationServer\Folder1 /MIR /Z /XA:H /W:5
/Z : Enables resume of while from without starting from beginning.
/XA:H : Ignore Hidden files.
/W:5 : Reduces wait time between failures to 5 seconds instead of the 30 second default.
Example 11: Monitor and automatically synchronize on change in source:
robocopy C:\Folder1 C:\Backup /MON:1 /R:10
This command re-saves every time a change is made. Increase value of
/MON to change number of changes before sync is performed.
/R is used to specify retries.
Example 12: Enable multi-threaded support:
robocopy \\sourceserver\share\path C:\Backup /MIR /MT[:n]
In this command, n instructs Robocopy to do multi-threaded copies with n threads.
Robocopy copies files and folders in multi-threaded operation by default, with 8 threads in one go. If you want, you can increase its value using
Example 13: Log only errors into a text file:
robocopy C:\Folder1 C:\Backup /NFL /NDL /NJH /NJS /NS /NC /NP >> log.txt
Robocopy Switches and What They Do
Copy options: /S : Copy sub-folders. /E : Copy sub-folders, including empty sub-folders. /Z : Copy files with resume support. /B : Copy files in Backup mode. /SL: Copy symbolic links instead of the target. /ZB : Copy files using resume support; if access denied use Backup mode. /EFSRAW : Copy encrypted files using EFS RAW mode. /LEV:n : Copy only top n levels of the source folder tree. /DCOPY:T : Copy Folder Timestamps. /COPY:copyflag[s] : Specifiy what file information to copy. Copyflags: D=Data, A=Attributes, T=Timestamps, S=Security=NTFS ACLs, O=Owner info, U=Auditing info. /COPYALL : Copy all file information. /NOCOPY : Copy no file information. /SECFIX : Fix all files security. /TIMFIX : Fix all files time. /PURGE : Delete destination files/folders that no longer exist in source. /MIR : Mirror folder structure. /MOV : Move files. /MOVE : Move files and folders. /A+:[RASHCNET] : Add attributes to destination files. /A-:[RASHCNET] : Remove attributes from destination files. /CREATE : Create folder structures and zero-length files only. /FAT : Create destination files using 8.3 FAT file names only. /256 : Disable very long path (> 256 characters support). /MON:n : Monitor source, and run again when more than n changes seen. /MOT:m : Monitor source; and run again in m minutes Time, if changed. /RH:hhmm-hhmm : Run Hours - times when new copies may be started. /PF : Check run hours on a Per File basis. /IPG:n : Inter-Packet Gap (ms) to free bandwidth on slow lines. File Selection Options: /A : Files with Archive attribute set. /M : Files with the Archive attribute and remove it. /IA:[RASHCNETO] : Include files with specific attributes set. /XA:[RASHCNETO] : Exclude files with specific attributes set. /XF file [file]... : Exclude Files matching given names/paths/wildcards. /XD dirs [dirs]... : Exclude folders matching given names/paths. /XC : Exclude Changed files. /XN : Exclude Newer files. /XO : Exclude Older files. /XX : Exclude extra files present in destination folder but not in source. This will prevent deletion of existing files in destination folder. /XL : Exclude files and folders present in source but not destination. This switch will prevent new files being added to the destination /IS : Overwrite existing files even if they are same. /IT : Include files with identical size and timestamp, but different attribute settings. /MAX:n : Exclude files bigger than n bytes. /MIN:n : Exclude files smaller than n bytes. /MAXAGE:n : Exclude files older than n days/date. /MINAGE:n : Exclude files newer than n days/date. /MAXLAD:n : Exclude files unused since n days. /MINLAD:n : Exclude files used since n days. /XJ : Exclude Junction points /FFT : FAT File Times (2-second granularity. /DST : Compensate for one-hour DST time differences. /XJD : Exclude Junction points for Folders. /XJF : Exclude Junction points for Files. Retry Options: /R:n : Number of Retries on failed copies: default 1 million. /W:n : Wait n time between retries: default is 30 seconds. /TBD : Wait for sharenames to be defined. Logging Options: /L : List only. /X : Report all extra files. /V : Verbose output. /TS : Include source file Time Stamps. /FP : Include Full Pathname of files. /BYTES : Print file sizes as bytes. /NS : Don't log file sizes. /NC : Don't log file classes. /NFL : Don't log file names. /NDL : Don't log folder names. /NP : Don't show progress of operation. /ETA : Show Estimated Time of Arrival of copied files. /LOG:file : Output status to a LOG file. Overwrite existing file /LOG+:file : Append existing output status to an existing LOG file. /UNILOG:file : Output status to a Unicode LOG file. Overwrite existing file /UNILOG+:file : Append existing output status to an existing Unicode LOG file. /TEE : Output to console window and log file. /NJH : Don't output Job Header. /NJS : Don't output Job Summary. Job Options: /JOB:jobname : Take parameters from specified job file. /SAVE:jobname : Save parameters to a specific job file. /QUIT : QUIT after processing. /NOSD : NO Source Folder is specified. /NODD : NO Destination Folder is specified. /IF : Include the following Files.