How to use robocopy in Windows for backup and sync like rsync in Linux

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!

 

Share this post

3 comments

  1. Robocopy tried a lot to be like rsync but no it cant be even close to it. I loved rsync, no alternative on windows. Then read an article stating the effectiveness of gs richcopy 360. Tried it, pretty amazing software, effective as rysnc and gui based. what else do you need. job done. Cool!

  2. Hi, nice article. I’ve Robocopy for years as scheduled tasks and it always worked brilliantly. I’ve now ditched my 2003 server and jumped in at the deep end with Centos 7. I’ve got Samba working but Robo isn’t playing nicely anymore 🙁 Tried many switched including the one in your post but I keep getting:-

    ERROR 5 (0x00000005) Changing File Attributes \\192.168.0.201\folder\ Access is denied.

    I don’t know if it’s a permissions thing or a Samba thing or a Robo thing. Any suggestions?

    Thinking I might try mounting my “data” drive as NTFS instead of ext3. I need to hang an external USB “Data back up” drive and that’s currently NTFS. Not used rsync for years but hopefully it would do NTFS to NTFS?

Leave a Reply

Your email address will not be published. Required fields are marked *