Categories
Command Line Robocopy RoboCopy Examples Windows

Robocopy Examples

Examples of Microsoft’s Robocopy (robocopy.exe) syntax.

Robocopy Example 1: Copy files from one computer to another, skipping files already in the destination.

robocopy \Computer1reports \Computer2backup *.doc /S

Robocopy Example 2: List files over 32 MBytes in size.

robocopy C:xyz /MAX:33554432 /L

Robocopy Example 3: Move files over 14 days old (note the MOVE option will fail if any files are open and locked).

robocopy C:origin C:destination /move /minage:14

Robocopy Example 4: /MIR is an option to ROBOCOPY where you mirror a directory tree with all the subfolders including the empty directories and you purge files and folders on the destination server that no longer exists in source.

robocopy \sourceserversharepath \destinationserversharepath /MIR

Or

robocopy source-drive:path destination-drive:path /MIR

Robocopy Example 5: The following command will mirror the directories using robocopy:

robocopy \SourceServerShare \DestinationServerShare /MIR /FFT /Z /XA:H /W:5

/MIR specifies that robocopy should mirror the source directory and the destination directory. Note that this will delete files at the destination if they were deleted at the source.
/FFT uses fat file timing instead of NTFS. This means the granularity is a bit less precise. For across-network share operations this seems to be much more reliable – just don’t rely on the file timings to be completely precise to the second.
/Z ensures robocopy can resume the transfer of a large file in mid-file instead of restarting.
/XA:H makes robocopy ignore hidden files, usually these will be system files that we’re not interested in.
/W:5 reduces the wait time between failures to 5 seconds instead of the 30 second default.

Robocopy Example 6: use robocopy to copy all changes to files in a directory called c:data to a directory that contains the date, like data_20091124.  Create a batch file as follows.

@echo off
set day=%date:~0,2%
set month=%date:~3,2%
set year=%date:~6,4%
robocopy "c:data" "c:backupdata%day%-%month%-%year%" /MAXAGE:1

Robocopy Example 7: To mirror the directory “C:directory” to “\server2directory” excluding \server2directorydir2″ from being deleted (since it isn’t present in C:directory) use the following command:

robocopy "C: directory" "\server2 directory" /MIR /XD "\server2 directorydir2"

Robocopy Example 8: Copy a single file:

robocopy <Source Dir> <Destination Dir> <File Name> <Switches> 

Robocopy can be setup as a simply Scheduled Task that runs daily, hourly, weekly etc. Note that robocopy also contains a switch that will make robocopy monitor the source for changes and invoke synchronization each time a configurable number of changes has been made. This may work in your scenario, but be aware that robocopy will not just copy the changes, it will scan the complete directory structure just like a normal mirroring procedure. If there are a lot of files & directories, this may hamper performance.

More Robocopy
robocopy commands
robocopy syntax
Categories
Command Line Robocopy RoboCopy Examples Windows

How to Copy Files Multi-Threaded with Robocopy in Windows 7

Robocopy, short for Robust File Copy, is a command-line directory replication and file copy command utility that first made available as feature in Windows Vista and Windows Server 2008, although it has been available as part of Windows Resources Kit. In Windows 7 and Windows Server 2008, Robocopy utility is further enhanced with ability to multi-threaded copy operation feature.

Multi-threaded support allows Robocopy to open multiple threads simultaneously, allowing many files to be copied in parallel. With multi-threaded copying, total time required to complete the operation will be drastically reduced and cut, when comparing with with typical copying one file at time in serial sequential order.

As Robocopy is generally a command-line only utility (although a GUI add-on is available for Robocopy), the new multi-threaded operation capability has to be called via a new switch supported by Robocopy. The new multi-threaded copy feature can be enabled and turned on with the following parameter:

/MT[:n]

Where n will instruct Robocopy to do multi-threaded copies with n threads (default 8). The value of n must be at least 1 and not greater than 128 (between 1 to 128), with 1 as single thread. In fact, Robocopy will copy files and folders in multi-threaded operation by default, with 8 threads in one go. Note that /MT[:n] switch is not compatible with the /IPG and /EFSRAW operations.

For example,

robocopy C:Folder1 C:Folder2 /MT:32

More Robocopy

Categories
Command Line Resource Kit Robocopy RoboCopy Examples Utility Windows

Robocopy Syntax, Command Line Switches and RoboCopy Examples

RoboCopy (Robust File Copy) is a command-line file copying tool in Windows 7, and Windows Vista. Although RoboCopy has been available for free with the Windows Resource Kit, it has never been an official feature of the operating system until Windows Vista. Unlike other built-in file copying commands such as Copy and XCopy, RoboCopy is designed for reliable copy or mirroring of entire folders of any size, and in the copying process, ensure that all NTFS ACLS, attributes, owner information, alternate data streams, auditing information, timestamps and properties are copied except security information unless explicitly requested with /COPYALL switch. And best of all, RoboCopy works over network connections that are subject to disruption or outages with resume copying feature, and has progress indicator on the command line that is useful when copying large files.

RoboCopy Syntax

ROBOCOPY source destination [file [file]…] [options]

Where source is Source Directory (drive:path or \serversharepath), destination is Destination Directory (drive:path or \serversharepath) and file is File(s) to copy where names or wildcards can be specified and default is “*.*” (all files).

RoboCopy Options and Switches
RoboCopy Copy Options

  • /S – copy Subdirectories, but not empty ones.
  • /E – copy subdirectories, including Empty ones.
  • /LEV:n – only copy the top n LEVels of the source directory tree.
  • /Z – copy files in restartable mode.
  • /B – copy files in Backup mode.
  • /ZB – use restartable mode; if access denied use Backup mode.
  • /EFSRAW – copy all encrypted files in EFS RAW mode.
  • /COPY:copyflag[s] – what to COPY for files (default is /COPY:DAT).
    (copyflags : D=Data, A=Attributes, T=Timestamps).
    (S=Security=NTFS ACLs, O=Owner info, U=aUditing info).
  • /DCOPY:T – COPY Directory Timestamps.
  • /SEC – copy files with SECurity (equivalent to /COPY:DATS).
  • /COPYALL – COPY ALL file info (equivalent to /COPY:DATSOU).
  • /NOCOPY – COPY NO file info (useful with /PURGE).
  • /SECFIX – FIX file SECurity on all files, even skipped files.
  • /TIMFIX – FIX file TIMes on all files, even skipped files.
  • /PURGE – delete dest files/dirs that no longer exist in source.
  • /MIR – MIRror a directory tree (equivalent to /E plus /PURGE).
  • /MOV – MOVe files (delete from source after copying).
  • /MOVE – MOVE files AND dirs (delete from source after copying).
  • /A+:[RASHCNET] – add the given Attributes to copied files.
  • /A-:[RASHCNET] – remove the given Attributes from copied files.
  • /CREATE – CREATE directory tree and zero-length files only.
  • /FAT – create destination files using 8.3 FAT file names only.
  • /256 – turn off very long path (> 256 characters) support.
  • /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 – times when new copies may be started.
  • /PF – check run hours on a Per File (not per pass) basis.
  • /IPG:n – Inter-Packet Gap (ms), to free bandwidth on slow lines.

RoboCopy File Selection Options

  • /A – copy only files with the Archive attribute set.
  • /M – copy only files with the Archive attribute and reset it.
  • /IA:[RASHCNETO] – Include only files with any of the given Attributes set.
  • /XA:[RASHCNETO] – eXclude files with any of the given Attributes set.
  • /XF file [file]… – eXclude Files matching given names/paths/wildcards.
  • /XD dirs [dirs]… – eXclude Directories matching given names/paths.
  • /XC – eXclude Changed files.
  • /XN – eXclude Newer files.
  • /XO – eXclude Older files.
  • /XX – eXclude eXtra files and directories.
  • /XL – eXclude Lonely files and directories.
  • /IS – Include Same files.
  • /IT – Include Tweaked files.
  • /MAX:n – MAXimum file size – exclude files bigger than n bytes.
  • /MIN:n – MINimum file size – exclude files smaller than n bytes.
  • /MAXAGE:n – MAXimum file AGE – exclude files older than n days/date.
  • /MINAGE:n – MINimum file AGE – exclude files newer than n days/date.
  • /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).
  • /XJ – eXclude Junction points. (normally included by default).
  • /FFT – assume FAT File Times (2-second granularity).
  • /DST – compensate for one-hour DST time differences.
  • /XJD – eXclude Junction points for Directories.
  • /XJF – eXclude Junction points for Files.

RoboCopy Retry Options

  • /R:n – number 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 in the Registry as default settings.
  • /TBD – wait for sharenames To Be Defined (retry error 67).

RoboCopy Logging Options

  • /L – List only – don’t copy, timestamp or delete any files.
  • /X – report all eXtra files, not just those selected.
  • /V – produce Verbose output, showing skipped files.
  • /TS – include source file Time Stamps in the output.
  • /FP – include Full Pathname of files in the output.
  • /BYTES – Print sizes as bytes.
  • /NS – No Size – don’t log file sizes.
  • /NC – No Class – don’t log file classes.
  • /NFL – No File List – don’t log file names.
  • /NDL – No Directory List – don’t log directory names.
  • /NP – No Progress – don’t display % copied.
  • /ETA – show Estimated Time of Arrival of copied files.
  • /LOG:file – output status to LOG file (overwrite existing log).
  • /LOG+:file – output status to LOG file (append to existing log).
  • /UNILOG:file – output status to LOG file as UNICODE (overwrite existing log).
  • /UNILOG+:file – output status to LOG file as UNICODE (append to existing log).
  • /TEE – output to console window, as well as the log file. 
  • /NJH – No Job Header.
  • /NJS – No Job Summary.
  • /UNICODE – output status as UNICODE.
RoboCopy Job Options
  • /JOB:jobname – take parameters from the named JOB file.
  • /SAVE:jobname – SAVE parameters to the named job file
  • /QUIT – QUIT after processing command line (to view parameters).
  • /NOSD – NO Source Directory is specified.
  • /NODD – NO Destination Directory is specified.
  • /IF – Include the following Files.

RoboCopy Examples
RoboCopy is simple to use, very similar to Copy and Xcopy. For example, to copy entire folder of C:Users to C:UserBackup, simply type:

robocopy C:Source C:Destination

Copy directory contents recursively, all contents of SourceDir to DestDir:

robocopy C:SourceDir C:DestDir /E

Copy directory recursively (/E), and copy all file information (/COPYALL, equivalent to /COPY:DATSOU, D=Data, A=Attributes, T=Timestamps, S=Security=NTFS ACLs, O=Owner info, U=aUditing info), do not retry locked files (/R:0).

robocopy C:source C:destination /COPYALL /E /R:0

Mirror source to destination, deleting any files in destination that are not present in source (/MIR), copy files in restartable mode (/Z) in case network connection is lost:

robocopy C:source \DestServerdestination /MIR /Z

More RoboCopy