I suppose that only small group of Windows users is aware of existence of such tool like robocopy. I bet it's better known among administrators, but typical user should also know more about this. Personally I discovered this utility after I was forced to transfer 30 GB of data through a VPN that was dropping connection randomly. The solution for that was rather simple - robocopy.
If you open a command line and type
robocopy /? , you'll get quite long description of this tool. There's no point in reading all of this, but if you want, go ahead. My goal is to describe only the basic usage that might be helpful for some of you.
The basic functionality of robocopy (which is turned on by default) is ability to copy only those files, which aren't in the target directory or were modified. This feature makes this tool perfect for typical backups on external drive. So if you want to backup your Documents, just type:
robocopy C:\Users\Foo\Documents Z:\Documents /Z /E
The syntax is rather self explanatory: copy all files from the first path to the second path. It's worth noting that robocopy works on directories; it compares content of both of them and does its magic. However, copying single files is also possible, keep reading.
These two parameters at the end needs quick explanation:
And that's it! If you run this command again, robocopy will copy only new and modified files.
If you prefer to also delete those files that were deleted in the source directory, add another option:
/PURGE . We can replace
/PURGE /E /Z with just:
/MIR /Z .
/PURGE :: delete dest files/dirs that no longer exist in source. /MIR :: MIRror a directory tree (equivalent to /E plus /PURGE).
It might be helpful to omit some directories when backuping. For example, if you want to backup your huge directory with source codes, you'd better exclude node_modules. To omit unwanted directories, use option:
/XD . Yep, that's not a joke XD. Keep in mind that you can use asterisk as a wildcard.
robocopy C:\Users\Foo\Sources Z:\Sources /E /XD node_modules .git
WHY YUU BACKAPPP YUR SORCES, YU HAVVV GIT!!!!111
Of course I use Git, but not every project I create is pushed to repository. Ain't nobody got time for that.
You can also omit specified files, just use:
/XF , the rest works exactly like when excluding directories.
Not always we want to copy the whole directory, sometimes we need to transfer a single file; why use robocopy then? As I said on the beginning - I used robocopy to transfer 30 GB file through unreliable connection, and it worked better than I expected. So assume you have the same situation: you, your huge and legal file, frivolous VPN. In this situation you execute the below command:
robocopy C:\Users\Foo\ Z:\ legal_windows.iso /Z /J
We know what
/Z does, it saves us a lot of headaches and swears, but what with
/J :: copy using unbuffered I/O (recommended for large files).
So if your happy VPN decides to drop connection in the middle of transfer, just reconnect, execute this command again, and robocopy will continue from the moment when it was interrupted.