I've always liked automating things with batch files, and i needed a simple way to intelligently syncronise all music and photos from my main PC to the HTPC.
First of all you need to download SyncToy 2.1, and set it up with your appropriate sync partnerships in the GUI. Mine is set to clone the files from my main PC over my network to my external hard drive plugged into the HTPC. Check it all works out correctly when you run all sync partnerships.
Note that synctoy alone is a very simple but useful tool, but i'm after some automation, so i call upon batch files.
First up is syncfiles.bat - the file you call upon to start the sync. This causes a log file to be generated of all the output.
@echo off
title Synctoy run in progress...
echo Attempting file sync. Please wait...
sync.bat >lastsync.log
(save as syncfiles.bat)
Then we have the sync.bat file, which is setup to check the connection to my main pc (office) and check for my external drive (Seagate Freeagent) plugged into the HTPC. If it all goes well, synctoy starts up.
@echo off
echo SyncToy Log starting at
time /T
date /T
echo ##############################################
echo Checking connection to office...
echo ##############################################
PING -n 2 -w 10 192.168.1.2 |find "TTL=" && goto FREEAGENT
goto PINGFAIL
:FREEAGENT
echo ##############################################
echo Office is online. Checking for freeagent...
if exist J:\Backup\ goto SYNC
goto FREEAGENTFAIL
:SYNC
echo ##############################################
echo Freeagent is plugged in. Begin syncing files...
echo ##############################################
cd "C:\Program Files\SyncToy 2.1\"
SyncToyCmd.exe -R
if %ERRORLEVEL% == 0 goto SUCCESS
goto SYNCFAIL
:PINGFAIL
echo ##############################################
echo Office not found. Exiting
goto END
:FREEAGENTFAIL
echo ##############################################
echo Freeagent not found. Exiting
goto END
:SUCCESS
echo ##############################################
echo Synctoy finished successfully. Exiting
goto END
:SYNCFAIL
echo ##############################################
echo Synctoy Failed. Exiting
goto END
:END
echo ##############################################
echo Synctoy Log ending at
time /T
date /T
(save as sync.bat)
Note how i look for TTL= instead of using an %errorlevel%, apparently ping won't always exit with an errorlevel of 0, so i simply look for TTL= instead.
As you can see, i like spacing things out to make the log file easy to read. Initially this looks messy, but the resulting log file it creates (lastsync.log) i think is nice and easy to read.
Heres a successful output to lastsync.log:
SyncToy Log starting at
03:02 p.m.
Tue 23/02/2010
##############################################
Checking connection to office...
##############################################
Reply from 192.168.1.2: bytes=32 time<1ms TTL=128
Reply from 192.168.1.2: bytes=32 time<1ms TTL=128
##############################################
Office is online. Checking for freeagent...
##############################################
Freeagent is plugged in. Begin syncing files...
##############################################
Preview of Photos (\\OFFICE\D Drive\Photos\, J:\Backup\Pictures\) in time 00:00:05:210.
SyncToy action was 'Echo'
Found 0 actions to perform.
Found 29,175 files that did not require action.
Analyzed 5,599.4 files per second.
Avoided copying 77,705,710,554 bytes in 29,175 files.
Saved approximately 19:10:11:00 by not copying any files.
SyncToy run of Photos (\\OFFICE\D Drive\Photos\, J:\Backup\Pictures\) completed at 23/02/2010 3:02:20 p.m..
SyncToy action was 'Echo'.
SyncToy options were:
Active for run all
All files included
No files excluded
Do not check file contents
Include read-only files
Include hidden files
Include system files
Backup older files (send to Recycle Bin)
All subfolders included
SyncToy run took 00:00:00:078.
Copied 0 bytes in 0 files in 00:00:00:78.
Bytes per second 0.0, files per second 0.0.
Avoided copying 77,705,710,554 bytes in 29,175 files that did not require action.
Saved approximately 19:10:11:00 by not copying all files.
Preview of Music (\\OFFICE\D Drive\Music\, J:\Backup\Music\) in time 00:00:03:57.
SyncToy action was 'Echo'
Found 0 actions to perform.
Found 15,729 files that did not require action.
Analyzed 5,144.2 files per second.
Avoided copying 63,203,446,975 bytes in 15,729 files.
Saved approximately 11:06:46:00 by not copying any files.
SyncToy run of Music (\\OFFICE\D Drive\Music\, J:\Backup\Music\) completed at 23/02/2010 3:02:23 p.m..
SyncToy action was 'Echo'.
SyncToy options were:
Active for run all
All files included
No files excluded
Do not check file contents
Include read-only files
Include hidden files
Include system files
Backup older files (send to Recycle Bin)
All subfolders included
SyncToy run took 00:00:00:078.
Copied 0 bytes in 0 files in 00:00:00:78.
Bytes per second 0.0, files per second 0.0.
Avoided copying 63,203,446,975 bytes in 15,729 files that did not require action.
Saved approximately 11:06:46:00 by not copying all files.
##############################################
Synctoy finished successfully. Exiting
##############################################
Synctoy Log ending at
03:02 p.m.
Tue 23/02/2010
So the end result, is i can schedule syncfiles.bat under scheduled tasks (or run on startup). It shows a simple clean cmd window with the message "Attempting file sync. Please wait..." and exits when finished. lastsync.log reveals details of the previous sync run.
Lastly, its notable i have a gigabit network, on a standard network if there are a large quantity of changes it will take a long time to sync. Also i run the sync often, the logfile will be very large if there are lots of changes(it will detail every file synced).
Hope this helps someone.

