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

Script to mount drives and run rsync

Discussion in 'Mac Programming' started by chazco, Sep 13, 2010.

  1. macrumors member

    #1
    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.
     
  2. macrumors member

    #2
    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?
     
  3. macrumors 603

    #3
    Post your code.
     
  4. macrumors member

    #4
    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 ..."
     
  5. Moderator emeritus

    angelwatt

    #5
    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
     

Share This Page