The lovely ROBOCOPY in VISTA

What is ROBOCOPY?

I just discovered that robocopy, that terrific file copying tool that beats xcopy by a mile is actually included in-box in Vista.

Robocopy has been around as an independent tool for a little while (primarily in the Windows Resource Kits), but finally in Windows Vista, someone has seen fit to give the little tool the recognition it deserves, and as a result it now sits on a high pedestal in the \windows\system32 directory on every Windows Vista installation.

Why is robocopy so cool? Well, for starters, it’s hard to find a more flexible, configurable tool – with over 80 switches, the chances are it can handle any batch or synchronous copy you have in mind

Secondly, it’s just very robust. If a network link goes down halfway through a lengthy copy, most tools bail out, but robocopy just patiently waits, retrying x times with a y second interval (of course, x and y are configurable). Better still, it can be configured to pick up where the file transfer left off, so you don’t have to go all the way back to the start if the network fails 99% of the way through a 2GB file.

Finally, it’s perfectly optimized for mirroring large file shares on a slow WAN link. It only copies files that have changed, which is perfect for the occasions when you want to pull down a daily build where only 30% of the files have changed since the last occasion. You can set it to monitor a source and keep the destination updated with changes on a repeated schedule. Lastly, you can even throttle the traffic down by tweaking the inter-packet gap, so that a network link isn’t monopolized by the copy process.

ROBOCOPY in operation

It is important to note the ROBOCOPY will only take folder paths not file path in its parameters.

By default Robocopy will only copy a file if the source and destination have different time stamps or different file sizes.

Syntax

ROBOCOPY source_folder destination_folder [file(s)_to_copy] [options]

Notes:

  • Robocopy will fail to copy files that are ‘locked’ by other users or applications, limiting the number of retries with /R:0 will speed up large jobs.
  • ROBOCOPY will accept UNC pathnames including UNC pathnames over 256 characters long.
  • /B (backup mode) will allow Robocopy to override file and folder permission settings (ACLs).
  • To run ROBOCOPY under a non-administrator account will require backup files privilege, to copy security information auditing privilege is also required, plus of course you need at least read access to the files and folders.
  • Robocopy ‘Jobs’ and the ‘Monitor source’ option provide an alternative to setting up a Scheduled task to run a batch file with a Robocopy command

What happens if you batch multiple robocopy commands and one fails ?

If robocopy fails to copy a file, it goes onto the next task and finishes what needs copying.

Important Note : Paths with spaces !!

If either the source or destination are a “quoted long foldername” do not include a trailing backslash as this will be treated as an escape character, i.e. “C:\some path\” will fail but “C:\some path\\” or “C:\some path” will work.

Bandwidth Throttling

By copying only the files that have changed, robocopy can be used to backup very large volumes.
To limit the network bandwidth used by robocopy, specify the Inter-Packet Gap parameter /IPG:n
This will send packets of 64 KB each followed by a delay of n Milliseconds.

More about Inter-Packet Gap here :

http://en.wikipedia.org/wiki/Interpacket_gap

Trick: When to choose /e switch and when to choose /MIR switch

The /e switch asks for all subdirectories to be copied, even if they are empty. Robocopy will only copy the changed files, and gives you a report showing how many files were copied and how many were skipped.

There is one possible flaw in this arrangement. If you deleted a file from the source folder, then copy it over an existing backup, the target folder will still contain the old file. This might not be what you want, especially if you are a developer and this is source code. Old files hanging around are a bad idea. Robocopy has an answer for this too:

robocopy c:\mysourcedir d:\mytargetdir /mir

What about copying USER DATA ?

When copying user accounts to another place in Windows Vista, be sure to exclute JUNCTIONS. There is a junction in ‘\Users\…\AppData\Local’ named ‘Application Data’ which points to its parent folder, thus effectively creating a LOOP.

Robocopy if used without /xj follows this junction and copies its contents and follows this junction and copies its contents and follows this junction

Examples:

  • Copy files from one server to another (auto skip files already in the destination)
ROBOCOPY \\Server1\reports \\Server2\backup *.doc /S
  • List files over 32 MBytes in size:
ROBOCOPY C:\work /MAX:33554432 /L
  • Move files over 14 days old: (note the MOVE option will fail if any files are open and locked.)

ROBOCOPY C:\work C:\destination /move /minage:14

Tip :  Script for regular backup:

@ECHO OFF
SETLOCAL

SET _source=\\FileServ1\e$\users

SET _dest=\\FileServ2\e$\BackupUsers

SET _what=/COPYALL /B /SEC /MIR
:: /COPYALL :: COPY ALL file info
:: /B :: copy files in Backup mode.
:: /SEC :: copy files with SECurity
:: /MIR :: MIRror a directory tree

SET _options=/R:0 /W:0 /LOG:MyLogfile.txt /NFL /NDL
:: /R:n :: number of Retries
:: /W:n :: Wait time between retries
:: /LOG :: Output log file
:: /NFL :: No file logging
:: /NDL :: No dir logging

ROBOCOPY %_source% %_dest% %_what% %_options%

Resources:

Download the ROBOCOPY GUI

 http://www.softpedia.com/get/System/OS-Enhancements/RoboCopy-GUI.shtml

ROBOCOPY Vista gadget

http://www.softpedia.com/get/Windows-Widgets/System-Utilities/RoboCopy.shtml

2 comments on “The lovely ROBOCOPY in VISTA

  1. Nice share.Another software that I am sharing might also help you with some errors .Try and download ” Long Path Tool ” is also useful in situations where you see these error messages: Cannot read from source file or disk, there has been a sharing violation, cannot delete file or folder, the file name you specified is not valid or too long,
    the source or destination file may be in use and many other file managing errors.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s