Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

chazco

macrumors member
Original poster
Aug 22, 2010
39
0
Hi,

I've finally got a working filevault+NAS backup solution using rsync. I'm looking to make the process more automatic with a script. I'd like the script to do the following:

  1. Connect to an AFP share (using password from keychain)
  2. Mount a sparseimage which is located on the share (also getting password from the keychain)
  3. If either of the above commands fail the script should abort with an error
  4. Execute the rsync command
  5. Unmount the sparseimage
  6. Disconnect from the AFP share

I have some experience with batch files and Unix scripts, but OSX is new to me and I'm not sure where to begin. There are also other options which may be more suitable... (Automator? Applescript?).

Any suggestions on the best way to do this?

Thanks in advance.
 

chazco

macrumors member
Original poster
Aug 22, 2010
39
0
I've had some luck with this using Applescript and the "mount volume" command. I've not had any luck getting the sparseimage to mount though...

Any ideas?
 

chazco

macrumors member
Original poster
Aug 22, 2010
39
0
Here it is :)

Code:
# Attempt to connect to network share
try
	mount volume "afp://username@MyBookWorld.local/backupshare"
on error
	# Displays it's own error on failure, so just exit
	return
end try

# Mount sparseimage here

# Run rsync
do shell script "rsync ..."
 

angelwatt

Moderator emeritus
Aug 16, 2005
7,852
9
USA
I have a bash script for doing this type of thing. For mounting the sparseimage the command I use is,
Code:
# Attach
hdiutil attach /path/to/sparse.dmg >/dev/null
# Detach
hdiutil detach /Volumes/mountedDrive/ >/dev/null
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.