Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the algorithm behind Robocopy?

I am curious to know what makes Robocopy (Robust File Copy) so fast and robust. Any body knows what is the API/Algo used for Robocopy? Anybody studied Robocopy?

I am asking since I have to write a method (in .NET/C#) which will copy directories/files fast and without errors... The amount of data can go up to 15Gb and I cannot simply call Robocopy for various reasons.

Thanks!

like image 835
Martin Avatar asked Oct 21 '10 16:10

Martin


People also ask

How does Robocopy work?

Robocopy is a robust file copying program built into Windows similar to UNIX rsync. It is a much better method of copying large datasets or lots of files across volumes and is a great tool for backing up data. It has the ability to resume copies if interrupted, various options and logging during copying.

What replaced Robocopy?

The best alternative is FreeFileSync, which is both free and Open Source. Other great apps like Robocopy are TeraCopy, rsync, FastCopy and Bvckup 2. Robocopy alternatives are mainly File Copy Utilities but may also be File Sync Tools or File Managers.

Is Robocopy faster than normal copy?

Windows 7 and newer versions come with a new version of the robocopy command that is able to copy files much faster then the normal copy command or copy function of the file explorer by using several simultanious threads. So if you plan to copy a large number of files, e.g. to make a backup, use the robocopy command.

Who made Robocopy?

Created by Kevin Allen and first released as part of the Windows NT 4.0 Resource Kit, it has been a standard feature of Windows since Windows Vista and Windows Server 2008. The command is robocopy.


1 Answers

You can get very close to Robocopy's speed with a simple C# program that does asynchronous reads and writes using a standard FileStream with a 64K buffer. Larger buffer sizes up to 256K will give a slight performance increase. Larger than 256K will slow things down to a surprising extent. In my tests, using a 512K buffer took almost twice as long as copying with a 256K buffer.

The idea is pretty simple:

Read the first buffer from the source file
do
{
    start asynchronous write to destination file.
    Read the next buffer from the source file
    wait for asynchronous write to complete
} while not end of file

It's a pretty simple thing to write. My program that does this is almost as fast as Robocopy and doesn't cause the kinds of problems that Robocopy causes when you're copying a very large (hundred gigabyte) file from a server.

A bit more info on the large file copy problem.

Note that this asynchronous read/write thing doesn't do much for performance if you're reading from and writing to the same physical disk. It's most effective when the source and destination are on different drives.

like image 75
Jim Mischel Avatar answered Sep 23 '22 06:09

Jim Mischel