Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 3, 2012, 12:00 PM   #1
unixperience
macrumors regular
 
Join Date: Jul 2010
how to sync folders recursively?

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
__________________
2008 Aluminum MacBook, 2.4GHz IC2D, 8GB ram, 64bit EFI 10.6.8, 500GB momentus 7200.4
unixperience is offline   0 Reply With Quote
Old Mar 3, 2012, 05:43 PM   #2
sero
macrumors member
 
Join Date: Aug 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
sero is offline   0 Reply With Quote
Old Mar 3, 2012, 06:16 PM   #3
robvas
macrumors 68000
 
Join Date: Mar 2009
Location: USA
Cron job to run the script every 5 minutes?
robvas is offline   0 Reply With Quote
Old Mar 3, 2012, 07:55 PM   #4
MorphingDragon
Banned
 
Join Date: Mar 2009
Location: The World Inbetween
Send a message via Skype™ to MorphingDragon
Quote:
Originally Posted by unixperience View Post
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/
MorphingDragon is offline   0 Reply With Quote
Old Mar 3, 2012, 08:42 PM   #5
subsonix
macrumors 68030
 
Join Date: Feb 2008
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_...s_with_launchd
subsonix is offline   0 Reply With Quote
Old Mar 3, 2012, 11:13 PM   #6
unixperience
Thread Starter
macrumors regular
 
Join Date: Jul 2010
Quote:
Originally Posted by robvas View Post
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 :-)
__________________
2008 Aluminum MacBook, 2.4GHz IC2D, 8GB ram, 64bit EFI 10.6.8, 500GB momentus 7200.4
unixperience is offline   0 Reply With Quote
Old Mar 4, 2012, 12:15 AM   #7
subsonix
macrumors 68030
 
Join Date: Feb 2008
Quote:
Originally Posted by unixperience View Post
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.
subsonix is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Recursively calling init method… am I doing this right? ArtOfWarfare Mac Programming 19 Feb 2, 2014 05:15 PM
Sync home folders with Google Drive? Mac.User OS X 10.8 Mountain Lion 1 Aug 25, 2013 10:37 AM
alternatives to Synk, sync file and folders al404 Mac Basics and Help 3 Feb 8, 2013 11:03 AM
sync folders to NAS drive tommy060289 OS X 10.8 Mountain Lion 1 Sep 28, 2012 12:59 PM
Sync 2 Folders, different extensions. joeco Mac Basics and Help 0 Jul 11, 2012 02:15 AM

Forum Jump

All times are GMT -5. The time now is 12:56 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC