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.

 

 

 

 

 

 

Published by

5 thoughts on “Robocopy File Migration

  1. Hi Arnold,
    I have made this Copy Script for my migrations.
    I generate Logfiles for Mirr and I shedule it as Daily Mirr Task for some Days before the final Migration.

    Greetings Cali

    @echo off
    set Source=E
    set Target=K

    for /f “tokens=1 delims=: ” %%h in (‘time /T’) do set hr=%%h
    for /f “tokens=2 delims=: ” %%m in (‘time /T’) do set mi=%%m

    set y=%date:~10,4%
    if “%y%” == “” goto German
    for /f “tokens=3 delims=: ” %%a in (‘time /T’) do set ap=%%a

    rem Date for Englisch
    set d=%date:~7,2%
    set m=%date:~4,2%
    set y=%date:~10,4%
    goto Date

    :German
    rem Date for German
    set d=%date:~0,2%
    set m=%date:~3,2%
    set y=%date:~6,4%

    :Date
    set Day=%d%-%m%-%y%
    set d=
    set m=
    set y=
    set Hour=%hr%-%mi%%ap%
    set hr=
    set mi=
    set ap=

    set MyDrive=%~d0
    set MyPath=%~dp0

    rem Test
    rem robocopy %Source%:\ %Target%:\ /XD “System Volume Information” “$RECYCLE.BIN” /E /B /NFL /R:0 /W:1 /XJ /TEE /LOG:%MyPath%ROBO_%Source%-%Target%_%Day%_%Hour%.txt

    rem Mirror
    robocopy %Source%:\ %Target%:\ /XD “System Volume Information” “$RECYCLE.BIN” /E /B /NFL /R:0 /W:1 /COPYALL /XJ /DCOPY:T /MIR /TEE /LOG:%MyPath%ROBO_%Source%-%Target%_%Day%_%Hour%.txt

    rem Copy
    rem robocopy %Source%:\ %Target%:\ /XD “System Volume Information” “$RECYCLE.BIN” /E /B /NFL /R:0 /W:1 /COPYALL /XJ /DCOPY:T /TEE /LOG:%MyPath%ROBO_%Source%-%Target%_%Day%_%Hour%.txt

Leave a Reply to Richard T Arnold Cancel 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.