Robocopy backup tip for developers

Posted: (EET/GMT+2)

 

If you want a simple, reliable backup for your source code folders, you might enjoy using Robocopy. It is built right into Windows and works nicely from the command line or Windows Task Scheduler.

Basic usage to mirror one folder to another drive:

robocopy "C:\Projects" "D:\Backups\Projects" /MIR /R:1 /W:5 /FFT /XA:H /XD bin obj

Here's a quick summary of the switches in the above command:

  • /MIR: mirror source to destination (add and remove files as needed)
  • /R:1 and /W:5: retry once, wait five seconds (faster than the defaults)
  • /FFT: use FAT file timing tolerance (helps when copying to NAS or USB drives)
  • /XA:H: skip hidden files
  • /XD bin obj: exclude build output folders

If you'd like a daily snapshot without deleting older copies, you can use timestamps:

robocopy "C:\Projects" "D:\Backups\Projects-%date:~-4,4%-%date:~4,2%-%date:~7,2%" /E /R:1 /W:5 /XD bin obj

This quite lengthy command creates dated folders like Projects-2018-03-15. These are perfect for quick restores when you don't want a full backup system.

If you happen to use the Finnish locale, the above date string won't work. Use this one instead:

%date:~-4,4%-%date:~6,2%-%date:~3,2%

Another tip: add /LOG:C:\Logs\robocopy.log to keep a history of what changed.

Hope this helps!