Synchronising web server files in Windows 7

I tried several tools for synchronising files and folders between 2 computers running Windows 7. My purpose is to sync web server files between 2 computers- basically "htdocs" and database folders of XAMPP.

When you try syncing web sever files that you want to use on both the computers, you have to create the same directory structure on the destination computer. For instance, if your source folder is C:\Program Files\xampp\htdocs, then you should install xampp in the same directory structure on the destination computer. Otherwise your synced webserver will not work on the destination computer.

Out of few tools I tried, I found command-based Robocopy the most reliable and ideal for my sync purpose. This is my concise review of the tools I tried.

Sync Toy - Good and easy to use with Synchronize, Echo and Contribute modes but I have noticed it's not too reliable when transferring large number of files.

Sync Center - Comes with Windows 7. It creates an offline file access, which allows you to access the files even when the network is disconnected. I wanted to sync "htdocs" in PC1 with "htdocs" in PC2. It creates its own "sync folders" on the destination, which is not suitable for my purpose.

Karen's Replicator - Does not allow good folder exclusion function. Only has global exclude but not per-task.

RichCopy - Failed to work on my computer when I tried running after installing it. So I just gave up.

Robocopy - comes with Windows 7. This is by far the best tool I have come across. It is a command-line utility. You must run this command as an Administrator. This is the syntax I used:
robocopy C:\YourPath\sharedfolder \\NetworkPC\sharedfolder /MIR /ZB /R:2 /V /FP /LOG:logfilename /TEE 
  • /MIR - mirror a directory tree
  • /ZB - restartable mode- often used for copying files over a network.
  • /R:2 - number of retries, in case the network connection fails.
  • /V - verbose mode, shows skipped files
  • /FP - show full pathname of files in the output.
  • /LOG:filename -  output status to log file (overwrite existing file)
  • /TEE - display log to the standard output.
    To make sync job easier, I created a batch file that can then be double-clicked or scheduled to run at specific times to do the sync job. Creating a batch file is easy. Open up the Notepad and copy and paste the code below and save the file with .bat extension:
    @ECHO OFF
    SETLOCAL
    
    SET _source=C:\YourPath\xampp\htdocs
    
    SET _dest=\\NetworkPC\htdocs
    
    SET _options=/MIR /ZB /R:2 /V /FP /LOG:D:\Robocopy\robocopylog.txt /TEE
    
    ROBOCOPY %_source% %_dest% %_options%
    
    ENDLOCAL
    

    Issues:
    1) Don't save the file as robocopy.bat
    I first saved the file as robocopy.bat and when I tried to run it, it gave me the message "Maximum setlocal recursion level reached". I then renamed the file something else and the error is gone.

    2) Running the batch file as Administrator
    The newly created batch file may not run in Windows 7 even though you are logged in as Administrator. This is because of the UAC settings. The batch file needs to be run explicitly as administrator. To do this, follow the steps below:
    1. Create a shortcut of the batch file by right-clicking on the batch file and selecting "Create Shortcut" from the menu. This will create a shortcut of the batch file. 
    2. Right-click on the shortcut file. Select "Properties" and click on "Shortcut" tab. Click on "Advanced..." button and choose "Run as administrator". Click "Ok".
    3. Now every time you want to run the batch file, make sure you run the shortcut file.

      Comments

      Popular posts from this blog

      How to resolve 'res://ieframe.dll/acr_error.htm#' error (Internet Explorer stopped working while viewing a website)

      htaccess: Redirecting multiple domains to the main domain

      MailChimp API V2.0 SSL error solution