Quick Windows file syncing

If you have Windows Vista, 7, or 8, you have robocopy.  Robocopy replaces xcopy found in older versions of Windows and adds several new features.  It is similar to rsync for Unix.

If you need to regularly synchronize files between folders, Robocopy is perfect.  Like rsync, it only copies changed files, so once you create an initial backup, only changed files are copied during later backups of the same folders.

Using Robocopy is pretty simple. Let’s say you want to back up your user directory C:\Users\You to a flash drive E:\You.  Open a command line and type:

robocopy C:\Users\You E:\You

…and all of your files will be backed up to the flash drive. Then you change some of your files and want to back up the changes–rerun the same command, and only the changed files will be copied.

There are many more switches (options).  Run “robocopy /?” to see them.

If you use /MIR, you will make a mirror image.  So if you delete files in the source folder, robocopy will delete them from the destination.

If you use /XF, you can exclude certain files and /XD to exclude certain directories.  This is important because if you are backing up from or to a root drive (example, from D:\ to E:\) there are certain system files you don’t want to mess with.  So you can exclude them: /XD "D:\System Volume Information" "D:\RECYCLER"

/LOG lets you dump the program output to a log file, and /TEE lets you dump it to a file and see it in the command window.

This is the command line I use to back up my I:\ drive to my K:\ drive and create a date-stamped log file in C:\backup:

robocopy i:\ k:\ /MIR /TEE /LOG:"C:\Backup\data2-%date:~10,4%-%date:~4,2%-%date:~7,2%-%time:~0,2%-%time:~3,2%.log" /XD "i:\System Volume Information" i:\RECYCLER i:\$RECYCLE.BIN

Posted in Computing on Jan 8th, 2014, 9:26 pm by Dennis   

Comments are closed.