how to sync folders recursively?

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

  1. unixperience macrumors regular

    Jul 21, 2010
    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. sero macrumors member

    Aug 28, 2008
    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. robvas macrumors 68030

    Mar 29, 2009
  4. MorphingDragon macrumors 603


    Mar 27, 2009
    The World Inbetween
    Try this:
  5. subsonix macrumors 68040

    Feb 2, 2008
  6. unixperience thread starter macrumors regular

    Jul 21, 2010
    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. subsonix macrumors 68040

    Feb 2, 2008
    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