1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

how to sync folders recursively?

Discussion in 'Mac Programming' started by unixperience, Mar 3, 2012.

  1. macrumors regular

    #1
    Hello, not exactly programming, but scripting; I wrote an bash script that syncs two folders, and set it as a folder action. here is a sample:

    echo "syncing from server to local"
    rsync -avru -progress --delete LOCAL_SOURCE TARGET_SERVER
    echo "operation complete"

    I have it associated with a folder, and it syncs all subfolders already, since i told rsync to sync recursively, however can i get this to run anytime there is a change in any subfolder of LOCAL_SOURCE ????

    I could of course associate the folder action with every single subfolder, but there are hundreds. and new folders are added and deleted everyday, I wouldn't want to associate the script every time I make a new folder. anyway to get around this?

    i'm fairly proficient with programming so I can use scripts or automator, just about anything, so ALL ideas are welcome
     
  2. macrumors member

    #2
    Wirelessly posted (Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3)

    So use launchd
     
  3. macrumors 68000

    #3
    Cron job to run the script every 5 minutes?
     
  4. macrumors 603

    MorphingDragon

    #4
    Try this:
    http://code.google.com/p/lsyncd/
     
  5. macrumors 68040

    #5
  6. macrumors regular

    #6
    Yeah I thought that would be one way to do it... but I wanted instant updates whenever a change is applied, but I suppose using cron is probably better for the harddrive, so its not updating with every autosave. cron is looking like the best answer, for me anyway


    thanks everyone for your help. I may not understand launchd properly, but it looks like it only runs at boot? do you schedule tasks similar to cron?


    but thanks again to everyone :)
     
  7. macrumors 68040

    #7
    It does schedule things like cron, but it does more, like supervising background processes, running boot scripts and so on. Unlike cron it can act upon events, like changes in files and folders, mounting of volumes and so on which is what the link I provided shows. But I agree that cron may be better in this case, but it depends on your requirements, it's simpler.
     

Share This Page