Robocopy

Although “Robocopy” sounds like something robots do to make baby robots, it actually stands for “Robust File Copy” and is a popular (and free) tool from Microsoft. It’s included with Windows Vista and is available for Windows XP and Windows 200 as part of the Windows 2003 Server Resource Kit (despite the “Windows 2003? name, Robocopy works just fine in Windows 2000, XP and Vista).

What’s so cool about it is that it’s a command-line program for copying files from one place to another, yet it has some powerful features that you can’t get simply by dragging and dropping files using Windows Explorer. For instance, you can have Robocopy copy all the NTFS security information from certain files. You can set the number of retries on failed copies, exclude or include changed, newer or older files, copy subdirectories but not empty ones, copy subdirectories including empty ones and much, much more.

One of my favorite Robocopy options is /mir, which creates an exact copy of any directory on another drive or network share. This is an *excellent* tool for making backups. Here’s a sample of a batch file I use to copy my application and music files over to my server:

robocopy.exe \\mycomputer\applications \\server\applications /mir /eta /tee
robocopy.exe \\mycomputer\jukebox \\server\jukebox /mir /xd Recycled Recycler “System Volume Information” Temp /eta /tee

Both commands use the /mir switch to mirror the source directories and also use the /eta switch to show the estimated completion time and /tee to send output to console window. Since the “Jukebox” share is sharing the root of the drive I use the /xd switch to exclude various folders on the drive, such as the “Recycle Bin” and “Temp” folders. Neat huh? Of course, Robocopy with the /mir switch will (by default ) only copy newer or changed files, so it doesn’t waste time copying unchanged files. If I add four or five new albums to my music collection and then run the batch file, only those new albums will be copied to the server. This is *such* a time saver! Robocopy works far better than many shareware utilities that do the same thing.

Anyone in a corporate setting will appreciate the usefulness of this tool. In many cases it might be easier – not to mention much faster – to run a backup program like NTBACKUP to a file on a local computer and then use robocopy to copy the backup file to a main server where it can be archived to tape. That’s what I do with my Exchange backups: I have NTBACKUP running at 8am every morning to a folder on the server itself. As soon as the backup is done, the Exchange and System State BKF files get “robocopied” to my local machine, where another batch file runs locally that compresses the files using RAR and renames the file with today’s date. And not do I only have the RAR-ed copy of the backup, I still have the original BKF on the server, so if I needed to restore Exchange from backup the restore will happen quickly. Also of note to your corporate users is that Robocopy has a raft of logging features available as well.

But still, Robocopy is useful even if you’re not a corporate user. A few years back, I owned a mobile phone that supported SD cards. While I could have used Microsoft’s ActiveSync to copy mp3 and movie files to the phone, it was really slow. So instead I use my SD card reader. I created a folder on my computer called “Smartphone Mirror” and I kept everything I wanted to transfer to the SD card in there. When I had the songs and videos just right, I popped the SD card into the reader and clicked a batch file that looks like this:

robocopy.exe “f:\Smartphone Mirror” k:\ /purge
robocopy.exe “f:\Smartphone Mirror” k:\ /mir
exit

/purge deletes everything on the SD card that is not present in the “Smartphone Mirror” directory. This is typically not necessary, since the next line’s /mir implies /purge. However Robocopy only copies one directory at a time and since I usually keep my SD card as full of media as possible, Robocopy often runs out of space on the card for copying new stuff before it deletes missing files in the next subdirectory. By getting rid of older files I don’t want, /purge creates all the space you need on the card before /mir does its thing.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.