ROBOCOPY

(from RoboCop Copy)

Advanced tool for copying and moving files and directory structures. It is an extension and evolution of the COPYCOPY and XCOPYXCOPY commands, as well as the MOVEMOVE command for the move operation. The name of the command presumably derives from the possibility of automating the process of repeatedly copying files and directories, through a very large number of criteria and options. This tool is in fact very powerful and capable of performing particular and advanced operations that are not possible with the other commands.

Syntax:

ROBOCOPY source destination [file [...]] [options]

Where:

  • source - Source directory, containing the files or subdirectories to copy. You can specify a local path drive:\path or a network/shared path \\domain\path.
  • destination - Destination directory. You can specify a local path drive:\path or a network/shared path \\domain\path.
  • file [...] - Specifies one or more files to copy from the source directory. You can use wildcardswildcards. If no files are specified, copies all files in the source directory.
  • options - Specifies one or more options.

Options regarding copying:

  • /S - Also copies non-empty subdirectories.
  • /E - Also copies subdirectories, including empty ones.
  • /LEV:n - Copies the first n levels of the source directory structure.
  • /Z - Copies files in restart mode.
  • /B - Copies files in backup mode.
  • /ZB - Copies files in restart or backup mode if access is denied, with restart mode taking precedence.
  • /J - Copies without using intermediate buffer, recommended for large files.
  • /EFSRAW - Copies encrypted files in RAW EFS (Encrypting File System) mode.
  • /COPY:flag - Specifies the properties to copy and keep in new files. Instead of flag, specify one or more of the following letters (default is DAT):
    • D - Last modified date.
    • A - Attributes (see ATTRIBATTRIB).
    • T - Timestamp.
    • X - Skips alternate data streams (flag ignored if /B or /ZB option is specified).
    • S - Access security flag, concerns NTFS ACLs (see ICACLSICACLS).
    • O - Owner information.
    • U - Control information.
  • /SEC - Copies files while preserving access security information (equivalent to /COPY:DATS).
  • /COPYALL - Copies while retaining all properties of the original files (equivalent to /COPY:DATSOU).
  • /NOCOPY - Copies without retaining any ownership of the original files (useful in conjunction with the /PURGE option).
  • /SECFIX - Fixes access security information for all files, including ignored ones.
  • /TIMFIX - Corrects date and time information, including ignored ones.
  • /PURGE - Deletes files and directories from the destination if they do not exist in the source path. If the root of a drive is specified as the destination (e.g. D:), files in the System Volume Information directory are ignored. In the past, a bug in ROBOCOPY allowed these files to be deleted in this case, but this no longer happens in newer versions of Windows.
  • /MIR - Mirrors a directory structure (equivalent to /E with /PURGE).
  • /MOV - Moves files, that is, deletes the source files after copying.
  • /MOVE - Moves files and directories, i.e. deletes sources after copying.
  • /A+:attr - Adds the specified attributes to the target files as a sequence of letters. Some attributes that can be used with this option are R, A, S, H, C, N, E, T (see ATTRIBATTRIB and DIRDIR for complete lists of attribute letters and their meanings).
  • /A-:attr - Removes attributes specified in target files as a sequence of letters. Some attributes that can be used with this option are R, A, S, H, C, N, E, T, O (see ATTRIBATTRIB and DIRDIR for complete lists of attribute letters and their meanings).
  • /CREATE - Only creates empty files and directory structures, without copying their contents.
  • /FAT - The names of the destination files and directories are created as FAT 8.3 names (i.e. short names, see FSUTILFSUTIL).
  • /256 - Disables support for paths longer than 256 characters. Paths longer than 256 characters may not be supported by older file systems.
  • /MON:n - Enables monitoring of source files and directories, making a new copy when at least n changes are detected.
  • /MOT:m - Enables monitoring of source files and directories, making a new copy after m minutes if changes are detected.
  • /RH:hhmm-hhmm - Specifies a range of times during which new copies can be made.
  • /PT - Checks that you are within the time range specified by /RH for each file rather than for each pass.
  • /IPG:n - Specifies the gap between packets in milliseconds, to free up bandwidth on slow lines.
  • /SJ - Copies junctions to the destination instead of the directories they point to.
  • /SL - Copies symbolic links to the destination instead of the files or directories they refer to.
  • /MT[:n] - Uses multithreading, where n is the number of threads. The number of threads is between 1 and 128. By default, n is set to 8.
  • /DCOPY:flag - Specifies the properties to copy and keep in new directories. Instead of flag, specify one or more of the following letters (default is DA):
    • D - Last modified date.
    • A - Attributes.
    • T - Timestamp.
    • E - EA (extended attribute).
    • X - Skips alternate data streams.
  • /NODCOPY - Copies without retaining any ownership of the original directories.
  • /NOOFFLOAD - Copies files without using Windows copy offload feature.
  • /COMPRESS - Requires network compression during file transfer (if applicable).
  • /SPARSE - Preserve sparse attribute when copying a sparse file.

Bandwidth throttling (I/O throttling) options for file copying:

  • /IOMAXSIZE:n[K|M|G] - Specifies the maximum input/output size requested per read and write cycle in bytes, kilobytes, megabytes, or gigabytes. Note that the specified size may be changed by ROBOCOPY.
  • /IORATE:n[K|M|G] - Specifies the requested input/output rate in bytes, kilobytes, megabytes, or gigabytes per second. Note that the specified size may be changed by ROBOCOPY.
  • /THRESHOLD:n[K|M|G] - Specifies the size threshold to enable the limiting options in bytes, kilobytes, megabytes, or gigabytes.

File selection options:

  • /A - Copies only files with archive attribute.
  • /M - Copies only files with archive attribute and resets the attribute.
  • /IA:attr - Copies only files with attributes specified as a sequence of letters. Some attributes that can be used with this option are R, A, S, H, C, N, E, T, O (see ATTRIBATTRIB and DIRDIR for complete lists of attribute letters and their meanings).
  • /XA:attr - Excludes from copying files that do not have the specified attributes as a sequence of letters. The attributes that can be used for this option are the same as those for /IA.
  • /XF file [...] - Excludes from copying files that do not match the specified names or paths. Wildcards can be used.
  • /XD cartella [...] - Excludes directories from copying that do not match the specified names or paths. Wildcards can be used.
  • /XC - Excludes modified files from copying.
  • /XN - Excludes the newest and most recent files from copying.
  • /XO - Excludes older files from copying.
  • /XX - Excludes additional files and directories from the copy, that is, those that are present in the destination but not in the source. This means that these files will not be deleted from the destination.
  • /XL - Excludes solitary files and directories from the copy, that is, those that are present in the source but not in the destination. This means that after you make a copy, any files added to the source will not be copied.
  • /IS - Includes identical files (in terms of name, size, date and attributes) in the copy.
  • /IT - Includes changed files in the copy (i.e. with same name, same size but different attributes).
  • /MAX:n - Excludes files larger than n bytes from copying. You can specify binary multiples prefixes K, M, or G.
  • /MIN:n - Excludes files smaller than n from copying. &` You can specify binary multiples prefixes K, M, or G.
  • /MAXAGE:n_o_data - Excludes from copying files with a last modified date earlier than the specified date or older than the specified number of days.
  • /MINAGE:n_o_data - Excludes from copying files with a last modified date later than the specified date or more recent than the specified number of days.
  • /MAXLAD:n_o_data - Excludes from copying files with a last access date earlier than the specified date or accessed older than the specified number of days.
  • /FFT - Sets the time mode of FAT files (FAT file time, with two-second granularity).
  • /DST - Takes into account differences due to time changes, such as daylight saving time.
  • /XJ - Excludes symbolic links and junction points from copying.
  • /XJD - Excludes symbolic links for directories (but not files) and junction points from copying.
  • /XJF - Excludes symbolic links for files from copying.
  • /IM - Includes changed files in the copy, that is, files that have different modification times between source and destination, but are otherwise the same. Without /IM, these files are not copied. This option only has an effect if the source and destination file systems support modification timestamps, such as NTFS volumes.

Options for managing new copy attempts:

  • /R:n - Specifies the number of retries for failed copies (default is 1000000).
  • /W:t - Specifies the waiting time in seconds between one retry and the next (default is 30 s).
  • /REG - Sets the values for the /R and /W options as default by saving them to the registry (RegEdit).
  • /TBD - Waiting for share names to be defined (error 67).
  • /LFSM[:n[K|M|G]] - Enables low-space mode, which pauses copying files when the available space on a volume reaches a certain minimum. If n is specified, it sets the minimum size of the low-space in bytes, kilobytes, megabytes, or gigabytes. By default, this value is set to 10% of the volume's storage space. This option is not compatible with the /MT (multithreading) and /EFSRAW options.

Displaying Options:

  • /L - Lists the files to copy or move, without performing the operation.
  • /X - Also lists additional files.
  • /V - Enables verbose mode.
  • /TS - Displays source file timestamps.
  • /FP - Displays full path of copied files.
  • /BYTES - Displays size in bytes of copied files.
  • /NS - Does not display the size of copied files.
  • /NC - Does not display classes of copied files.
  • /NFL - Does not display copied file names.
  • /NDL - Does not display copied directory names.
  • /NP - Does not display copy completion percentages.
  • /ETA - Does not display the estimated time of arrival (ETA) remaining for file copies to complete.
  • /LOG:file - Specifies the log file in which to write information about the copy operation, instead of displaying it in the console (if the specified file exists, it is overwritten).
  • /LOG+:file - Specifies the log file in which to write information about the copy operation (if the specified file exists, appends the information to the end of the file).
  • /UNILOG:file - Specifies the log file in which to write information about the copy operation, using UNICODE format (if the specified file exists, it is overwritten).
  • /UNILOG+:file - Specifies the log file in which to write information about the copy operation, using UNICODE format (if the specified file exists, appends the information to the end of the file).
  • /TEE - Copy information is both displayed in the console and recorded in the log file.
  • /NJH - Does not display job header.
  • /NJS - Does not display job summary.
  • /UNICODE - Displays copy information in UNICODE format.

Job options:

  • /JOB:jobname - Specifies the file in which the job options were saved with /SAVE.
  • /SAVE:jobname - Specifies the file in which to save job options for use with /JOB. This option must be placed before the copy, retry, and display options for it to take effect.
  • /QUIT - Displays options without copying.
  • /NOSD - Reports that no source directory was specified.
  • /NODD - Reports that no destination directory was specified.
  • /IF - Also includes the specified files in the options to save.

Example: Back up the C:\Bunker directory to a cloud storage directory located at the shared path \\BackupServer\CloudStorage (in UNC format), specifying to mirror (delete directories and files on the destination that do not exist in the original path), using 16-thread multithreading, specifying 3 retries for failed copies with a 10-second wait, skipping the directories named Temp and Logs and the files with the extensions .tmp, .log, and .iso, using reboot mode (useful if the connection to the server is unstable), enabling sleep mode and verbose mode, showing copy information both on the console and in the C:\Reports\Robocopy_Save.log file (without overwriting it), keeping the timestamps of the original directory and all properties of the original files:

robocopy "C:\Bunker" "\\BackupServer\CloudStorage" /mir /mt:16 /r:3 /w:10 /xd "Temp" "Logs" /xf "*.tmp" "*.log" "*.iso" /z /v /tee /log+:C:\Reports\Robocopy_Save.log /dcopy:t /copyall

Comments