Windows supports Offline Sync support for Mobile and Network devices through Sync Center tool in Control Panel. What will you do if you want to fine tune your sync with command line capability? Here is ROBOCOPY command built into the Windows.
Robocopy is the advanced version of good old xcopy command in Windows. Microsoft calls it as “Robust File Copy for Windows”. This command is available in most of the recent Windows versions like Windows Vista, Windows 7, Windows 8, Windows Server 2008 and Windows Server 2012. It supports multithreaded copying. It can skip NTFS junction points (Windows version of symbolic links in Unix), files already in destination and pattern of file names mentioned in command line to exclude in copying. It can resume copying after network interruption. It can preserve file attributes like permissions and timestamps in destination. In mirror mode, it syncs both source and destination in sync. There is a option to delete file in destination if it doesn’t exist in source.
Here I detail on how I use this command to carry out sync operation (a kind of backup, not a true backup!) from my Windows 8.1 Desktop to ARM based QNAP Linux Server TS-110. My Ubuntu Linux and Windows 8.1 shares a common NTFS file system for data storage. Here I explain how my C:\Users directory is kept in sync with Server using this robocopy command.
Source: Windows 8.1 Desktop’s C:\Users directory to be sync
Destination: Samba Share of Linux Server (Linux supports the SMB/CIFS protocol used by Windows to share files).
Command to run in Windows:
ROBOCOPY C:\Users \\HomeServer\Backup\Windows-PC\Users /DCOPY:DA /MIR /FFT /Z /XA:SH /R:0 /TEE /XJD /XD AppData /XD OneDrive /XD SkyDrive
C:\Users – It is the directory which I want to sync
\\HomeServer\Backup\Windows-PC\Users – Server Name is “HomeServer”, Share name is “Backup” and directory under Backup is “Windows-PC\Users”.
/DCOPY:DA – Copy Data and Attributes.
/MIR – It mirrors the entire directory tree C:\Users in destination. It also deletes destination files which no longer exists in C:\Users.
/FFT – This is to support FAT file systems which needs a tweak to support timestamp validation by copy logic in robocopy tool.
/Z – Copy operation can be resumed after termination.
/XA:SH – Exclude System (S) files and Hidden (H) files
/R:0 – Number of retries on failed copy operation. By default it does retry for 1 million times, which is useful in poor network.
/TEE – Output to console window and log file – In this case I haven’t used log file. You have to add “/LOG:file” option too.
/XJD – excluding Junction Points (symbolic link) of directories from copying
/XD AppData /XD OneDrive /XD SkyDrive – list of directories to be excluded from copying
It is a wonderful alternative in Windows (though not par with rsync) available out of box, native command simple syntax and well documented (robocopy /?).
You can compile this robocopy operations in a batch file and run through Task scheduler to automate sync. It works! No more third party tools for sync!