Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.




4025 posts

Uber Geek
+1 received by user: 1076

Trusted

Topic # 57743 23-Feb-2010 15:04
Send private message

Hey guys,
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.

Create new topic
1608 posts

Uber Geek
+1 received by user: 268

Trusted

  Reply # 301579 23-Feb-2010 16:59
Send private message

Looks very nice - can I pilfer it ? :-)
Did you consider using scheduler ? I know it wont have all the detail as your log file uses - was that the reason ?




My thoughts are no longer my own and is probably representative of our media-controlled government


81 posts

Master Geek


  Reply # 301592 23-Feb-2010 17:28
Send private message

Nice work.

I'd been using Synctoy for a few years until quite recently. I stopped using it for 2 reasons:
1. It wouldn't delete empty folders
2. It creates it's own log files all over the place (I think they were logs, or maybe configs).

I've been using SyncbackSE, which is free, for the last couple of months.
http://www.2brightsparks.com/downloads.html

Nice work scripting Synctoy tho eXDee, very clever.

-Matt

 
 
 
 


527 posts

Ultimate Geek
+1 received by user: 31

Subscriber

  Reply # 301597 23-Feb-2010 17:45
Send private message

I used it for a customer a few weeks ago as syncbackse kept causing him troubles.. I really liked how fast it was.. Setting it up in the scheduler didnt work well - ended up making a cmd file and scheduling that.. Works perfect now..



4025 posts

Uber Geek
+1 received by user: 1076

Trusted

  Reply # 301659 23-Feb-2010 21:14
Send private message

SepticSceptic: Looks very nice - can I pilfer it ? :-)
Did you consider using scheduler ? I know it wont have all the detail as your log file uses - was that the reason ?

Im not really after log detail, it was just something useful to have as a feature, and it gives a purpose to all the fancy formatting

But go ahead and use it, let me know if you need help in modifying it for your own setup. Not that many people copy from a network source onto an external drive so its unlikely the same script will work out without edits.

Its very simple though.

Create new topic



Twitter »

Follow us to receive Twitter updates when new discussions are posted in our forums:



Follow us to receive Twitter updates when news items and blogs are posted in our frontpage:



Follow us to receive Twitter updates when tech item prices are listed in our price comparison site:





News »

New Zealand's IT industry in 2018 and beyond
Posted 22-Jan-2018 12:50


Introducing your new workplace headache: Gen Z
Posted 22-Jan-2018 12:45


Jucy set to introduce electric campervan fleet
Posted 22-Jan-2018 12:41


Hawaiki cable system will be ready for service in June 2018
Posted 22-Jan-2018 12:32


New Zealand hits peak broadband data
Posted 18-Jan-2018 12:21


Amazon Echo devices coming to New Zealand early February 2018
Posted 18-Jan-2018 10:53


$3.74 million for new electric vehicles in New Zealand
Posted 17-Jan-2018 11:27


Nova 2i: Value, not excitement from Huawei
Posted 17-Jan-2018 09:02


Less news in Facebook News Feed revamp
Posted 15-Jan-2018 13:15


Australian Government contract awarded to Datacom Connect
Posted 11-Jan-2018 08:37


Why New Zealand needs a chief technology officer
Posted 6-Jan-2018 13:59


Amazon release Silk Browser and Firefox for Fire TV
Posted 21-Dec-2017 13:42


New Chief Technology Officer role created
Posted 19-Dec-2017 22:18


All I want for Christmas is a new EV
Posted 19-Dec-2017 19:54


How clever is this: AI will create 2.3 million jobs by 2020
Posted 19-Dec-2017 19:52



Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.

Alternatively, you can receive a daily email with Geekzone updates.