A poor man's Windows rsync

Posted by sam Mon, 12 Apr 2010 16:17:00 GMT

When I’m on a Windows box and I want to sync two directories (remote or local), I use this little one-liner:

@echo off
xcopy %1 %2 /M /E /Y /Z

The switches are:

  • M: Copy only files with the archive bit set
  • E: Copy directories and subdirectories, even empty ones
  • Y: Supress prompting for overwrites
  • Z: Copy in network restartable mode

The %1 and %2 obviously denote parameter arguments when called from a batch file, so when saved as ‘file_sync.bat’:

C:\>file_sync.bat c:\somedirectory \\someserver\sometargetdir

Will sync the local directory with the remote share. When files are modified or added, Windows sets the NTFS archive bit. When run again the script will only copy the new or amended files.