Skip to main content

In today’s digital age, efficient file migrations are crucial. Enter Robocopy, the command-line powerhouse in Windows, designed for swift and precise file transfers. In this post, we unravel the best Robocopy commands, equipping you with the knowledge to execute seamless file migrations effortlessly. Join us on this journey to mastering the art of file transfers.

What is Robocopy?

Robocopy, short for Robust File Copy, is a powerful command-line tool in Windows that facilitates efficient file transfers and migrations. Developed by Microsoft, Robocopy excels in copying large volumes of data with speed and accuracy, making it a favorite among IT professionals and system administrators. Its versatility allows users to copy files, directories, and even entire drives, while preserving timestamps, security settings, and file attributes. With its robust features and reliability, Robocopy simplifies complex file migration tasks, ensuring seamless transfers and data integrity.

What command can I use for file migrations?

In this section, I will show you a command that I personally use for migrations and have had very good experiences with. I will only cover the parameters that I use. There are, of course, many more options that can be used. However, these can be found in the official Microsoft Learn – Robocopy documentation.

 

robocopy "[source]" "[destination]" /E /Z /COPY:DATSOU /R:5 /W:5 /MT:8 /MIR /LOG+:"logfiledestination"

Source and Destination

On the [source] enter the folder which you want to migrate. This can either be a local path or a share. When you want to migrate something from a share please check, if you have enough permissions.

"C:\Users\Max\Documents\FolderToBeMigrated"

On the [destination] enter the folder where you want to migrate. This can either be a local path or a share. When you want to migrate something from a share please check, if you have enough permissions.

"\\Server01\Data\NewFolderForFiles"

In this example I will be migrate the Files from the C:\Users\Max\Documents\FolderToBeMigrated to the Share \\Server01\Data\NewFolderForFiles.

/E /Z /COPY:DATSOU

The /E option will make sure, that all subdirectories with also empty directories will be migrated.

The /Z option will make sure, that it will copy files in restartable mode. When a file copy will be interrupted, robocopy can pick up where it left off rather tahn recopying the entire file.

The /COPY:DATSOU option will define, which file properties will be copied. In this case we will be copying

D – Data
A – Attributes
T – Time stamps
S – NTFS access control list (ACL)
O – Owner information
U – Auditing information

/R:5 /W:5 /MT:8 /MIR

The /R:5 option will specify the number of retries on failed copies. In this case it will try 5 times befor skipping the file.

The /W:5 option will specify the wait time between retries in seconds. In this case it will wait 5 seconds.

The /MT:8 option will enable multi-threading for higher performance and the ability to restart the transfer in case it’s interrupted.

The /MIR option will mirror a directory tree. Using this option with the /E option and a destination directory, overwrites the destination deirectory security settings. This is very handy because you can run the script multiple times. It will only overwrite the files which has changed!

/LOG+:"logfiledestination"

On the [logfiledestination] enter the folder where you want to save the LOG file. This can either be a local path or a share. Also add the name of the log file how you want it to be named. Dont forgett .txt on the end!

/LOG+:"C:\logfiles\LogFromMigration.txt"

You can also add some parameters for example the Date or Time. Here is another example with an Date and Time stamp.

/LOG+:"C:\logfiles\LogFromMigration_%DATE%_%time:~0,2%-%time:~3,2%-%time:~6,2%.txt"
[/vc_column_inner]

When and how should I migrate?

By using the “/MIR” option, you can ensure that the destination directory is an exact replica of the source directory. It saves time and effort by automatically synchronizing the files and directories, maintaining the integrity and consistency of the data across different locations.

For example you can run the command a couple of days prior to the switch. You can rerun the command every couple of days. This means that it not only copies files and folders but also deletes any files in the destination directory that no longer exist in the source.

Leave a Reply