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
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.
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.
- What is the Linux equivalent to robocopy?
- How to Copy Files Multi-Threaded with Robocopy in Windows 7
- Robocopy Syntax, Command Line Switches and Examples