PDA

View Full Version : how to sync folders recursively?




unixperience
Mar 3, 2012, 12:00 PM
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



sero
Mar 3, 2012, 05:43 PM
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

robvas
Mar 3, 2012, 06:16 PM
Cron job to run the script every 5 minutes?

MorphingDragon
Mar 3, 2012, 07:55 PM
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

Try this:
http://code.google.com/p/lsyncd/

subsonix
Mar 3, 2012, 08:42 PM
Launchd supports system events, like changes in files and folders which means you can have you script doing backups when ever changes are made to your selected path.

Example using lauchd to do backup: http://www.macresearch.org/tutorial_backups_with_launchd

unixperience
Mar 3, 2012, 11:13 PM
Cron job to run the script every 5 minutes?

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 :-)

subsonix
Mar 4, 2012, 12:15 AM
I may not understand launchd properly, but it looks like it only runs at boot? do you schedule tasks similar to cron?


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.