Robocopy File Migration

Introduction

Migrating storage data has never been so easy with methods like, vMotion and 3PAR’s online import tool. I recently had to do a NAS data transfer from an old to new device and neither of the above options were available and neither was Rsync, so I had to fail back to good old Robocopy. It certainly isn’t the fastest method but when you are short on options it is a useful one. There are lots of switches you can use so I wanted to look at the most common ones and some gotchas.

Useage

Robocopy is short for robust file copy and is included with Windows Server 2008, Windows 7, Windows Server 2008 R2, Windows Server 2012, Windows 8

The basic usage is

robocopy \\source server\source path \\destination server\destination path <switches>

Here are some of the most common switches:

/e Copy subdirectories including empty ones

/zb Enables restartable mode. This is useful if the link you are copying across is unreliable as it will retry the file when the connection is established again. It also allows access to files using backup mode you be otherwise be unable to access

/copy:all Copy all the properties of the file

/copy:DATSOU Like above allows you to copy the properties of the file. But this allows the granular selection of which properties to copy

D Data

A Attributes

T Time stamps

S NTFS access control list (ACL)

O Owner information

U Auditing information

The default value for CopyFlags is DAT (data, attributes, and time stamps).

/log:c:\Robocopy.log Output the results to a log file

/log:c:\Robocopy.log /V /NPCommands can be used in conjunction with the log command to specify what exactly is logged. For example the following writes the results to a log file in verbose mode and does not show the percentage progress

Gotchas

/r:1 Specifies how many times copying a file will be retried. Setting this to something sensible is key or it will default to 1 million

/t:1 Specifies in seconds time to wait between retries. Again worth setting or it will default to 30 seconds

You can see the full list of switches here

Putting it all together

robocopy \\Server1\Y$ \\Server2\Y$ /e /zb /copy:DAT /r:1 /w:1 /log:c:\Scripts\Robocopy.log /V /NP

The above command will copy the data from \\Server1\Y$ to \\Server2\Y$ . Copying subfolders including empty ones, in restartable mode, copying the date, time and file properties. A retry and wait of 1 second each and outputting in verbose mode with no progress percentage to c:\Scripts\Robocopy.log

If you are using Robocopy to migrate data you can run it several times to pick up new files or modified files. A standard strategy would be to run it several times to copy as many files as possible, then to have an outage for the final copy to make sure that you have everything.