Robocopy Command Tutorial

robocopy or robocopy.exe is a command-line tool used to copy files in Windows operating systems. the robocopy is provided by default for the Windows XP, Windows 7, Windows 8, Windows 10, Windows Server series. What makes the robocopy is the features it provides like multithread higher performance copy or clone operation. The robocopy name comes from the “Robust File Copy” which is created as a replacement for the xcopy command. The robocopy first released with the Windows NY 4.0 Resource Kit and a standard Windows operating system feature with the Windows Vista and Windows Server 2008. Currently, the latest version is 10.0.18 .

Robocopy Features

As a complete copy and backup tool robocopy provides following features abilities.

  • Copy files and folders over network with resume capability
  • Skip NTFS related errors easily without an infinite loop
  • Copy file and folder attributes
  • Copy NTFS permissions, owner, auditing information
  • Copy file and folder timestamps
  • Automatically retry failed copy operations
  • Recursive copy
  • Sync folders
  • Skipping all ready copied or up-to-date files

Display Help Information About Robocopy

The robocopy command or tool provides a lot of different features and options. Help information about these options and features can be displayed with the /? option like below.

robocopy /?
Display Help Information About Robocopy

robocopy Command Syntax

Robocopy command has the following syntax where the SOURCE and DESTINATION are mandatory.

robocopy SOURCE DESTINATION OPTIONS
  • SOURCE is the source location or path where the FILES will be copied from.
  • DESTINATION is the destination location where the FILES will be copied to.
  • OPTIONS is used to configure copy operation. The robocopy command provides a lot of options that can be categorized as File Selection , Retry , Logging , Job . All of them will be provided below.
READ  How To Find Computer Name (Windows, Linux, MacOSX)?

robocopy Copy Options

The copy options are used to specify different actions.

OPTIONDESCRIPTION
/sCopy subdirectories skip empty files
/eCopy subdirectories include empty files
/lev:NCopy N level of the source directories
/bCopy backup mode
/copy:FLAGCopy with the specified FLAG. FLAG can be an attribute, time stamps, owner information, etc.
/secCopy files with security options or attributes
/copyallCopy all file attributes or options
/purgeDelete destination files and directories which do not exist in the source
/mirMirror files and directories
/moveMoves files and directories and delete source
/a+ATTAdd specified attributes to the copied files
/a-ATTRemove specified attributes from the copied files
/createCreate directories and empty files without data
/slDon’t follow symbolic links

robocopy Attributes

The robocopy command provides different options that use the file attributes. These attributes are used to set file attributes or specify files with these attributes. These attributes are also called as RASHCNETO according to their names.

ATTRIBUTEDESCRIPTION
RRead-only
AArchive
SSystem
HHidden
HHidden
CCompressed
NNot content indexed
EEncrypted
TTemporary
OOffline

robocopy File Selection Options

The robocop command provides options in order to select files to be copied.

OPTIONDESCRIPTION
/aCopy only Archive files
/ia:ATTCopy only files with the specified ATT attribute
/xa:ATTSkip files with the specified ATT attribute
/xdDIRSkip specified DIR directories or path
/xcExclude changed files
/xnExclude newer files
/xoExclude older files
/max:SIZESpecify maximum SIZE for size
/min:SIZESpecify minimum SIZE for size
/maxage:AGESpecify maximum AGE for age
/minage:AGESpecify minimum AGE for age

robocopy Retry Options

The robocopy retry options are used to retry failed copy or clone operations.

READ  PowerShell Get-Date Command Tutorial
OPTIONDESCRIPTION
/r:NSpecify maximum retry which is N count for filed copy
/w:NSpecify the wait time between retries in seconds with N

robocopy Logging Options

During the usage of of the robocopy command a lot of copy operation is done or not. There will be a log information about the operations and these logging information can be managed with the logging options.

OPTIONDESCRIPTION
/lOnly list files or dry run which will not copy
/xReport all extra files which are not selected
/vVerbose and detailed output like debug information
/tsDisplay source files time stamps
/fpPrint full path information
/bytesPrint file and directory size
/npDo not display progress information or bar
/etaPrint estimated time to copy
/log:FILESpecify the log file name and path with the FILE parameter
/unicodeSet log encoding as Unicode
/teePrint log to both console and log file

robocopy Exit Codes

The robocopy command will provide an exit code when the copy operation completed. The exit code provides information about the task like no files copied, all files were copied successfully, etc. The exit codes can be very useful for batch file usage in order to get the result of the robocopy command.

ValueDescription
No files were copied. No failure was encountered. No files were mismatched. The files already exist in the destination directory; therefore, the copy operation was skipped.
1All files were copied successfully.
2There are some additional files in the destination directory that are not present in the source directory. No files were copied.
3Some files were copied. Additional files were present. No failure was encountered.
5Some files were copied. Some files were mismatched. No failure was encountered.
6Additional files and mismatched files exist. No files were copied and no failures were encountered. This means that the files already exist in the destination directory.
7Files were copied, a file mismatch was present, and additional files were present.
8Several files did not copy.

Copy All Files and Folders From Source To Destination

The robocopy command can be used to copy all source files and folders into the destination without using any option or providing the file name just providing the source and destination path.

> robocopy C:\Database D:\

The robocopy can be also used copy files between network share like below. In the following example the \\DEV\Data will be copied to the another share named \\BACKUP .

> robocopy \\DEV\Data \\BACKUP\

Copy Specified File Extension

The robocopy command can be used to copy or mirror only specified files type by providing the extension. In the following example, we will copy only the text files.

> robocopy \\DEV\Data \\BACKUP\ *.txt

We can also provides multiple extensions to copy like *.pdf , *.jpg .

> robocopy \\DEV\Data \\BACKUP\ *.txt *.pdf *.jpg

Do Not Copy Only List Files

The robocopy command provides the /l option in order to list copy log but not copy files really. This is also called a dry run which is just a simulation to show what will happen if the source is copied to the destination.

> robocopy \\DEV\Data \\BACKUP\ *.txt /l

Copy Only Files with Specified Size and Higher

The source files can be copied according to their sizes. By using the /min: option we will only copy files with 32 MB and higher.

> robocopy \\DEV\Data \\BACKUP\ *.txt /min:33554432

Copy Files Older Than Specified Days

The file date information can be used to select a copy by using the /minage: option and providing the date count. In the following example, we will copy files that are 10 days and older.

> robocopy \\DEV\Data \\BACKUP\ *.txt /minage:10

Robocopy GUI

The robocopy is a command line tool but Microsoft provides a GUI called Robocopy GUI. Also there are some non-Microsoft GUI alternatives for the robocopy command.

  • WinRobocopy
  • Easy Robocopy
  • Robocopy GUI
  • EazyCopy
READ  xcopy Command Tutorial

Leave a Comment