Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Jun 2002
    Location
    Nottingham, Nottinghamshire, United Kingdom
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need to auto-sync data from usb pen

    Hi

    I currently use Keepass to maintain my passwords and Wiki-on-a-Stick for general notes. The wiki file and the Keepass datafile both reside on my main computer and I also like to have them on my usb pendrive. At the moment I have to remember which copy of the data is the most up-to-date. What I want to do is to have these 2 files sync automatically each time the pendrive is mounted on my computer, i.e. check which is the most recent file and copy it whichever way its needed.

    I can't see any backup software that does just this (don't expect to) so plan to write something myself. Has anyone else done this? Can anyone suggest the best place to start, e.g. Robocopy, Autoit or something else? I am a reasonably competent programmer (primarily VBA).

    (Please feel free to move this post to a more suitable forum if necessary.)

    Regards
    David

  2. #2
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    3,420
    Thanks
    33
    Thanked 195 Times in 175 Posts

    Re: Need to auto-sync data from usb pen

    I used a BATch file with a double ROBOCOPY, one for each direction, but it's on a USB Flash Drive at the office...

    Later... No it was upstairs.<pre>@echo off

    :: run ONLY on MyPcName

    if /i not "%computername%"=="MyPcName" (
    echo %~n0: running on %computername%, not on MyPcName
    ping -n 4 127.0.0.1 > nul
    exit
    )

    setlocal

    :: robocopy BOTH ways so that files are up-to-date on both PC and UFD

    :: common parameters
    set files="Files to be Copied*.*"
    set parms=/xo /np /r:0 /w:0
    cls

    :: a) from HD to UFD
    set source=c:target
    :: %~d0 always gives the drive letter of where this BATch file is located
    set target=%~d0UFDdir
    robocopy %source% %target% %files% %parms%
    ping -n 3 127.0.0.1> nul
    cls

    :: from UFD to HD

    set source=%~d0UFDdir
    set target=c:target
    robocopy %source% %target% %files% %parms%
    ping -n 3 127.0.0.1> nul

    :: ask whether to dismount the USB Flash Drive
    set /p answer="Do you want to dismount the USB Flash Drive on %~d0? "
    if /i not "%answer%"=="y" endlocal & exit

    :: do the dismount
    endlocal & rundll32.exe shell32.dll,Control_RunDLL hotplug.dll & exit</pre>

    Obviously you will have to rework it, since I was just syncing files from a directory on the UFD to one on the C: drive...
    BATcher

    Time prevents everything happening all at once...

  3. #3
    3 Star Lounger
    Join Date
    Jun 2002
    Location
    Nottingham, Nottinghamshire, United Kingdom
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Need to auto-sync data from usb pen

    Very many thanks, BATcher. This is far more than I expected. I'll be amending and trying it out over the next few days.

    Regards
    David

  4. #4
    3 Star Lounger
    Join Date
    Jun 2002
    Location
    Nottingham, Nottinghamshire, United Kingdom
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Need to auto-sync data from usb pen

    Hi BATcher

    Many thanks for the bat script. It runs a dream although I found out I needed to remove the words 'Files to be copied' out of the set files line for it to work.

    Can I ask you for 2 additional bits of help. Firstly, what do you put in your autorun.inf file to start the process automatically? Second, in the last line (endlocal) what would I put to have the batch file run a further program, e.g. PStart.exe?

    Regards
    David

  5. #5
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    3,420
    Thanks
    33
    Thanked 195 Times in 175 Posts

    Re: Need to auto-sync data from usb pen

    With regard to your two questions:

    a) I've never been very successful in getting a BATch file to run automatically on the insertion of a USB Flash Drive, and so I just start it from Windows Explorer. searching Google Groups gave me this about CD insertion (similar matter).

    the concatenation of the final commands is not necessary, and you can split them onto separate lines, and insert your PStart.exe in an appropriate location
    BATcher

    Time prevents everything happening all at once...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •