Wednesday 01 Feb 2023


Windows CLI sync


Image copyright

I like to use command-line interfaces (CLI) to manage sync and file uploads to the cloud. I mainly use rsync and rclone. Rsync is great to move files around my linux server - it's easy to use and fast. I use rclone to upload to my cloud storage, again it's fast and easy to use. However, on Windows, copying a large volume of files can crash / hang the GUI. It would also be nice to schedule commands without windows popping up during the copy.

With a little research (and my memory of a program I have used before) I came across robocopy. However it's not as easy to configure. You need to read and manual in detail.

Rsync is easy:

rsync -avH --progress /dir1/ /dir2/

How to complete the same task in robocopy:

ROBOCOPY D:\ E:\ /E /Z /R:0 /W:0

Not as easy to remember and type quickly. The /E means copy subfolders and /Z will continue where left off if cancelled - I guess it's writing partial files. If there is an error, robocopy will wait 30 seconds and continuously retry. To stop this behaviour add the /R:0 and /W:0

I also exclude files using /XF (exclude file) and /XD (exclude directory); here is how the final command looks:

ROBOCOPY D:\ E:\ /E /Z /XD "D:\System Volume Information" "D:\Recycle Bin" D:\found.001 E:\$RECYCLE.BIN\ /XF D:\.VolumeIcon.ico D:\Autorun.inf /R:0 /W:0

And that's it, I am able to use the command. I am using robocopy to back up an external hard drive to another.


Backlinks:
Journal:Index
Journal:2023:02
Journal:2023:02:02